33# Include utils library
44script_dir=$( dirname " $0 " )
55source " $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!
89set -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
85103function 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
723759function 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
0 commit comments