Skip to content

Commit 19a56cc

Browse files
committed
build: split build into 2 variants - slim & full
Full builds also include python (similar to -with-python before) & also include cross architecture debugging. full builds are configurable via the full_build_conf.sh file.
1 parent 1956fde commit 19a56cc

File tree

3 files changed

+143
-92
lines changed

3 files changed

+143
-92
lines changed

Makefile

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
2+
GDB_BFD_ARCHS := $(shell echo $(ARCHS) | awk '{for(i=1;i<=NF;i++) $$i=$$i"-linux"; print}' OFS=,)
23

3-
TARGETS := $(addprefix build-, $(ARCHS))
4-
PYTHON_TARGETS := $(addprefix build-with-python-, $(ARCHS))
5-
ALL_TARGETS := $(TARGETS) $(PYTHON_TARGETS)
4+
BASE_TARGETS := $(addprefix build-, $(ARCHS))
65

7-
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
8-
PYTHON_PACK_TARGETS := $(addprefix pack-with-python-, $(ARCHS))
9-
ALL_PACK_TARGETS := $(PACK_TARGETS) $(PYTHON_PACK_TARGETS)
6+
SLIM_TARGETS := $(addsuffix -slim, $(BASE_TARGETS))
7+
FULL_TARGETS := $(addsuffix -full, $(BASE_TARGETS))
8+
ALL_TARGETS := $(SLIM_TARGETS) $(FULL_TARGETS)
9+
10+
BASE_PACK_TARGETS := $(addprefix pack-, $(ARCHS))
11+
12+
FULL_PACK_TARGETS := $(addsuffix -full, $(BASE_PACK_TARGETS))
13+
SLIM_PACK_TARGETS := $(addsuffix -slim, $(BASE_PACK_TARGETS))
14+
ALL_PACK_TARGETS := $(SLIM_PACK_TARGETS) $(FULL_PACK_TARGETS)
1015

