commit:     72925b1dccebbf082c31a2be89c7693d966ecd54
Author:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
AuthorDate: Mon Dec 26 22:32:02 2022 +0000
Commit:     James Le Cuirot <chewi <AT> gentoo <DOT> org>
CommitDate: Sat Jan 28 22:11:16 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=72925b1d

toolchain.eclass: Fix cross-compiling gcc for standalone prefix

Standalone prefix has always configured gcc with a sysroot, but the
location of this sysroot is different at build time when
cross-compiling. gcc has a separate configure option for that.

prefix-guest systems do not have a sysroot applied, as they use the
host's libc.

Move this code from the prefix profile into the eclass so that it's less
of a special case. We can avoid relying on the `BOOTSTRAP_RAP_STAGE2`
variable by checking for the `prefix-guest` USE flag instead, as a
prefix-guest profile is now used for RAP stage 2.

Signed-off-by: James Le Cuirot <chewi <AT> gentoo.org>

 eclass/toolchain.eclass                            | 15 +++++++++++++++
 profiles/features/prefix/standalone/profile.bashrc |  3 ---
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index 0dd23d93e383..479814f0df3e 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -1200,6 +1200,21 @@ toolchain_src_configure() {
                                confgcc+=( --enable-threads=posix )
                                ;;
                esac
+
+               if ! use prefix-guest ; then
+                       # GNU ld scripts, such as those in glibc, reference 
unprefixed paths
+                       # as the sysroot given here is automatically prepended. 
For
+                       # prefix-guest, we use the host's libc instead.
+                       if [[ -n ${EPREFIX} ]] ; then
+                               confgcc+=( --with-sysroot="${EPREFIX}" )
+                       fi
+
+                       # We need to build against the right headers and 
libraries. Again,
+                       # for prefix-guest, this is the host's.
+                       if [[ -n ${ESYSROOT} ]] ; then
+                               confgcc+=( --with-build-sysroot="${ESYSROOT}" )
+                       fi
+               fi
        fi
 
        # __cxa_atexit is "essential for fully standards-compliant handling of

diff --git a/profiles/features/prefix/standalone/profile.bashrc 
b/profiles/features/prefix/standalone/profile.bashrc
index 3cdda77b9a88..043f766c37e9 100644
--- a/profiles/features/prefix/standalone/profile.bashrc
+++ b/profiles/features/prefix/standalone/profile.bashrc
@@ -21,9 +21,6 @@ if [[ ${CATEGORY}/${PN} == sys-devel/gcc && ${EBUILD_PHASE} 
== configure ]]; the
        fi
        eend $?
     done
-
-    # use sysroot of toolchain to get correct include and library at compile 
time
-    EXTRA_ECONF="${EXTRA_ECONF} --with-sysroot=${EPREFIX}"
 elif [[ ${CATEGORY}/${PN} == sys-devel/clang && ${EBUILD_PHASE} == configure 
]]; then
     ebegin "Use ${EPREFIX} as default sysroot"
     sed -i -e "s@DEFAULT_SYSROOT \"\"@DEFAULT_SYSROOT \"${EPREFIX}\"@" 
"${S}"/CMakeLists.txt

Reply via email to