|
2 | 2 |
|
3 | 3 | # Include utils library
|
4 | 4 | script_dir=$(dirname "$0")
|
5 |
| -. "$script_dir/utils.sh" |
| 5 | +source "$script_dir/utils.sh" |
6 | 6 |
|
7 | 7 | function set_compliation_variables() {
|
8 | 8 | # Set compilation variables such as which compiler to use.
|
@@ -208,6 +208,64 @@ function build_ncurses() {
|
208 | 208 | popd > /dev/null
|
209 | 209 | }
|
210 | 210 |
|
| 211 | +function build_python() { |
| 212 | + # Build python. |
| 213 | + # |
| 214 | + # Parameters: |
| 215 | + # $1: python package directory |
| 216 | + # $2: target architecture |
| 217 | + # |
| 218 | + # Echoes: |
| 219 | + # The python build directory |
| 220 | + # |
| 221 | + # Returns: |
| 222 | + # 0: success |
| 223 | + # 1: failure |
| 224 | + local python_dir="$1" |
| 225 | + local target_arch="$2" |
| 226 | + local python_lib_dir="$(realpath "$python_dir/build-$target_arch")" |
| 227 | + |
| 228 | + echo "$python_lib_dir" |
| 229 | + mkdir -p "$python_lib_dir" |
| 230 | + |
| 231 | + # Having a python-config file is an indication that we successfully built python. |
| 232 | + if [[ -f "$python_lib_dir/python-config" ]]; then |
| 233 | + >&2 echo "Skipping build: libpython already built for $target_arch" |
| 234 | + return 0 |
| 235 | + fi |
| 236 | + |
| 237 | + pushd "$python_lib_dir" > /dev/null |
| 238 | + >&2 fancy_title "Building python for $target_arch" |
| 239 | + |
| 240 | + export LINKFORSHARED=" " |
| 241 | + export MODULE_BUILDTYPE="static" |
| 242 | + export CONFIG_SITE="$python_dir/config.site-static" |
| 243 | + >&2 CFLAGS="-static" LDFLAGS="-static" ../configure \ |
| 244 | + --prefix=$(realpath .) \ |
| 245 | + --disable-test-modules \ |
| 246 | + --with-ensurepip=no \ |
| 247 | + --without-decimal-contextvar \ |
| 248 | + --build=x86_64-pc-linux-gnu \ |
| 249 | + --host=$HOST \ |
| 250 | + --with-build-python=/usr/bin/python3.12 \ |
| 251 | + --disable-ipv6 \ |
| 252 | + --disable-shared |
| 253 | + |
| 254 | + >&2 make -j $(nproc) |
| 255 | + if [[ $? -ne 0 ]]; then |
| 256 | + return 1 |
| 257 | + fi |
| 258 | + |
| 259 | + # Install python (in build dir using the prefix set above), in order to have a bash (for cross-compilation) python3-config that works. |
| 260 | + >&2 make install |
| 261 | + if [[ $? -ne 0 ]]; then |
| 262 | + return 1 |
| 263 | + fi |
| 264 | + |
| 265 | + >&2 fancy_title "Finished building python for $target_arch" |
| 266 | + popd > /dev/null |
| 267 | +} |
| 268 | + |
211 | 269 | function build_libmpfr() {
|
212 | 270 | # Build libmpfr.
|
213 | 271 | #
|
@@ -298,7 +356,8 @@ function build_gdb() {
|
298 | 356 |
|
299 | 357 | >&2 fancy_title "Building gdb for $target_arch"
|
300 | 358 |
|
301 |
| - ../configure --enable-static --enable-tui --with-static-standard-libraries --disable-inprocess-agent \ |
| 359 | + ../configure -C --enable-static --with-static-standard-libraries --disable-inprocess-agent \ |
| 360 | + --enable-tui --with-python=/app/gdb/build/packages/cpython-static/build-$target_arch/bin/python3-config \ |
302 | 361 | "--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
|
303 | 362 | "--with-gmp=$libgmp_prefix" \
|
304 | 363 | "--with-mpfr=$libmpfr_prefix" \
|
@@ -395,9 +454,11 @@ function build_gdb_with_dependencies() {
|
395 | 454 | # Parameters:
|
396 | 455 | # $1: target architecture
|
397 | 456 | # $2: build directory
|
| 457 | + # $3: src directory |
398 | 458 |
|
399 | 459 | local target_arch="$1"
|
400 | 460 | local build_dir="$2"
|
| 461 | + local source_dir="$3" |
401 | 462 | local packages_dir="$build_dir/packages"
|
402 | 463 | local artifacts_dir="$build_dir/artifacts"
|
403 | 464 |
|
@@ -427,27 +488,31 @@ function build_gdb_with_dependencies() {
|
427 | 488 | if [[ $? -ne 0 ]]; then
|
428 | 489 | return 1
|
429 | 490 | fi
|
430 |
| - |
431 | 491 | set_ncurses_link_variables "$ncursesw_build_dir"
|
432 | 492 |
|
433 |
| - build_and_install_gdb "$packages_dir/gdb" \ |
434 |
| - "$iconv_build_dir/lib/.libs/" \ |
435 |
| - "$gmp_build_dir/.libs/" \ |
436 |
| - "$mpfr_build_dir/src/.libs/" \ |
437 |
| - "$artifacts_dir" \ |
438 |
| - "$target_arch" |
| 493 | + python_build_dir="$(build_python "$packages_dir/cpython-static" "$target_arch")" |
| 494 | + if [[ $? -ne 0 ]]; then |
| 495 | + return 1 |
| 496 | + fi |
| 497 | + |
| 498 | + build_and_install_gdb "$packages_dir/binutils-gdb" \ |
| 499 | + "$iconv_build_dir/lib/.libs/" \ |
| 500 | + "$gmp_build_dir/.libs/" \ |
| 501 | + "$mpfr_build_dir/src/.libs/" \ |
| 502 | + "$artifacts_dir" \ |
| 503 | + "$target_arch" |
439 | 504 | if [[ $? -ne 0 ]]; then
|
440 | 505 | return 1
|
441 | 506 | fi
|
442 | 507 | }
|
443 | 508 |
|
444 | 509 | function main() {
|
445 | 510 | if [[ $# -ne 3 ]]; then
|
446 |
| - >&2 echo "Usage: $0 <target_arch> <build_dir>" |
| 511 | + >&2 echo "Usage: $0 <target_arch> <build_dir> <src_dir>" |
447 | 512 | exit 1
|
448 | 513 | fi
|
449 | 514 |
|
450 |
| - build_gdb_with_dependencies "$1" "$2" |
| 515 | + build_gdb_with_dependencies "$1" "$2" "$3" |
451 | 516 | if [[ $? -ne 0 ]]; then
|
452 | 517 | >&2 echo "Error: failed to build gdb with dependencies"
|
453 | 518 | exit 1
|
|
0 commit comments