1116
SUBMODULE_PACKAGES := $(wildcard src/submodule_packages/*)
1217
BUILD_PACKAGES_DIR := "build/packages"
@@ -55,29 +60,29 @@ download-packages: build/download-packages.stamp
5560

5661
build: $(ALL_TARGETS)
5762

58-
$(TARGETS): build-%:
59-
@$(MAKE) _build-$*
63+
$(SLIM_TARGETS): build-%-slim:
64+
@BUILD_TYPE="slim" $(MAKE) _build-$*
6065

61-
$(PYTHON_TARGETS): build-with-python-%:
62-
@WITH_PYTHON="--with-python" $(MAKE) _build-$*
66+
$(FULL_TARGETS): build-%-full:
67+
@BUILD_TYPE="full" GDB_BFD_ARCHS=$(GDB_BFD_ARCHS) $(MAKE) _build-$*
6368

6469
_build-%: symlink-git-packages download-packages build-docker-image
6570
mkdir -p build
6671
docker run $(TTY_ARG) --user $(shell id -u):$(shell id -g) \
6772
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
68-
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(WITH_PYTHON)
73+
/app/gdb/src/compilation/build.sh $* /app/gdb/build/ /app/gdb/src $(BUILD_TYPE) $(GDB_BFD_ARCHS)
6974

7075
pack: $(ALL_PACK_TARGETS)
7176

72-
$(PACK_TARGETS): pack-%:
73-
@$(MAKE) _pack-$*
77+
$(SLIM_PACK_TARGETS): pack-%-slim:
78+
@BUILD_TYPE="slim" $(MAKE) _pack-$*
7479

75-
$(PYTHON_PACK_TARGETS): pack-with-python-%:
76-
@TAR_EXT="with-python-" ARTIFACT_EXT="_with_python" $(MAKE) _pack-$*
80+
$(FULL_PACK_TARGETS): pack-%-full:
81+
@BUILD_TYPE="full" $(MAKE) _pack-$*
7782

78-
_pack-%: build-%
79-
if [ ! -f "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" ]; then \
80-
tar -czf "build/artifacts/gdb-static-$(TAR_EXT)$*.tar.gz" -C "build/artifacts/$*$(ARTIFACT_EXT)" .; \
83+
_pack-%: build-%-$(BUILD_TYPE)
84+
if [ ! -f "build/artifacts/gdb-static-$(BUILD_TYPE)-$*.tar.gz" ]; then \
85+
tar -czf "build/artifacts/gdb-static-$(BUILD_TYPE)-$*.tar.gz" -C "build/artifacts/$*_$(BUILD_TYPE)" .; \
8186
fi
8287

8388
clean-git-packages:

src/compilation/build.sh

Lines changed: 112 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Include utils library
44
script_dir=$(dirname "$0")
55
source "$script_dir/utils.sh"
6+
source "$script_dir/full_build_conf.sh"
67

78
# Don't want random unknown things to fail in the build procecss!
89
set -e
@@ -50,36 +51,53 @@ function set_compliation_variables() {
5051
export CC="${CROSS}gcc"
5152
export CXX="${CROSS}g++"
5253

53-
export CFLAGS="-O2"
54-
export CXXFLAGS="-O2"
54+
export CFLAGS="-Os"
55+
export CXXFLAGS="-Os"
5556

5657
# Strip the binary to reduce it's size.
5758
export LDFLAGS="-s"
5859
}
5960

60-
function set_up_lib_search_paths() {
61+
function set_up_lib_search_path() {
62+
# Set up library-related linker search paths.
63+
#
64+
# Parameters:
65+
# $1: library install dir
66+
# $2: whether to add linker search path or not (include path is always added).
67+
local lib_install_dir="$1"
68+
local add_linker_include_path="$2"
69+
70+
if [[ $add_linker_include_path == 1 ]]; then
71+
# Add library to the linker's include path.
72+
export LDFLAGS="-L$lib_install_dir/lib $LDFLAGS"
73+
fi
74+
75+
# Add library standard headers to the CC / CXX flags.
76+
local include_paths="-I$lib_install_dir/include"
77+
export CC="$CC $include_paths"
78+
export CXX="$CXX $include_paths"
79+
}
80+
81+
function set_up_base_lib_search_paths() {
6182
# Set up library-related linker search paths.
6283
#
6384
# Parameters:
6485
# $1: iconv build dir
6586
# $2: gmp build dir
6687
# $3: mpfr build dir
6788
# $4: ncursesw build dir
68-
# $5: libexpat build dir
89+
# $5: expat build dir
6990
local iconv_build_dir="$1"
7091
local gmp_build_dir="$2"
7192
local mpfr_build_dir="$3"
7293
local ncursesw_build_dir="$4"
73-
local libexpat_build_dir="$5"
94+
local expat_build_dir="$5"
7495

75-
# I) Allow tui mode by adding our custom built static ncursesw library to the linker search path.
76-
# II) Allow parsing xml files by adding libexpat library to the linker search path.
77-
export LDFLAGS="-L$ncursesw_build_dir/lib -L$libexpat_build_dir/lib/ $LDFLAGS"
78-
79-
# Add library standard headers to the CC / CXX flags.
80-
export INCLUDE_PATHS="-I$iconv_build_dir/include -I$gmp_build_dir/include -I$mpfr_build_dir/include -I$ncursesw_build_dir/include -I$libexpat_build_dir/include"
81-
export CC="$CC $INCLUDE_PATHS"
82-
export CXX="$CXX $INCLUDE_PATHS"
96+
set_up_lib_search_path $iconv_build_dir 0
97+
set_up_lib_search_path $gmp_build_dir 0
98+
set_up_lib_search_path $mpfr_build_dir 0
99+
set_up_lib_search_path $ncursesw_build_dir 1
100+
set_up_lib_search_path $expat_build_dir 1
83101
}
84102

85103
function build_iconv() {
@@ -489,10 +507,11 @@ function build_gdb() {
489507
# $1: gdb directory
490508
# $2: target architecture
491509
# $3: libiconv prefix
492-
# $4: liblzma prefix
493-
# $5: libgmp prefix
494-
# $6: libmpfr prefix
495-
# $7: whether to build with python or not
510+
# $4: libgmp prefix
511+
# $5: libmpfr prefix
512+
# $6: liblzma prefix
513+
# $7: whether to build gdb with all extra configurations specified in src/compilation/full_build_conf.sh
514+
# $8: gdb cross-architecture binary format support formats (relevant for full builds only).
496515
#
497516
# Echoes:
498517
# The gdb build directory
@@ -504,17 +523,28 @@ function build_gdb() {
504523
local gdb_dir="$1"
505524
local target_arch="$2"
506525
local libiconv_prefix="$3"
507-
local liblzma_prefix="$4"
508-
local libgmp_prefix="$5"
509-
local libmpfr_prefix="$6"
510-
local with_python="$7"
511-
512-
if [[ "$with_python" == "yes" ]]; then
513-
local python_flag="--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config"
514-
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_with_python")"
526+
local libgmp_prefix="$4"
527+
local libmpfr_prefix="$5"
528+
local liblzma_prefix="$6"
529+
local full_build="$7"
530+
local gdb_bfd_archs="$8"
531+
532+
local extra_flags=()
533+
if [[ "$full_build" == "yes" ]]; then
534+
if [[ $full_build_supported_targets -eq 1 ]]; then
535+
extra_flags+=("--enable-targets=$gdb_bfd_archs" "--enable-64-bit-bfd")
536+
fi
537+
538+
if [[ $full_build_python_support -eq 1 ]]; then
539+
extra_flags+=("--with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config")
540+
else
541+
extra_flags+=("--without-python")
542+
fi
543+
544+
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_full")"
515545
else
516-
local python_flag="--without-python"
517-
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}")"
546+
extra_flags+=("--without-python")
547+
local gdb_build_dir="$(realpath "$gdb_dir/build-${target_arch}_slim")"
518548
fi
519549

520550
echo "$gdb_build_dir"
@@ -530,16 +560,16 @@ function build_gdb() {
530560
>&2 fancy_title "Building gdb for $target_arch"
531561

532562
../configure --enable-static --with-static-standard-libraries --disable-inprocess-agent \
533-
--enable-targets=all --enable-64-bit-bfd \
534-
--enable-tui "$python_flag" \
535-
--with-expat --with-libexpat-type="static" \
536563
--with-gdb-datadir="/usr/share/gdb" --with-separate-debug-dir="/usr/lib/debug" \
537564
--with-system-gdbinit="/etc/gdb/gdbinit" --with-system-gdbinit-dir="/etc/gdb/gdbinit.d" \
538565
--with-jit-reader-dir="/usr/lib/gdb" \
539-
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
540-
"--with-liblzma-prefix=$liblzma_prefix" --with-liblzma-type=static --with-lzma=yes \
541-
"--with-gmp=$libgmp_prefix" \
542-
"--with-mpfr=$libmpfr_prefix" \
566+
--with-libiconv-prefix="$libiconv_prefix" --with-libiconv-type=static \
567+
--with-gmp="$libgmp_prefix" \
568+
--with-mpfr="$libmpfr_prefix" \
569+
--enable-tui \
570+
--with-expat --with-libexpat-type=static \
571+
--with-lzma=yes --with-liblzma-prefix="$liblzma_prefix" --with-liblzma-type="static" \
572+
"${extra_flags[@]}" \
543573
"CC=$CC" "CXX=$CXX" "LDFLAGS=$LDFLAGS" "--host=$HOST" \
544574
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
545575
if [[ $? -ne 0 ]]; then
@@ -563,7 +593,7 @@ function install_gdb() {
563593
# $1: gdb build directory
564594
# $2: artifacts directory
565595
# $3: target architecture
566-
# $4: whether gdb was built with or without python
596+
# $4: whether to build gdb with all extra configurations specified in src/compilation/full_build_conf.sh
567597
#
568598
# Returns:
569599
# 0: success
@@ -572,12 +602,12 @@ function install_gdb() {
572602
local gdb_build_dir="$1"
573603
local artifacts_dir="$2"
574604
local target_arch="$3"
575-
local with_python="$4"
605+
local full_build="$4"
576606

577-
if [[ "$with_python" == "yes" ]]; then
578-
local artifacts_location="$artifacts_dir/${target_arch}_with_python"
607+
if [[ "$full_build" == "yes" ]]; then
608+
local artifacts_location="$artifacts_dir/${target_arch}_full"
579609
else
580-
local artifacts_location="$artifacts_dir/${target_arch}"
610+
local artifacts_location="$artifacts_dir/${target_arch}_slim"
581611
fi
582612

583613
if [[ -d "$artifacts_location" && -n "$(ls -A "$artifacts_location")" ]]; then
@@ -608,32 +638,34 @@ function build_and_install_gdb() {
608638
# Parameters:
609639
# $1: gdb package directory
610640
# $2: libiconv prefix
611-
# $3: liblzma prefix
612-
# $4: libgmp prefix
613-
# $5: libmpfr prefix
614-
# $6: whether to build with python or not
615-
# $7: install directory
616-
# $8: target architecture
641+
# $3: libgmp prefix
642+
# $4: libmpfr prefix
643+
# $5: liblzma prefix.
644+
# $6: whether to build gdb with all extra configurations specified in src/compilation/full_build_conf.sh
645+
# $7: gdb cross-architecture binary format support formats (relevant for full builds only).
646+
# $8: install directory
647+
# $9: target architecture
617648
#
618649
# Returns:
619650
# 0: success
620651
# 1: failure
621652

622653
local gdb_dir="$1"
623654
local libiconv_prefix="$2"
624-
local liblzma_prefix="$3"
625-
local libgmp_prefix="$4"
626-
local libmpfr_prefix="$5"
627-
local with_python="$6"
628-
local artifacts_dir="$7"
629-
local target_arch="$8"
655+
local libgmp_prefix="$3"
656+
local libmpfr_prefix="$4"
657+
local liblzma_prefix="$5"
658+
local full_build="$6"
659+
local gdb_bfd_archs="$7"
660+
local artifacts_dir="$8"
661+
local target_arch="$9"
630662

631-
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$liblzma_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$with_python")"
663+
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix" "$liblzma_prefix" "$full_build" "$gdb_bfd_archs")"
632664
if [[ $? -ne 0 ]]; then
633665
return 1
634666
fi
635667

636-
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$with_python"
668+
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch" "$full_build"
637669
if [[ $? -ne 0 ]]; then
638670
return 1
639671
fi
@@ -646,12 +678,14 @@ function build_gdb_with_dependencies() {
646678
# $1: target architecture
647679
# $2: build directory
648680
# $3: src directory
649-
# $4: whether to build gdb with python or not
681+
# $4: whether to build gdb with all extra configurations specified in src/compilation/full_build_conf.sh
682+
# $5: gdb cross-architecture binary format support formats (relevant for full builds only).
650683

651684
local target_arch="$1"
652685
local build_dir="$2"
653686
local source_dir="$3"
654-
local with_python="$4"
687+
local full_build="$4"
688+
local gdb_bfd_archs="$5"
655689
local packages_dir="$build_dir/packages"
656690
local artifacts_dir="$build_dir/artifacts"
657691

@@ -667,11 +701,6 @@ function build_gdb_with_dependencies() {
667701
return 1
668702
fi
669703

670-
lzma_build_dir="$(build_lzma "$packages_dir/xz" "$target_arch")"
671-
if [[ $? -ne 0 ]]; then
672-
return 1
673-
fi
674-
675704
gmp_build_dir="$(build_libgmp "$packages_dir/gmp" "$target_arch")"
676705
if [[ $? -ne 0 ]]; then
677706
return 1
@@ -692,13 +721,19 @@ function build_gdb_with_dependencies() {
692721
return 1
693722
fi
694723

695-
set_up_lib_search_paths "$iconv_build_dir" \
696-
"$gmp_build_dir" \
697-
"$mpfr_build_dir" \
698-
"$ncursesw_build_dir" \
699-
"$libexpat_build_dir"
724+
lzma_build_dir="$(build_lzma "$packages_dir/xz" "$target_arch")"
725+
if [[ $? -ne 0 ]]; then
726+
return 1
727+
fi
728+
729+
set_up_base_lib_search_paths "$iconv_build_dir" \
730+
"$gmp_build_dir" \
731+
"$mpfr_build_dir" \
732+
"$ncursesw_build_dir" \
733+
"$libexpat_build_dir"
700734

701-
if [[ "$with_python" == "yes" ]]; then
735+
# Optional build components
736+
if [[ $full_build == "yes" && $full_build_python_support -eq 1 ]]; then
702737
local gdb_python_dir="$packages_dir/binutils-gdb/gdb/python/lib/"
703738
local pygments_source_dir="$packages_dir/pygments/"
704739
local python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch" "$gdb_python_dir" "$pygments_source_dir")"
@@ -709,10 +744,11 @@ function build_gdb_with_dependencies() {
709744

710745
build_and_install_gdb "$packages_dir/binutils-gdb" \
711746
"$iconv_build_dir" \
712-
"$lzma_build_dir" \
713747
"$gmp_build_dir" \
714748
"$mpfr_build_dir" \
715-
"$with_python" \
749+
"$lzma_build_dir" \
750+
"$full_build" \
751+
"$gdb_bfd_archs" \
716752
"$artifacts_dir" \
717753
"$target_arch"
718754
if [[ $? -ne 0 ]]; then
@@ -721,17 +757,19 @@ function build_gdb_with_dependencies() {
721757
}
722758

723759
function main() {
724-
if [[ $# -lt 3 ]]; then
725-
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir> [--with-python]"
760+
if [[ $# -lt 4 ]]; then
761+
>&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir> <slim/full> [gdb-bfd-archs]"
726762
exit 1
727763
fi
728764

729-
local with_python="no"
730-
if [[ "$4" == "--with-python" ]]; then
731-
with_python="yes"
765+
local full_build="no"
766+
if [[ "$4" == "full" ]]; then
767+
full_build="yes"
768+
else
769+
full_build="no"
732770
fi
733771

734-
build_gdb_with_dependencies "$1" "$2" "$3" "$with_python"
772+
build_gdb_with_dependencies "$1" "$2" "$3" "$full_build" "$5"
735773
if [[ $? -ne 0 ]]; then
736774
>&2 echo "Error: failed to build gdb with dependencies"
737775
exit 1

src/compilation/full_build_conf.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# This file contains the build configuration for a full build.
4+
# In order to disable a component, simply change the it to 0.
5+
# This allows us to fully control the binary extensions.
6+
7+
full_build_supported_targets=1
8+
full_build_python_support=1

0 commit comments

Comments
 (0)