Skip to content

Commit fdc2d2e

Browse files
authored
Merge pull request #1 from RoiKlevansky/build-using-dockerfile
Automate building using docker
2 parents 1706882 + 4cde133 commit fdc2d2e

File tree

9 files changed

+860
-0
lines changed

9 files changed

+860
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
# IDE Folders
22
.idea/
33
.vscode/
4+
5+
# Build folders
6+
build/

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM ubuntu:24.04
2+
3+
# Install dependencies
4+
RUN apt update && apt install -y \
5+
g++ \
6+
g++-aarch64-linux-gnu \
7+
g++-arm-linux-gnueabi \
8+
g++-powerpc-linux-gnu \
9+
gcc \
10+
gcc-aarch64-linux-gnu \
11+
gcc-arm-linux-gnueabi \
12+
gcc-powerpc-linux-gnu \
13+
m4 \
14+
make \
15+
patch \
16+
texinfo \
17+
wget \
18+
xz-utils
19+
20+
WORKDIR /app/gdb

Makefile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
ARCHS := x86_64 arm aarch64 powerpc
2+
TARGETS := $(addprefix build-, $(ARCHS))
3+
4+
.PHONY: clean help download_packages build patch-gdb build-docker-image $(TARGETS)
5+
6+
help:
7+
@echo "Usage:"
8+
@echo " make build"
9+
@echo ""
10+
11+
@for target in $(TARGETS); do \
12+
echo " $$target"; \
13+
done
14+
15+
@echo ""
16+
@echo " make clean"
17+
18+
build/build-docker-image.stamp: Dockerfile
19+
mkdir -p build
20+
docker build -t gdb-static .
21+
touch build/build-docker-image.stamp
22+
23+
build-docker-image: build/build-docker-image.stamp
24+
25+
build/download-packages.stamp: build/build-docker-image.stamp src/download_packages.sh
26+
mkdir -p build/packages
27+
docker run --user $(shell id -u):$(shell id -g) \
28+
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
29+
/app/gdb/src/download_packages.sh /app/gdb/build/packages
30+
touch build/download-packages.stamp
31+
32+
download-packages: build/download-packages.stamp
33+
34+
build/patch-gdb.stamp: build/build-docker-image.stamp src/gdb_static.patch build/download-packages.stamp
35+
docker run --user $(shell id -u):$(shell id -g) \
36+
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
37+
/app/gdb/src/patch_gdb.sh /app/gdb/build/packages/gdb /app/gdb/src/gdb_static.patch
38+
touch build/patch-gdb.stamp
39+
40+
patch-gdb: build/patch-gdb.stamp
41+
42+
build: $(TARGETS)
43+
44+
$(TARGETS): build-%: download-packages patch-gdb build-docker-image
45+
mkdir -p build
46+
docker run --user $(shell id -u):$(shell id -g) \
47+
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
48+
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src/gdb_static.patch
49+
50+
clean:
51+
rm -rf build
52+
# Kill and remove all containers of image gdb-static
53+
docker ps -a | grep -P "^[a-f0-9]+\s+gdb-static\s+" | awk '{print $$1}' | xargs docker rm -f 2>/dev/null || true
54+
docker rmi -f gdb-static 2>/dev/null || true

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,53 @@
22

33
The statically compiled gdb / gdbserver binaries are avaliable to download under github releases!
44

5+
# Compiling gdb using docker
6+
7+
This repository contains a dockerfile and build scripts to compile gdb and gdbserver statically for multiple architectures.
8+
Currently, the supported architectures are:
9+
- x86_64
10+
- arm
11+
- aarch64
12+
- powerpc (32bit)
13+
You can easily expand it to support more architectures by adding the appropriate cross compilers to the dockerfile, and other build scripts.
14+
15+
NOTE: You don't need to interact with the dockerfile directly, as the Makefile will take care of everything for you.
16+
17+
## Building for a specific architecture
18+
19+
To build for a specific architecture, you can use the following command:
20+
```bash
21+
make build-<ARCH>
22+
```
23+
24+
For example, to build for arm:
25+
```bash
26+
make build-arm
27+
```
28+
29+
The resulting binaries will be placed under the `build/artifacts/` directory.
30+
Each architecture will have its own directory under `build/artifacts/`. For example, the arm architecture will have the following directory structure:
31+
```
32+
build/
33+
artifacts/
34+
arm/
35+
...
36+
```
37+
38+
## Building for all architectures
39+
40+
To build for all architectures, you can use the following command:
41+
```bash
42+
make build
43+
```
44+
45+
## Cleaning the build
46+
47+
To clean the build, you can use the following command:
48+
```bash
49+
make clean
50+
```
51+
552
# Notes about this file - read before proceeding!
653

754
While i already provided the gdb/gdbserver-15 statically compiled binaries handed out to you, some people might want to compile it to a different architecture, or compile a newer version of gdb in the future :). This rest of the file contains my compilation documentation so that you could save yourself some time and do it yourself, if you wish.
@@ -86,6 +133,8 @@ II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-st
86133
III) run `make -j$(nproc)`
87134
IV) run `mkdir ./src/.libs/lib`
88135
V) run `cp ./src/.libs/libmpfr.a ./src/.libs/lib`
136+
VI) run `mkdir ./src/.libs/include`
137+
VII) run `cp ../src/mpfr.h ./src/.libs/include/`
89138

90139
## 4) Compiling gdb
91140

0 commit comments

Comments
 (0)