--- eclass/multilib.eclass 2005/11/30 09:59:17 1.1.1.1 +++ eclass/multilib.eclass 2012/10/17 19:13:18 1.101 @@ -1,97 +1,19 @@ -# Copyright 1999-2004 Gentoo Foundation +# Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/multilib.eclass,v 1.1.1.1 2005/11/30 09:59:17 chriswhite Exp $ -# -# Author: Jeremy Huddleston -# -# This eclass is for all functions pertaining to handling multilib. -# configurations. - -DESCRIPTION="Based on the ${ECLASS} eclass" - -# has_multilib_profile: -# Return true if the current profile is a multilib profile and lists more than -# one abi in ${MULTILIB_ABIS}. You might want to use this like -# 'use multilib || has_multilib_profile' until all profiles utilizing the -# 'multilib' use flag are removed from portage - -# is_final_abi: -# Return true if ${ABI} is the final abi to be installed (and thus we are -# on our last run through a src_* function. - -# number_abis: -# echo the number of ABIs we will be installing for - -# get_install_abis: -# Return a list of the ABIs we want to install for with -# the last one in the list being the default. - -# get_all_abis: -# Return a list of the ABIs supported by this profile. -# the last one in the list being the default. - -# get_all_libdirs: -# Returns a list of all the libdirs used by this profile. This includes -# those that might not be touched by the current ebuild and always includes -# "lib". - -# get_libdir: -# Returns the libdir for the selected ABI. This is backwards compatible -# and simply calls get_abi_LIBDIR() on newer profiles. You should use this -# to determine where to install shared objects (ex: /usr/$(get_libdir)) +# $Header: /var/cvsroot/gentoo-x86/eclass/multilib.eclass,v 1.101 2012/10/17 19:13:18 vapier Exp $ -# get_abi_var []: -# returns the value of ${_} which should be set in make.defaults -# -# get_abi_CFLAGS: -# get_abi_CDEFINE: -# get_abi_LIBDIR: -# Aliases for 'get_abi_var CFLAGS', etc. - -# get_ml_incdir [ []] -# include dir defaults to /usr/include -# ABI defaults to ${ABI} or ${DEFAULT_ABI} -# -# If a multilib include dir is associated with the passed include dir, then -# we return it, otherwise, we just echo back the include dir. This is -# neccessary when a built script greps header files rather than testing them -# via #include (like perl) to figure out features. - -# prep_ml_includes: -# Some includes (include/asm, glibc, etc) are ABI dependent. In this case, -# We can install them in different locations for each ABI and create a common -# header which includes the right one based on CDEFINE_${ABI}. If your -# package installs ABI-specific headers, just add 'prep_ml_includes' to the -# end of your src_install(). It takes a list of directories that include -# files are installed in (default is /usr/include if none are passed). -# -# Example: -# src_install() { -# ... -# prep_ml_includes /usr/qt/3/include -# } - -# create_ml_includes : [: ...] -# If you need more control than prep_ml_includes can offer (like linux-headers -# for the asm-* dirs, then use create_ml_includes. The firs argument is the -# common dir. The remaining args are of the form : where -# is what is put in the #ifdef for choosing that dir. -# -# Ideas for this code came from debian's sparc-linux headers package. -# -# Example: -# create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64 -# create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64 +# @ECLASS: multilib.eclass +# @MAINTAINER: +# amd64@gentoo.org +# toolchain@gentoo.org +# @BLURB: This eclass is for all functions pertaining to handling multilib configurations. +# @DESCRIPTION: +# This eclass is for all functions pertaining to handling multilib configurations. -# get_libname [version] -# returns libname with proper suffix {.so,.dylib} and optionally supplied version -# for ELF/MACH-O shared objects -# -# Example: -# get_libname libfoo ${PV} -# Returns: libfoo.so.${PV} (ELF) || libfoo.${PV}.dylib (MACH) +if [[ ${___ECLASS_ONCE_MULTILIB} != "recur -_+^+_- spank" ]] ; then +___ECLASS_ONCE_MULTILIB="recur -_+^+_- spank" -### END DOCUMENTATION ### +inherit toolchain-funcs # Defaults: export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"} @@ -101,21 +23,27 @@ export CHOST_default=${CHOST_default:-${CHOST}} export CTARGET_default=${CTARGET_default:-${CTARGET:-${CHOST_default}}} export LIBDIR_default=${CONF_LIBDIR:-"lib"} -export CDEFINE_default="__unix__" +export KERNEL_ABI=${KERNEL_ABI:-${DEFAULT_ABI}} -# has_multilib_profile() +# @FUNCTION: has_multilib_profile +# @DESCRIPTION: +# Return true if the current profile is a multilib profile and lists more than +# one abi in ${MULTILIB_ABIS}. When has_multilib_profile returns true, that +# profile should enable the 'multilib' use flag. This is so you can DEPEND on +# a package only for multilib or not multilib. has_multilib_profile() { [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ] } +# @FUNCTION: get_libdir +# @RETURN: the libdir for the selected ABI +# @DESCRIPTION: # This function simply returns the desired lib directory. With portage # 2.0.51, we now have support for installing libraries to lib32/lib64 # to accomidate the needs of multilib systems. It's no longer a good idea # to assume all libraries will end up in lib. Replace any (sane) instances # where lib is named directly with $(get_libdir) if possible. # -# Travis Tilley (24 Aug 2004) -# # Jeremy Huddleston (23 Dec 2004): # Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set, # fall back on old behavior. Any profile that has these set should also @@ -131,38 +59,11 @@ fi } -get_multilibdir() { - if has_multilib_profile; then - eerror "get_multilibdir called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org" - exit 1 - fi - echo ${CONF_MULTILIBDIR:=lib32} -} - -# Sometimes you need to override the value returned by get_libdir. A good -# example of this is xorg-x11, where lib32 isnt a supported configuration, -# and where lib64 -must- be used on amd64 (for applications that need lib -# to be 32bit, such as adobe acrobat). Note that this override also bypasses -# portage version sanity checking. -# get_libdir_override expects one argument, the result get_libdir should -# return: -# -# get_libdir_override lib64 -# -# Travis Tilley (31 Aug 2004) -get_libdir_override() { - if has_multilib_profile; then - eerror "get_libdir_override called, but it shouldn't be needed with the new multilib approach. Please file a bug at http://bugs.gentoo.org and assign it to eradicator@gentoo.org" - exit 1 - fi - CONF_LIBDIR="$1" - CONF_LIBDIR_OVERRIDE="$1" - LIBDIR_default="$1" -} - -# get_abi_var [] -# returns the value of ${_} which should be set in make.defaults -# +# @FUNCTION: get_abi_var +# @USAGE: [ABI] +# @RETURN: returns the value of ${_} which should be set in make.defaults +# @INTERNAL +# @DESCRIPTION: # ex: # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32 # @@ -172,56 +73,73 @@ # If is not specified, ${ABI} is used. # If is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used. # If is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string. -# -# Jeremy Huddleston get_abi_var() { local flag=$1 - local abi - if [ $# -gt 1 ]; then - abi=${2} - elif [ -n "${ABI}" ]; then - abi=${ABI} - elif [ -n "${DEFAULT_ABI}" ]; then - abi=${DEFAULT_ABI} - else - abi="default" - fi - + local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}} local var="${flag}_${abi}" echo ${!var} } +# @FUNCTION: get_abi_CFLAGS +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var CFLAGS' get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; } + +# @FUNCTION: get_abi_LDFLAGS +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var LDFLAGS' get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; } + +# @FUNCTION: get_abi_CHOST +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var CHOST' get_abi_CHOST() { get_abi_var CHOST "$@"; } + +# @FUNCTION: get_abi_CTARGET +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var CTARGET' get_abi_CTARGET() { get_abi_var CTARGET "$@"; } + +# @FUNCTION: get_abi_FAKE_TARGETS +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var FAKE_TARGETS' get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; } -get_abi_CDEFINE() { get_abi_var CDEFINE "$@"; } + +# @FUNCTION: get_abi_LIBDIR +# @USAGE: [ABI] +# @DESCRIPTION: +# Alias for 'get_abi_var LIBDIR' get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; } +# @FUNCTION: get_install_abis +# @DESCRIPTION: # Return a list of the ABIs we want to install for with # the last one in the list being the default. get_install_abis() { - local order="" + local x order="" if [[ -z ${MULTILIB_ABIS} ]] ; then echo "default" return 0 fi - if hasq multilib-pkg-force ${RESTRICT} || - { hasq multilib-pkg ${FEATURES} && hasq multilib-pkg ${RESTRICT}; }; then + if [[ ${EMULTILIB_PKG} == "true" ]] ; then for x in ${MULTILIB_ABIS} ; do if [[ ${x} != "${DEFAULT_ABI}" ]] ; then - hasq ${x} ${ABI_DENY} || ordera="${ordera} ${x}" + has ${x} ${ABI_DENY} || order="${order} ${x}" fi done - hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${ordera} ${DEFAULT_ABI}" + has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}" if [[ -n ${ABI_ALLOW} ]] ; then local ordera="" for x in ${order} ; do - if hasq ${x} ${ABI_ALLOW} ; then + if has ${x} ${ABI_ALLOW} ; then ordera="${ordera} ${x}" fi done @@ -239,319 +157,125 @@ return 0 } +# @FUNCTION: get_all_abis +# @DESCRIPTION: # Return a list of the ABIs supported by this profile. # the last one in the list being the default. get_all_abis() { - local order="" + local x order="" mvar dvar - if [[ -z ${MULTILIB_ABIS} ]] ; then + mvar="MULTILIB_ABIS" + dvar="DEFAULT_ABI" + if [[ -n $1 ]] ; then + mvar="$1_${mvar}" + dvar="$1_${dvar}" + fi + + if [[ -z ${!mvar} ]] ; then echo "default" return 0 fi - for x in ${MULTILIB_ABIS}; do - if [[ ${x} != ${DEFAULT_ABI} ]] ; then + for x in ${!mvar}; do + if [[ ${x} != ${!dvar} ]] ; then order="${order:+${order} }${x}" fi done - order="${order:+${order} }${DEFAULT_ABI}" + order="${order:+${order} }${!dvar}" echo ${order} return 0 } -# get_all_libdirs() +# @FUNCTION: get_all_libdirs +# @DESCRIPTION: # Returns a list of all the libdirs used by this profile. This includes -# those that might not be touched by the current ebuild. +# those that might not be touched by the current ebuild and always includes +# "lib". get_all_libdirs() { - local libdirs="lib" - local abi - local dir - - if has_multilib_profile; then - for abi in ${MULTILIB_ABIS}; do - [ "$(get_abi_LIBDIR ${abi})" != "lib" ] && libdirs="${libdirs} $(get_abi_LIBDIR ${abi})" - done - elif [ -n "${CONF_LIBDIR}" ]; then - for dir in ${CONF_LIBDIR} ${CONF_MULTILIBDIR:-lib32}; do - [ "${dir}" != "lib" ] && libdirs="${libdirs} ${dir}" - done - fi + local libdirs abi + + for abi in ${MULTILIB_ABIS}; do + libdirs+=" $(get_abi_LIBDIR ${abi})" + done + [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib" echo "${libdirs}" } +# @FUNCTION: is_final_abi +# @DESCRIPTION: # Return true if ${ABI} is the last ABI on our list (or if we're not # using the new multilib configuration. This can be used to determine # if we're in the last (or only) run through src_{unpack,compile,install} is_final_abi() { has_multilib_profile || return 0 - local ALL_ABIS=$(get_install_abis) - local LAST_ABI=${ALL_ABIS/* /} - [[ ${LAST_ABI} == ${ABI} ]] + set -- $(get_install_abis) + local LAST_ABI=$# + [[ ${!LAST_ABI} == ${ABI} ]] } +# @FUNCTION: number_abis +# @DESCRIPTION: # echo the number of ABIs we will be installing for number_abis() { - get_install_abis | wc -w + set -- `get_install_abis` + echo $# } -# get_ml_incdir [ []] -# include dir defaults to /usr/include -# ABI defaults to ${ABI} or ${DEFAULT_ABI} -get_ml_incdir() { - local dir=/usr/include - - if [[ $# -gt 0 ]]; then - incdir=$1 - shift - fi - - if [[ -z "${MULTILIB_ABIS}" ]]; then - echo ${incdir} - return 0 - fi - - local abi=${ABI-${DEFAULT_ABI}} - if [[ $# -gt 0 ]]; then - abi=$1 - shift - fi - - if [[ -d "${dir}/gentoo-multilib/${abi}" ]]; then - echo ${dir}/gentoo-multilib/${abi} - else - echo ${dir} - fi -} - -# prep_ml_includes: -# -# Some includes (include/asm, glibc, etc) are ABI dependent. In this case, -# We can install them in different locations for each ABI and create a common -# header which includes the right one based on CDEFINE_${ABI}. If your -# package installs ABI-specific headers, just add 'prep_ml_includes' to the -# end of your src_install(). It takes a list of directories that include -# files are installed in (default is /usr/include if none are passed). +# @FUNCTION: get_libname +# @USAGE: [version] +# @DESCRIPTION: +# Returns libname with proper suffix {.so,.dylib,.dll,etc} and optionally +# supplied version for the current platform identified by CHOST. # # Example: -# src_install() { -# ... -# prep_ml_includes /usr/qt/3/include -# } - -prep_ml_includes() { - if [[ $(number_abis) -gt 1 ]] ; then - local dir - local dirs - local base - - if [[ $# -eq 0 ]] ; then - dirs=/usr/include - else - dirs="$@" - fi - - for dir in ${dirs} ; do - base=${T}/gentoo-multilib/${dir}/gentoo-multilib - mkdir -p "${base}" - [[ -d ${base}/${ABI} ]] && rm -rf "${base}/${ABI}" - mv "${D}/${dir}" "${base}/${ABI}" - done - - if is_final_abi; then - base=${T}/gentoo-multilib - pushd "${base}" - find . | tar -c -T - -f - | tar -x --no-same-owner -f - -C ${D} - popd - - # This 'set' stuff is required by mips profiles to properly pass - # CDEFINE's (which have spaces) to sub-functions - set -- - for dir in ${dirs} ; do - set -- "$@" "${dir}" - local abi - for abi in $(get_install_abis); do - set -- "$@" "$(get_abi_CDEFINE ${abi}):${dir}/gentoo-multilib/${abi}" - done - create_ml_includes "$@" - done - fi - fi -} - -# If you need more control than prep_ml_includes can offer (like linux-headers -# for the asm-* dirs, then use create_ml_includes. The firs argument is the -# common dir. The remaining args are of the form : where -# is what is put in the #ifdef for choosing that dir. -# -# Ideas for this code came from debian's sparc-linux headers package. -# -# Example: -# create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64 -# create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64 -create_ml_includes() { - local dest=$1 - shift - local basedirs=$(create_ml_includes-listdirs "$@") - - create_ml_includes-makedestdirs ${dest} ${basedirs} - - local file - for file in $(create_ml_includes-allfiles ${basedirs}) ; do - #local name=$(echo ${file} | tr '[:lower:]' '[:upper:]' | sed 's:[^[:upper:]]:_:g') - ( - echo "/* Autogenerated by create_ml_includes() in multilib.eclass */" - - local dir - for dir in ${basedirs}; do - if [[ -f ${D}/${dir}/${file} ]] ; then - echo "" - local sym=$(create_ml_includes-sym_for_dir ${dir} "$@") - if [[ ${sym/=} != "${sym}" ]] ; then - echo "#if ${sym}" - elif [[ ${sym::1} == "!" ]] ; then - echo "#ifndef ${sym:1}" - else - echo "#ifdef ${sym}" - fi - echo "# include <$(create_ml_includes-absolute ${dir}/${file})>" - echo "#endif /* ${sym} */" - fi - done - - #echo "#endif /* __CREATE_ML_INCLUDES_STUB_${name}__ */" - ) > "${D}/${dest}/${file}" - done -} - -# Helper function for create_ml_includes -create_ml_includes-absolute() { - local dst="$(create_ml_includes-tidy_path $1)" - - dst=(${dst//\// }) - - local i - for ((i=0; i<${#dst[*]}; i++)); do - [ "${dst[i]}" == "include" ] && break - done - - local strip_upto=$i - - for ((i=strip_upto+1; i<${#dst[*]}-1; i++)); do - echo -n ${dst[i]}/ - done - - echo -n ${dst[i]} -} - -# Helper function for create_ml_includes -create_ml_includes-tidy_path() { - local removed=$1 - - if [ -n "${removed}" ]; then - # Remove multiple slashes - while [ "${removed}" != "${removed/\/\//\/}" ]; do - removed=${removed/\/\//\/} - done - - # Remove . directories - while [ "${removed}" != "${removed//\/.\//\/}" ]; do - removed=${removed//\/.\//\/} - done - [ "${removed##*/}" = "." ] && removed=${removed%/*} - - # Removed .. directories - while [ "${removed}" != "${removed//\/..\/}" ]; do - local p1="${removed%%\/..\/*}" - local p2="${removed#*\/..\/}" - - removed="${p1%\/*}/${p2}" - done - - # Remove trailing .. - [ "${removed##*/}" = ".." ] && removed=${removed%/*/*} - - # Remove trailing / - [ "${removed##*/}" = "" ] && removed=${removed%/*} - - echo ${removed} - fi -} - -# Helper function for create_ml_includes -create_ml_includes-listdirs() { - local dirs - local data - for data in "$@"; do - dirs="${dirs} ${data/*:/}" - done - echo ${dirs:1} -} - -# Helper function for create_ml_includes -create_ml_includes-makedestdirs() { - local dest=$1 - shift - local basedirs=$@ - - dodir ${dest} - - local basedir - for basedir in ${basedirs}; do - local dir - for dir in $(find ${D}/${basedir} -type d); do - dodir ${dest}/${dir/${D}\/${basedir}/} - done - done -} - -# Helper function for create_ml_includes -create_ml_includes-allfiles() { - local basedir file - for basedir in "$@" ; do - for file in $(find "${D}"/${basedir} -type f); do - echo ${file/${D}\/${basedir}\//} - done - done | sort | uniq -} - -# Helper function for create_ml_includes -create_ml_includes-sym_for_dir() { - local dir=$1 - shift - local data - for data in "$@"; do - if [[ ${data} == *:${dir} ]] ; then - echo ${data/:*/} - return 0 - fi - done - echo "Shouldn't be here -- create_ml_includes-sym_for_dir $1 $@" - # exit because we'll likely be called from a subshell - exit 1 -} - +# get_libname ${PV} +# Returns: .so.${PV} (ELF) || .${PV}.dylib (MACH) || ... get_libname() { local libname local ver=$1 case ${CHOST} in - *-darwin*) libname="dylib";; - *) libname="so";; + *-cygwin|mingw*|*-mingw*) libname="dll";; + *-darwin*) libname="dylib";; + *-mint*) libname="irrelevant";; + hppa*-hpux*) libname="sl";; + *) libname="so";; esac - if [[ -z $@ ]] ; then + if [[ -z $* ]] ; then echo ".${libname}" else for ver in "$@" ; do case ${CHOST} in *-darwin*) echo ".${ver}.${libname}";; + *-mint*) echo ".${libname}";; *) echo ".${libname}.${ver}";; esac done fi } +# @FUNCTION: get_modname +# @USAGE: +# @DESCRIPTION: +# Returns modulename with proper suffix {.so,.bundle,etc} for the current +# platform identified by CHOST. +# +# Example: +# libfoo$(get_modname) +# Returns: libfoo.so (ELF) || libfoo.bundle (MACH) || ... +get_modname() { + local modname + local ver=$1 + case ${CHOST} in + *-darwin*) modname="bundle";; + *) modname="so";; + esac + + echo ".${modname}" +} + # This is for the toolchain to setup profile variables when pulling in # a crosscompiler (and thus they aren't set in the profile) multilib_env() { @@ -561,92 +285,142 @@ x86_64*) export CFLAGS_x86=${CFLAGS_x86--m32} export CHOST_x86=${CTARGET/x86_64/i686} + CHOST_x86=${CHOST_x86/%-gnux32/-gnu} export CTARGET_x86=${CHOST_x86} - export CDEFINE_x86="__i386__" - export LIBDIR_x86="lib" + if [[ ${SYMLINK_LIB} == "yes" ]] ; then + export LIBDIR_x86="lib32" + else + export LIBDIR_x86="lib" + fi export CFLAGS_amd64=${CFLAGS_amd64--m64} - export CHOST_amd64=${CTARGET} - export CTARGET_amd64=${CTARGET_amd64} - export CDEFINE_amd64="__x86_64__" + export CHOST_amd64=${CTARGET/%-gnux32/-gnu} + export CTARGET_amd64=${CHOST_amd64} export LIBDIR_amd64="lib64" - export MULTILIB_ABIS="amd64 x86" - export DEFAULT_ABI="amd64" + export CFLAGS_x32=${CFLAGS_x32--mx32} + export CHOST_x32=${CTARGET/%-gnu/-gnux32} + export CTARGET_x32=${CHOST_x32} + export LIBDIR_x32="libx32" + + case ${CTARGET} in + *-gnux32) + : ${MULTILIB_ABIS=x32 amd64 x86} + : ${DEFAULT_ABI=x32} + ;; + *) + : ${MULTILIB_ABIS=amd64 x86} + : ${DEFAULT_ABI=amd64} + ;; + esac ;; mips64*) export CFLAGS_o32=${CFLAGS_o32--mabi=32} export CHOST_o32=${CTARGET/mips64/mips} export CTARGET_o32=${CHOST_o32} - export CDEFINE_o32="_MIPS_SIM == _ABIO32" export LIBDIR_o32="lib" export CFLAGS_n32=${CFLAGS_n32--mabi=n32} export CHOST_n32=${CTARGET} export CTARGET_n32=${CHOST_n32} - export CDEFINE_n32="_MIPS_SIM == _ABIN32" export LIBDIR_n32="lib32" export CFLAGS_n64=${CFLAGS_n64--mabi=64} export CHOST_n64=${CTARGET} export CTARGET_n64=${CHOST_n64} - export CDEFINE_n64="_MIPS_SIM == _ABI64" export LIBDIR_n64="lib64" - export MULTILIB_ABIS="n64 n32 o32" - export DEFAULT_ABI="n32" + : ${MULTILIB_ABIS=n64 n32 o32} + : ${DEFAULT_ABI=n32} ;; powerpc64*) export CFLAGS_ppc=${CFLAGS_ppc--m32} export CHOST_ppc=${CTARGET/powerpc64/powerpc} export CTARGET_ppc=${CHOST_ppc} - export CDEFINE_ppc="!__powerpc64__" export LIBDIR_ppc="lib" export CFLAGS_ppc64=${CFLAGS_ppc64--m64} export CHOST_ppc64=${CTARGET} export CTARGET_ppc64=${CHOST_ppc64} - export CDEFINE_ppc64="__powerpc64__" export LIBDIR_ppc64="lib64" - export MULTILIB_ABIS="ppc64 ppc" - export DEFAULT_ABI="ppc64" + : ${MULTILIB_ABIS=ppc64 ppc} + : ${DEFAULT_ABI=ppc64} ;; s390x*) export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo export CHOST_s390=${CTARGET/s390x/s390} export CTARGET_s390=${CHOST_s390} - export CDEFINE_s390="!__s390x__" export LIBDIR_s390="lib" export CFLAGS_s390x=${CFLAGS_s390x--m64} export CHOST_s390x=${CTARGET} export CTARGET_s390x=${CHOST_s390x} - export CDEFINE_s390x="__s390x__" export LIBDIR_s390x="lib64" - export MULTILIB_ABIS="s390x s390" - export DEFAULT_ABI="s390x" + : ${MULTILIB_ABIS=s390x s390} + : ${DEFAULT_ABI=s390x} ;; sparc64*) export CFLAGS_sparc32=${CFLAGS_sparc32--m32} export CHOST_sparc32=${CTARGET/sparc64/sparc} export CTARGET_sparc32=${CHOST_sparc32} - export CDEFINE_sparc32="!__arch64__" export LIBDIR_sparc32="lib" export CFLAGS_sparc64=${CFLAGS_sparc64--m64} export CHOST_sparc64=${CTARGET} export CTARGET_sparc64=${CHOST_sparc64} - export CDEFINE_sparc64="__arch64__" export LIBDIR_sparc64="lib64" - export MULTILIB_ABIS="sparc64 sparc32" - export DEFAULT_ABI="sparc64" + : ${MULTILIB_ABIS=sparc64 sparc32} + : ${DEFAULT_ABI=sparc64} ;; *) - export MULTILIB_ABIS="default" - export DEFAULT_ABI="default" + : ${MULTILIB_ABIS=default} + : ${DEFAULT_ABI=default} ;; esac + + export MULTILIB_ABIS DEFAULT_ABI } + +# @FUNCTION: multilib_toolchain_setup +# @DESCRIPTION: +# Hide multilib details here for packages which are forced to be compiled for a +# specific ABI when run on another ABI (like x86-specific packages on amd64) +multilib_toolchain_setup() { + local v vv + + export ABI=$1 + + # First restore any saved state we have laying around. + if [[ ${__DEFAULT_ABI_SAVED} == "true" ]] ; then + for v in CHOST CBUILD AS CC CXX LD ; do + vv="__abi_saved_${v}" + export ${v}="${!vv}" + unset ${vv} + done + unset __DEFAULT_ABI_SAVED + fi + + # We want to avoid the behind-the-back magic of gcc-config as it + # screws up ccache and distcc. See #196243 for more info. + if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then + # Back that multilib-ass up so we can restore it later + for v in CHOST CBUILD AS CC CXX LD ; do + export __abi_saved_${v}="${!v}" + done + export __DEFAULT_ABI_SAVED="true" + + # Set the CHOST native first so that we pick up the native + # toolchain and not a cross-compiler by accident #202811. + export CHOST=$(get_abi_CHOST ${DEFAULT_ABI}) + export CC="$(tc-getCC) $(get_abi_CFLAGS)" + export CXX="$(tc-getCXX) $(get_abi_CFLAGS)" + export LD="$(tc-getLD) $(get_abi_LDFLAGS)" + export CHOST=$(get_abi_CHOST $1) + export CBUILD=$(get_abi_CHOST $1) + fi +} + +fi