commit:     ca82c7fd37522d32124e0fe06384a9c2f5387dcf
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Dec  3 23:24:49 2014 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Dec  3 23:24:49 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=dev/mgorny.git;a=commit;h=ca82c7fd

sys-devel/gcc: Add supposedly universal multilib support

Package-Manager: portage-2.2.14

---
 sys-devel/gcc/gcc-4.9.2-r100.ebuild | 98 +++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 43 deletions(-)

diff --git a/sys-devel/gcc/gcc-4.9.2-r100.ebuild 
b/sys-devel/gcc/gcc-4.9.2-r100.ebuild
index 3ef83c8..f243294 100644
--- a/sys-devel/gcc/gcc-4.9.2-r100.ebuild
+++ b/sys-devel/gcc/gcc-4.9.2-r100.ebuild
@@ -12,7 +12,15 @@ PIE_VER="0.6.1"
 SPECS_VER="0.2.0"
 SPECS_GCC_VER="4.4.3"
 
-inherit eutils flag-o-matic multilib toolchain-funcs
+# ABIs supported by gcc/ebuild.
+MULTILIB_COMPAT=(
+       abi_x86_32 abi_x86_64 abi_x86_x32
+       abi_mips_n32 abi_mips_n64 abi_mips_o32
+       abi_ppc_32 abi_ppc_64
+       abi_s390_32 abi_s390_64
+)
+
+inherit eutils flag-o-matic multilib multilib-build toolchain-funcs
 
 DESCRIPTION="The GNU Compiler Collection"
 HOMEPAGE="http://gcc.gnu.org/";
@@ -25,8 +33,8 @@ SRC_URI="mirror://gnu/${PN}/${P}/${P}.tar.bz2
 LICENSE="GPL-3+ LGPL-3+ || ( GPL-3+ libgcc libstdc++ 
gcc-runtime-library-exception-3.1 ) FDL-1.3+"
 SLOT="${PV%.*}"
 KEYWORDS="~amd64 ~x86"
-IUSE="abi_x86_32 abi_x86_64 abi_x86_x32
-       altivec +cxx doc fixed-point +fortran go graphite hardened libssp
+
+IUSE="altivec +cxx doc fixed-point +fortran go graphite hardened libssp
        multilib +nls +nptl objc objc-gc objc++ +openmp +pie +sanitize
        test vanilla"
 
@@ -161,21 +169,24 @@ src_prepare() {
        ./contrib/gcc_update --touch
 }
 
-gcc-abi-map() {
-       # Convert the ABI name we use in Gentoo to what gcc uses
-       local map=()
-       case ${CTARGET} in
-               mips*)   map=("o32 32" "n32 n32" "n64 64") ;;
-               x86_64*) map=("amd64 m64" "x86 m32" "x32 mx32") ;;
+# Map Gentoo ABI into gcc ABI, for MIPS.
+get_gcc_mips_abi() {
+       case ${1} in
+               o32) echo 32;;
+               n32) echo n32;;
+               n64) echo 64;;
+               *) die "Invalid MIPS ABI: ${1}";;
        esac
+}
 
-       local m
-       for m in "${map[@]}" ; do
-               if [[ $1 == ${l% *} ]]; then
-                       echo "${l#* }"
-                       break
-               fi
-       done
+# Map Gentoo ABI into gcc ABI, for amd64.
+get_gcc_amd64_abi() {
+       case ${1} in
+               x86*) echo m32;;
+               amd64*) echo m64;;
+               x32) echo mx32;;
+               *) die "Invalid AMD64 ABI: ${1}";;
+       esac
 }
 
 src_configure() {
@@ -253,7 +264,6 @@ src_configure() {
                # mips fixed-point arithmetic
                $(use_enable fixed-point)
 
-               $(use_enable multilib)
                $(use_enable openmp libgomp)
                --disable-libmudflap
                $(use_enable libssp)
@@ -295,20 +305,6 @@ src_configure() {
        : ${TARGET_MULTILIB_ABIS:=${MULTILIB_ABIS}}
        : ${TARGET_DEFAULT_ABI:=${DEFAULT_ABI}}
 
-       # translate our notion of multilibs into gcc's
-       local abi list
-       for abi in $(get_all_abis TARGET); do
-               local l=$(gcc-abi-map ${abi})
-               [[ -n ${l} ]] && list+=",${l}"
-       done
-       if [[ -n ${list} ]] ; then
-               case ${CTARGET} in
-               x86_64*)
-                       myconf+=( --with-multilib-list=${list:1} )
-                       ;;
-               esac
-       fi
-
        case $(tc-is-softfloat) in
                yes)    myconf+=( --with-float=soft ) ;;
                softfp) myconf+=( --with-float=softfp ) ;;
