@@ -599,7 +599,6 @@ build_ncurses() {
599599# Helper to build gmp, used by native gdb. Starting from
600600# GDB 11.1, it requires libgmp to be built natively [1].
601601# Arguments:
602- # $1 - target triplet
603602#
604603# [1] gdb: Make GMP a required dependency for buidling GDB
605604# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=1b4ac058f7d
@@ -629,6 +628,137 @@ build_gmp() {
629628 make_target_ordered installing install DESTDIR=$SYSROOTDIR
630629}
631630
631+ # Helper to build mpfr, used by native gdb. Since 21-Dec-2022,
632+ # GDB requires libgmp to be built natively [1].
633+ #
634+ # To build mpfr, native libgmp must have already bin built. See
635+ # build_gmp() for that matter.
636+ #
637+ # [1] Use toplevel configure for GMP and MPFR for gdb
638+ # https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=991180627851
639+ #
640+ # Note:
641+ # libmpfr must be built against the native libgmp (--with-libgmp...).
642+ # If this libgmp is built for a sysroot (--prefix=/usr), then its libtool
643+ # script (libgmp.la) contains entries that can be confused with the build
644+ # system's paths:
645+ #
646+ # $ cat /sysroot/usr/lib/libgmp.a
647+ # ...
648+ # libdir=/usr/lib
649+ #
650+ # libtool has a trick to handle these situations, when the effective
651+ # compiler's prefix is not the same as the default one in build system.
652+ # to trigger this trick, one has to pass "--with-sysroot=yes" to the
653+ # configure command [2]. This will result in a successful build AND
654+ # a leading '=' character in some of the libraries names in installed
655+ # libmpfs.la script. This leading character must be ignored on a native
656+ # system. However on a build system, it must be exapnded to the full
657+ # sysroot path. libtool >= 2.4.x is capable of doing this.
658+ #
659+ # [2]
660+ # https://bugs.gentoo.org/show_bug.cgi?id=521184#c8
661+ build_mpfr () {
662+ local triplet=$1
663+ mpfr_version=4.2.1
664+ mpfr_url_base=https://www.mpfr.org/mpfr-current
665+ mpfr_tar=mpfr-${mpfr_version} .tar.xz
666+ mpfr_url=$mpfr_url_base /$mpfr_tar
667+
668+ mkdir -p $toolchain_build_dir /_download_tmp
669+ cd $toolchain_build_dir /_download_tmp
670+ if [ ! -s $mpfr_tar ]; then
671+ $WGET -O $mpfr_tar $mpfr_url
672+ fi
673+
674+ build_dir_init mpfr
675+ tar xf $toolchain_build_dir /_download_tmp/$mpfr_tar --strip-components=1
676+
677+ configure_for_arc . $triplet \
678+ --prefix=/usr \
679+ --sysconfdir=/etc \
680+ --localstatedir=/var \
681+ --program-prefix= \
682+ --enable-static \
683+ --with-sysroot=yes \
684+ --with-gmp=$SYSROOTDIR /usr
685+
686+ make_target building
687+ make_target_ordered installing install DESTDIR=$SYSROOTDIR
688+ }
689+
690+ # This function manipulates two entries. First, it turns
691+ #
692+ # dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
693+ #
694+ # into
695+ #
696+ # #dependency_libs=' -L=/usr/lib =/usr/lib'
697+ # dependency_libs=' -L/sysroot/usr/lib /sysroot/usr/lib/libgmp.la'
698+ #
699+ # And then
700+ #
701+ # libdir='/usr/lib'
702+ #
703+ # into
704+ #
705+ # #libdir='/usr/lib'
706+ # libdir='/sysroot/usr/lib'
707+ #
708+ # Rationale
709+ # ---------
710+ # libmpfr, which is needed for building gdb, installs with a libtool
711+ # script (*.la) with the following entry:
712+ #
713+ # $ cat /sysroot/usr/lib/libmpfr.la
714+ # ...
715+ # dependency_libs=' -L=/usr/lib =/usr/lib/libgmp.la'
716+ #
717+ # The leading '=' character indicates to libtool that this is a
718+ # sysroot path and must be replaced with whatever the compiler returns
719+ # as the sysroot: arc-snps-linux-gnu-gcc --print-sysroot
720+ #
721+ # libtool v2.2.7 that ships with GDB is not recent enough (v2.4+) to
722+ # expand these. Therefore, this function will expand those pesky equal
723+ # signs. Same sort of story goes for 'libdir'. libtool 2.4+ provides
724+ # a "func_resolve_sysroot()" that turns "/usr/lib" into full path on a
725+ # build machine.
726+ la_expand_libs () {
727+ local la_file=" $1 "
728+
729+ # Duplicate the "dependency_libs=" line while
730+ # keeping the original instance commented out
731+ $SED -i " s/^\(dependency_libs=.*\)/#\1\n\1/" $la_file
732+
733+ # The '=' in '-L=.* should be replaced by SYSROOTDIR
734+ # The '=' in ' =/usr/lib/.*' should be replaced by SYSROOTDIR
735+ $SED -i \
736+ -e " /^dependency_libs=/ s,-L=,-L$SYSROOTDIR ,g" \
737+ -e " /^dependency_libs=/ s, =, $SYSROOTDIR ,g" \
738+ $la_file
739+
740+ # Duplicate the "libdir=" line ...
741+ $SED -i " s/^\(libdir=.*\)/#\1\n\1/" $la_file
742+
743+ # Add SYSROOTDIR to the beginning of the path in "libdir"
744+ $SED -i " /^libdir=/ s,=',='$SYSROOTDIR ," $la_file
745+ }
746+
747+ # Remove the manipulated paths and uncomment the original ones.
748+ la_restore_libs () {
749+ local la_file=" $1 "
750+
751+ $SED -i \
752+ -e " /^dependency_libs=/d" \
753+ -e " s/^#\(dependency_libs=.*\)/\1/" \
754+ $la_file
755+
756+ $SED -i \
757+ -e " /^libdir=/d" \
758+ -e " s/^#\(libdir=.*\)/\1/" \
759+ $la_file
760+ }
761+
632762# $1 - a configuration file or a directory with .config
633763# $2 - option to enable
634764kconfig_enable_option () {
0 commit comments