Skip to content

Commit f7e97ca

Browse files
authored
Merge pull request #25 from guyush1/allow-build-with-and-without-python
build: Allow building gdb with and without python
2 parents 17346ca + 6738ced commit f7e97ca

File tree

3 files changed

+77
-28
lines changed

3 files changed

+77
-28
lines changed

.github/workflows/pr-pipeline.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ jobs:
99
build:
1010
strategy:
1111
matrix:
12+
build_type: ["build", "build-with-python"]
1213
architecture: ["x86_64", "arm", "aarch64", "powerpc", "mips", "mipsel"]
1314

1415
runs-on: ubuntu-latest
@@ -21,4 +22,4 @@ jobs:
2122
run: sudo apt-get install -y wget
2223

2324
- name: Build
24-
run: make build-${{ matrix.architecture }} -j$((`nproc`+1))
25+
run: make ${{ matrix.build_type }}-${{ matrix.architecture }} -j$((`nproc`+1))

Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
2+
23
TARGETS := $(addprefix build-, $(ARCHS))
4+
PYTHON_TARGETS := $(addprefix build-with-python-, $(ARCHS))
5+
ALL_TARGETS := $(TARGETS) $(PYTHON_TARGETS)
6+
37
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
8+
PYTHON_PACK_TARGETS := $(addprefix pack-with-python-, $(ARCHS))
9+
ALL_PACK_TARGETS := $(PACK_TARGETS) $(PYTHON_PACK_TARGETS)
10+
411
SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*)
512
BUILD_PACKAGES_DIR := "build/packages"
613

7-
.PHONY: clean help download_packages build build-docker-image $(TARGETS) $(PACK_TARGETS)
14+
.PHONY: clean help download_packages build build-docker-image $(ALL_TARGETS) $(ALL_PACK_TARGETS)
815

916
help:
1017
@echo "Usage:"
1118
@echo " make build"
1219
@echo ""
1320

14-
@for target in $(TARGETS); do \
21+
@for target in $(ALL_TARGETS); do \
1522
echo " $$target"; \
1623
done
1724

@@ -20,7 +27,7 @@ help:
2027

2128
build/build-docker-image.stamp: Dockerfile
2229
mkdir -p build
23-
docker build -t gdb-static .
30+
docker buildx build --tag gdb-static .
2431
touch build/build-docker-image.stamp
2532

2633
build-docker-image: build/build-docker-image.stamp
@@ -40,19 +47,31 @@ symlink-git-packages: build/symlink-git-packages.stamp
4047

4148
download-packages: build/download-packages.stamp
4249

43-
build: $(TARGETS)
50+
build: $(ALL_TARGETS)
51+
52+
$(TARGETS): build-%:
53+
@$(MAKE) _build-$*
4454

45-
$(TARGETS): build-%: symlink-git-packages download-packages build-docker-image
55+
$(PYTHON_TARGETS): build-with-python-%:
56+
@WITH_PYTHON="--with-python" $(MAKE) _build-$*
57+
58+
_build-%: symlink-git-packages download-packages build-docker-image
4659
mkdir -p build
4760
docker run --user $(shell id -u):$(shell id -g) \
4861
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
49-
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src
62+
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON)
63+
64+
pack: $(ALL_PACK_TARGETS)
65+
66+
$(PACK_TARGETS): pack-%:
67+
@$(MAKE) _pack-$*
5068

51-
pack: $(PACK_TARGETS)
69+
$(PYTHON_PACK_TARGETS): pack-with-python-%:
70+
@TAR_EXT="with-python-" ARTIFACT_EXT="_with_python" $(MAKE) _pack-$*
5271

53-
$(PACK_TARGETS): pack-%: build-%
54-
if [ ! -f "build/artifacts/gdb-static-$*.tar.gz" ]; then \
55-
tar -czf "build/artifacts/gdb-static-$*.tar.gz" -C "build/artifacts/$*" .; \
72+
_pack-%: build-%
73+
if [ ! -f "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" ]; then \
74+
tar -czf "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" -C "build/artifacts/$*$(ARTIFACT_EXT)" .; \
5675
fi
5776

5877
clean-git-packages:

