@@ -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
515539function 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