@@ -320,7 +316,24 @@ src_configure() {
                        esac
        esac
 
-       local with_abi_map=()
+       # Multilib guessing.
+       # From this point forward, ABI variables may correspond to CTARGET.
+       [[ ${CHOST} != ${CTARGET} ]] && multilib_env "${CTARGET}"
+       local abis=( $(multilib_get_enabled_abis) )
+
+       # isn't that brilliant?
+       if [[ ${#abis[@]} -gt 1 ]]; then
+               myconf+=( --enable-multilib )
+       else
+               myconf+=( --disable-multilib )
+       fi
+
+       # now, verify!
+       # (abis may be empty on non-multilib arches)
+       if [[ ${abis[@]} ]] && ! has "${DEFAULT_ABI}" "${abis[@]}"; then
+               die "DEFAULT_ABI ${DEFAULT_ABI} not enabled (USE 
misconfiguration?)"
+       fi
+
        case $(tc-arch) in
                arm) #264534 #414395
                        local a arm_arch=${CTARGET%%-*}
@@ -355,20 +368,19 @@ src_configure() {
                        fi
                        ;;
                mips)
-                       # Add --with-abi flags to set default ABI
-                       myconf+=( --with-abi=$(gcc-abi-map 
"${TARGET_DEFAULT_ABI}") )
+                       myconf+=( --with-abi="$(get_gcc_mips_abi 
"${DEFAULT_ABI}")" )
                        ;;
                amd64)
-                       local abis=()
-                       use abi_x86_32 && abis+=( m32 )
-                       use abi_x86_64 && abis+=( m64 )
-                       use abi_x86_x32 && abis+=( mx32 )
-                       abis=${abis[*]}
+                       local a gcc_abis=()
+                       for a in "${abis[@]}"; do
+                               gcc_abis+=( "$(get_gcc_amd64_abi "${a}")" )
+                       done
+                       gcc_abis=${gcc_abis[*]}
 
                        myconf+=(
                                --enable-multilib
-                               --with-multilib-list="${abis// /,}"
-                               --with-abi="$(gcc-abi-map 
"${TARGET_DEFAULT_ABI}")"
+                               --with-multilib-list="${gcc_abis// /,}"
+                               --with-abi="$(get_gcc_amd64_abi 
"${DEFAULT_ABI}")"
                        )
                        ;;
                x86)
@@ -416,7 +428,7 @@ src_compile() {
                LDFLAGS="${LDFLAGS}" \
                STAGE1_CFLAGS="${CFLAGS}" \
                LIBPATH="${LIBPATH}" \
-               BOOT_CFLAGS="$(get_abi_CFLAGS "${TARGET_DEFAULT_ABI}") 
${CFLAGS}"
+               BOOT_CFLAGS="$(get_abi_CFLAGS "${DEFAULT_ABI}") ${CFLAGS}"
 
        if use cxx && use doc; then
                emake -C "${WORKDIR}"/build/"${CTARGET}"/libstdc++-v3/doc \
@@ -490,7 +502,7 @@ create_gcc_env_entry() {
        # workaround for libtool being stupid and using .la's from
        # conflicting ABIs by using the first one in the search path
        local ldpaths mosdirs mdir mosdir abi ldpath
-       for abi in $(get_all_abis TARGET) ; do
+       for abi in $(get_all_abis) ; do
                mdir=$($(XGCC) $(get_abi_CFLAGS ${abi}) --print-multi-directory)
                ldpath=${LIBPATH}
                [[ ${mdir} != "." ]] && ldpath+="/${mdir}"

Reply via email to