src/compilation/build.sh

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ function build_gdb() {
335335
# $3: libiconv prefix
336336
# $4: libgmp prefix
337337
# $5: libmpfr prefix
338+
# $6: whether to build with python or not
338339
#
339340
# Echoes:
340341
# The gdb build directory
@@ -348,7 +349,15 @@ function build_gdb() {
348349
local libiconv_prefix="$3"
349350
local libgmp_prefix="$4"
350351
local libmpfr_prefix="$5"
351-
local gdb_build_dir="$(realpath "$gdb_dir/build-$target_arch")"
352+
local with_python="$6"
353+
354+
if [[ "$with_python" == "yes" ]]; then
355+
local python_flag="--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config"
356+
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_with_python")"
357+
else
358+
local python_flag="--without-python"
359+
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}")"
360+
fi
352361

353362
echo "$gdb_build_dir"
354363
mkdir -p "$gdb_build_dir"
@@ -363,7 +372,7 @@ function build_gdb() {
363372
>&2 fancy_title "Building gdb for $target_arch"
364373

365374
../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \
366-
--enable-tui --with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config \
375+
--enable-tui "$python_flag" \
367376
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
368377
"--with-gmp=$libgmp_prefix" \
369378
"--with-mpfr=$libmpfr_prefix" \
@@ -390,6 +399,7 @@ function install_gdb() {
390399
# $1: gdb build directory
391400
# $2: artifacts directory
392401
# $3: target architecture
402+
# $4: whether gdb was built with or without python
393403
#
394404
# Returns:
395405
# 0: success
@@ -398,15 +408,22 @@ function install_gdb() {
398408
local gdb_build_dir="$1"
399409
local artifacts_dir="$2"
400410
local target_arch="$3"
411+
local with_python="$4"
412+
413+
if [[ "$with_python" == "yes" ]]; then
414+
local artifacts_location="$artifacts_dir/${target_arch}_with_python"
415+
else
416+
local artifacts_location="$artifacts_dir/${target_arch}"
417+
fi
401418

402-
if [[ -d "$artifacts_dir/$target_arch" && -n "$(ls -A "$artifacts_dir/$target_arch")" ]]; then
419+
if [[ -d "$artifacts_location" && -n "$(ls -A "$artifacts_location")" ]]; then
403420
>&2 echo "Skipping install: gdb already installed for $target_arch"
404421
return 0
405422
fi
406423

407424
temp_artifacts_dir="$(mktemp -d)"
408425

409-
mkdir -p "$artifacts_dir/$target_arch"
426+
mkdir -p "$artifacts_location"
410427

411428
make -C "$gdb_build_dir" install "DESTDIR=$temp_artifacts_dir" 1>&2
412429
if [[ $? -ne 0 ]]; then
@@ -415,7 +432,7 @@ function install_gdb() {
415432
fi
416433

417434
while read file; do
418-
cp "$file" "$artifacts_dir/$target_arch/"
435+
cp "$file" "$artifacts_location/"
419436
done < <(find "$temp_artifacts_dir/usr/local/bin" -type f -executable)
420437

421438
rm -rf "$temp_artifacts_dir"
@@ -429,8 +446,9 @@ function build_and_install_gdb() {
429446
# $2: libiconv prefix
430447
# $3: libgmp prefix
431448
# $4: libmpfr prefix
432-
# $5: install directory
433-
# $6: target architecture
449+
# $5: whether to build with python or not
450+
# $6: install directory
451+
# $7: target architecture
434452
#
435453
# Returns:
436454
# 0: success
@@ -440,15 +458,16 @@ function build_and_install_gdb() {
440458
local libiconv_prefix="$2"
441459
local libgmp_prefix="$3"
442460
local libmpfr_prefix="$4"
443-
local artifacts_dir="$5"
444-
local target_arch="$6"
461+
local with_python="$5"
462+
local artifacts_dir="$6"
463+
local target_arch="$7"
445464

446-
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix")"
465+
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$with_python")"
447466
if [[ $? -ne 0 ]]; then
448467
return 1
449468
fi
450469

451-
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch"
470+
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$with_python"
452471
if [[ $? -ne 0 ]]; then
453472
return 1
454473
fi
@@ -461,10 +480,12 @@ function build_gdb_with_dependencies() {
461480
# $1: target architecture
462481
# $2: build directory
463482
# $3: src directory
483+
# $4: whether to build gdb with python or not
464484

465485
local target_arch="$1"
466486
local build_dir="$2"
467487
local source_dir="$3"
488+
local with_python="$4"
468489
local packages_dir="$build_dir/packages"
469490
local artifacts_dir="$build_dir/artifacts"
470491

@@ -496,15 +517,18 @@ function build_gdb_with_dependencies() {
496517
fi
497518
set_ncurses_link_variables "$ncursesw_build_dir"
498519

499-
python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch")"
500-
if [[ $? -ne 0 ]]; then
501-
return 1
520+
if [[ "$with_python" == "yes" ]]; then
521+
build_python "$packages_dir/cpython-static" "$target_arch"
522+
if [[ $? -ne 0 ]]; then
523+
return 1
524+
fi
502525
fi
503526

504527
build_and_install_gdb "$packages_dir/binutils-gdb" \
505528
"$iconv_build_dir/lib/.libs/" \
506529
"$gmp_build_dir/.libs/" \
507530
"$mpfr_build_dir/src/.libs/" \
531+
"$with_python" \
508532
"$artifacts_dir" \
509533
"$target_arch"
510534
if [[ $? -ne 0 ]]; then
@@ -513,12 +537,17 @@ function build_gdb_with_dependencies() {
513537
}
514538

515539
function main() {
516-
if [[ $# -ne 3 ]]; then
517-
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir>"
540+
if [[ $# -lt 3 ]]; then
541+
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir> [--with-python]"
518542
exit 1
519543
fi
520544

521-
build_gdb_with_dependencies "$1" "$2" "$3"
545+
local with_python="no"
546+
if [[ "$4" == "--with-python" ]]; then
547+
with_python="yes"
548+
fi
549+
550+
build_gdb_with_dependencies "$1" "$2" "$3" "$with_python"
522551
if [[ $? -ne 0 ]]; then
523552
>&2 echo "Error: failed to build gdb with dependencies"
524553
exit 1

0 commit comments

Comments
 (0)