@@ -373,6 +373,100 @@ function build_libexpat() {
373373 popd > /dev/null
374374}
375375
376+ function build_libffi() {
377+ # Build libffi, for the ctypes python module.
378+ #
379+ # Parameters:
380+ # $1: libffi package directory
381+ # $2: Target architecture
382+ local libffi_dir=" $1 "
383+ local target_arch=" $2 "
384+
385+ pushd " ${libffi_dir} " > /dev/null
386+
387+ local libffi_build_dir=" $( realpath " $libffi_dir /build-$target_arch " ) "
388+
389+ # libffi needs a custom install dir due to it's non-standard compilation directories.
390+ local libffi_install_dir=" $libffi_build_dir /output"
391+ echo " ${libffi_install_dir} "
392+
393+ # Creates both the installation and build dirs because install is in build.
394+ mkdir -p " ${libffi_install_dir} "
395+
396+ if [[ -f " $libffi_install_dir /lib/libffi.a" ]]; then
397+ >&2 echo " Skipping build: libffi already built for $target_arch "
398+ return 0
399+ fi
400+
401+ >&2 ./autogen.sh
402+ pushd " ${libffi_build_dir} " > /dev/null
403+
404+ >&2 fancy_title " Building libffi for $target_arch "
405+
406+ >&2 CFLAGS=" ${CFLAGS} -DNO_JAVA_RAW_API" ../configure \
407+ --enable-silent-rules \
408+ --enable-static \
409+ --disable-shared \
410+ --disable-docs \
411+ --prefix=" ${libffi_install_dir} "
412+ if [[ $? -ne 0 ]]; then
413+ return 1
414+ fi
415+
416+ >&2 make -j$( nproc)
417+ if [[ $? -ne 0 ]]; then
418+ return 1
419+ fi
420+
421+ >&2 make -j$( nproc) install
422+ if [[ $? -ne 0 ]]; then
423+ return 1
424+ fi
425+
426+ >&2 fancy_title " Finished building libffi for $target_arch "
427+
428+ popd > /dev/null
429+ popd > /dev/null
430+ }
431+
432+ function add_to_pkg_config_path() {
433+ # This method add directories to the list that pkg-config looks for .pc (package config) files
434+ # when finding the correct flags for modules.
435+ #
436+ # Parameters:
437+ # $1: The directory to add to the package-config path.
438+ local new_pkg_config_dir=" ${1} "
439+
440+ if [[ -n " ${PKG_CONFIG_PATH} " ]]; then
441+ export PKG_CONFIG_PATH=" ${PKG_CONFIG_PATH} :${new_pkg_config_dir} "
442+ else
443+ export PKG_CONFIG_PATH=" ${new_pkg_config_dir} "
444+ fi
445+ }
446+
447+ function setup_libffi_env() {
448+ # We need a valid pkg-config file for libffi in order for Python to recognize the package and
449+ # know that it exists. Because we a pkg-config file, we might as well use it in order to ensure
450+ # that we get the correct flags instead of manually typing them.
451+ # Becuase of this, the setup of libffi isn't done in set_up_lib_search_path, as we don't need it.
452+ #
453+ # Parameters:
454+ # $1: Libffi installation dir
455+ local libffi_install_dir=" $1 "
456+
457+ # Needed because this is how Python recognizes the available packages.
458+ add_to_pkg_config_path " ${libffi_install_dir} /lib/pkgconfig/"
459+
460+ # If we have a pc file, might as well use it.
461+ local libffi_cflags=" $( pkg-config --cflags libffi) "
462+ local libffi_libs=" $( pkg-config --libs --static libffi) "
463+
464+ export CC=" ${CC} ${libffi_cflags} "
465+ export CXX=" ${CXX} ${libffi_cflags} "
466+
467+ export LDFLAGS=" ${libffi_libs} ${LDFLAGS} "
468+ }
469+
376470function build_python() {
377471 # Build python.
378472 #
@@ -428,10 +522,17 @@ function build_python() {
428522 # Regenerate frozen modules with gdb env varaible. Do it after the configure because we need
429523 # the `regen-frozen` makefile.
430524 >&2 python3.12 ../Tools/build/freeze_modules.py
525+ if [[ $? -ne 0 ]]; then
526+ return 1
527+ fi
528+
431529 >&2 make regen-frozen
530+ if [[ $? -ne 0 ]]; then
531+ return 1
532+ fi
432533
433534 # Build python after configuring the project and regnerating frozen files.
434- >&2 make -j $( nproc)
535+ >&2 make -j$( nproc)
435536 if [[ $? -ne 0 ]]; then
436537 return 1
437538 fi
@@ -734,6 +835,9 @@ function build_gdb_with_dependencies() {
734835
735836 # Optional build components
736837 if [[ $full_build == " yes" && $full_build_python_support -eq 1 ]]; then
838+ local libffi_install_dir=" $( build_libffi " ${packages_dir} /libffi" " ${target_arch} " ) "
839+ setup_libffi_env " ${libffi_install_dir} "
840+
737841 local gdb_python_dir=" $packages_dir /binutils-gdb/gdb/python/lib/"
738842 local pygments_source_dir=" $packages_dir /pygments/"
739843 local python_build_dir=" $( build_python " $packages_dir /cpython-static" " $target_arch " " $gdb_python_dir " " $pygments_source_dir " ) "
0 commit comments