1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: multilib.eclass
9 # @BLURB: This eclass is for all functions pertaining to handling multilib configurations.
11 # This eclass is for all functions pertaining to handling multilib configurations.
13 if [[ -z ${_MULTILIB_ECLASS} ]]; then
16 inherit toolchain-funcs
19 export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
20 export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
22 export LDFLAGS_default
23 export CHOST_default=${CHOST_default:-${CHOST}}
24 export CTARGET_default=${CTARGET_default:-${CTARGET:-${CHOST_default}}}
25 export LIBDIR_default=${CONF_LIBDIR:-"lib"}
26 export KERNEL_ABI=${KERNEL_ABI:-${DEFAULT_ABI}}
28 # @FUNCTION: has_multilib_profile
30 # Return true if the current profile is a multilib profile and lists more than
31 # one abi in ${MULTILIB_ABIS}. When has_multilib_profile returns true, that
32 # profile should enable the 'multilib' use flag. This is so you can DEPEND on
33 # a package only for multilib or not multilib.
34 has_multilib_profile() {
35 [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
38 # @FUNCTION: get_libdir
39 # @RETURN: the libdir for the selected ABI
41 # This function simply returns the desired lib directory. With portage
42 # 2.0.51, we now have support for installing libraries to lib32/lib64
43 # to accomidate the needs of multilib systems. It's no longer a good idea
44 # to assume all libraries will end up in lib. Replace any (sane) instances
45 # where lib is named directly with $(get_libdir) if possible.
47 # Jeremy Huddleston <eradicator@gentoo.org> (23 Dec 2004):
48 # Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set,
49 # fall back on old behavior. Any profile that has these set should also
50 # depend on a newer version of portage (not yet released) which uses these
51 # over CONF_LIBDIR in econf, dolib, etc...
52 if has "${EAPI:-0}" 0 1 2 3 4 5; then
55 if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
56 # if there is an override, we want to use that... always.
57 echo ${CONF_LIBDIR_OVERRIDE}
64 # @FUNCTION: get_abi_var
66 # @RETURN: returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
70 # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
72 # Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
73 # This will hopefully be added to portage soon...
75 # If <ABI> is not specified, ${ABI} is used.
76 # If <ABI> is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used.
77 # If <ABI> is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string.
80 local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}}
81 local var="${flag}_${abi}"
85 # @FUNCTION: get_abi_CFLAGS
88 # Alias for 'get_abi_var CFLAGS'
89 get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; }
91 # @FUNCTION: get_abi_LDFLAGS
94 # Alias for 'get_abi_var LDFLAGS'
95 get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; }
97 # @FUNCTION: get_abi_CHOST
100 # Alias for 'get_abi_var CHOST'
101 get_abi_CHOST() { get_abi_var CHOST "$@"; }
103 # @FUNCTION: get_abi_CTARGET
106 # Alias for 'get_abi_var CTARGET'
107 get_abi_CTARGET() { get_abi_var CTARGET "$@"; }
109 # @FUNCTION: get_abi_FAKE_TARGETS
112 # Alias for 'get_abi_var FAKE_TARGETS'
113 get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; }
115 # @FUNCTION: get_abi_LIBDIR
118 # Alias for 'get_abi_var LIBDIR'
119 get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; }
121 # @FUNCTION: get_install_abis
123 # Return a list of the ABIs we want to install for with
124 # the last one in the list being the default.
128 if [[ -z ${MULTILIB_ABIS} ]] ; then
133 if [[ ${EMULTILIB_PKG} == "true" ]] ; then
134 for x in ${MULTILIB_ABIS} ; do
135 if [[ ${x} != "${DEFAULT_ABI}" ]] ; then
136 has ${x} ${ABI_DENY} || order="${order} ${x}"
139 has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}"
141 if [[ -n ${ABI_ALLOW} ]] ; then
143 for x in ${order} ; do
144 if has ${x} ${ABI_ALLOW} ; then
145 ordera="${ordera} ${x}"
154 if [[ -z ${order} ]] ; then
155 die "The ABI list is empty. Are you using a proper multilib profile? Perhaps your USE flags or MULTILIB_ABIS are too restrictive for this package."
162 # @FUNCTION: get_all_abis
164 # Return a list of the ABIs supported by this profile.
165 # the last one in the list being the default.
167 local x order="" mvar dvar
171 if [[ -n $1 ]] ; then
176 if [[ -z ${!mvar} ]] ; then
181 for x in ${!mvar}; do
182 if [[ ${x} != ${!dvar} ]] ; then
183 order="${order:+${order} }${x}"
186 order="${order:+${order} }${!dvar}"
192 # @FUNCTION: get_all_libdirs
194 # Returns a list of all the libdirs used by this profile. This includes
195 # those that might not be touched by the current ebuild and always includes
200 for abi in ${MULTILIB_ABIS}; do
201 libdirs+=" $(get_abi_LIBDIR ${abi})"
203 [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib"
208 # @FUNCTION: is_final_abi
210 # Return true if ${ABI} is the last ABI on our list (or if we're not
211 # using the new multilib configuration. This can be used to determine
212 # if we're in the last (or only) run through src_{unpack,compile,install}
214 has_multilib_profile || return 0
215 set -- $(get_install_abis)
217 [[ ${!LAST_ABI} == ${ABI} ]]
220 # @FUNCTION: number_abis
222 # echo the number of ABIs we will be installing for
224 set -- `get_install_abis`
228 # @FUNCTION: get_libname
231 # Returns libname with proper suffix {.so,.dylib,.dll,etc} and optionally
232 # supplied version for the current platform identified by CHOST.
236 # Returns: .so.${PV} (ELF) || .${PV}.dylib (MACH) || ...
241 *-cygwin*) libname="dll.a";; # import lib
242 mingw*|*-mingw*) libname="dll";;
243 *-darwin*) libname="dylib";;
244 *-mint*) libname="irrelevant";;
245 hppa*-hpux*) libname="sl";;
249 if [[ -z $* ]] ; then
254 *-cygwin*) echo ".${ver}.${libname}";;
255 *-darwin*) echo ".${ver}.${libname}";;
256 *-mint*) echo ".${libname}";;
257 *) echo ".${libname}.${ver}";;
263 # @FUNCTION: get_modname
266 # Returns modulename with proper suffix {.so,.bundle,etc} for the current
267 # platform identified by CHOST.
270 # libfoo$(get_modname)
271 # Returns: libfoo.so (ELF) || libfoo.bundle (MACH) || ...
276 *-darwin*) modname="bundle";;
283 # This is for the toolchain to setup profile variables when pulling in
284 # a crosscompiler (and thus they aren't set in the profile)
286 local CTARGET=${1:-${CTARGET}}
287 local cpu=${CTARGET%%*-}
291 # Not possible to do multilib with aarch64 and a single toolchain.
292 export CFLAGS_arm=${CFLAGS_arm-}
294 aarch64*be) export CHOST_arm="armv8b-${CTARGET#*-}";;
295 *) export CHOST_arm="armv8l-${CTARGET#*-}";;
297 CHOST_arm=${CHOST_arm/%-gnu/-gnueabi}
298 export CTARGET_arm=${CHOST_arm}
299 export LIBDIR_arm="lib"
301 export CFLAGS_arm64=${CFLAGS_arm64-}
302 export CHOST_arm64=${CTARGET}
303 export CTARGET_arm64=${CHOST_arm64}
304 export LIBDIR_arm64="lib64"
306 : ${MULTILIB_ABIS=arm64}
307 : ${DEFAULT_ABI=arm64}
310 export CFLAGS_x86=${CFLAGS_x86--m32}
311 export CHOST_x86=${CTARGET/x86_64/i686}
312 CHOST_x86=${CHOST_x86/%-gnux32/-gnu}
313 export CTARGET_x86=${CHOST_x86}
314 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
315 export LIBDIR_x86="lib32"
317 export LIBDIR_x86="lib"
320 export CFLAGS_amd64=${CFLAGS_amd64--m64}
321 export CHOST_amd64=${CTARGET/%-gnux32/-gnu}
322 export CTARGET_amd64=${CHOST_amd64}
323 export LIBDIR_amd64="lib64"
325 export CFLAGS_x32=${CFLAGS_x32--mx32}
326 export CHOST_x32=${CTARGET/%-gnu/-gnux32}
327 export CTARGET_x32=${CHOST_x32}
328 export LIBDIR_x32="libx32"
332 : ${MULTILIB_ABIS=x32 amd64 x86}
336 : ${MULTILIB_ABIS=amd64 x86}
337 : ${DEFAULT_ABI=amd64}
342 export CFLAGS_o32=${CFLAGS_o32--mabi=32}
343 export CHOST_o32=${CTARGET/mips64/mips}
344 export CTARGET_o32=${CHOST_o32}
345 export LIBDIR_o32="lib"
347 export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
348 export CHOST_n32=${CTARGET}
349 export CTARGET_n32=${CHOST_n32}
350 export LIBDIR_n32="lib32"
352 export CFLAGS_n64=${CFLAGS_n64--mabi=64}
353 export CHOST_n64=${CTARGET}
354 export CTARGET_n64=${CHOST_n64}
355 export LIBDIR_n64="lib64"
357 : ${MULTILIB_ABIS=n64 n32 o32}
361 export CFLAGS_ppc=${CFLAGS_ppc--m32}
362 export CHOST_ppc=${CTARGET/powerpc64/powerpc}
363 export CTARGET_ppc=${CHOST_ppc}
364 export LIBDIR_ppc="lib"
366 export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
367 export CHOST_ppc64=${CTARGET}
368 export CTARGET_ppc64=${CHOST_ppc64}
369 export LIBDIR_ppc64="lib64"
371 : ${MULTILIB_ABIS=ppc64 ppc}
372 : ${DEFAULT_ABI=ppc64}
375 export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo
376 export CHOST_s390=${CTARGET/s390x/s390}
377 export CTARGET_s390=${CHOST_s390}
378 export LIBDIR_s390="lib"
380 export CFLAGS_s390x=${CFLAGS_s390x--m64}
381 export CHOST_s390x=${CTARGET}
382 export CTARGET_s390x=${CHOST_s390x}
383 export LIBDIR_s390x="lib64"
385 : ${MULTILIB_ABIS=s390x s390}
386 : ${DEFAULT_ABI=s390x}
389 export CFLAGS_sparc32=${CFLAGS_sparc32--m32}
390 export CHOST_sparc32=${CTARGET/sparc64/sparc}
391 export CTARGET_sparc32=${CHOST_sparc32}
392 export LIBDIR_sparc32="lib"
394 export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
395 export CHOST_sparc64=${CTARGET}
396 export CTARGET_sparc64=${CHOST_sparc64}
397 export LIBDIR_sparc64="lib64"
399 : ${MULTILIB_ABIS=sparc64 sparc32}
400 : ${DEFAULT_ABI=sparc64}
403 : ${MULTILIB_ABIS=default}
404 : ${DEFAULT_ABI=default}
408 export MULTILIB_ABIS DEFAULT_ABI
411 # @FUNCTION: multilib_toolchain_setup
413 # Hide multilib details here for packages which are forced to be compiled for a
414 # specific ABI when run on another ABI (like x86-specific packages on amd64)
415 multilib_toolchain_setup() {
420 # First restore any saved state we have laying around.
421 if [[ ${_DEFAULT_ABI_SAVED} == "true" ]] ; then
422 for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
424 [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v}
427 unset _DEFAULT_ABI_SAVED
430 # We want to avoid the behind-the-back magic of gcc-config as it
431 # screws up ccache and distcc. See #196243 for more info.
432 if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then
433 # Back that multilib-ass up so we can restore it later
434 for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
436 [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv}
438 export _DEFAULT_ABI_SAVED="true"
440 # Set the CHOST native first so that we pick up the native
441 # toolchain and not a cross-compiler by accident #202811.
442 export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
443 export CC="$(tc-getCC) $(get_abi_CFLAGS)"
444 export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
445 export F77="$(tc-getF77) $(get_abi_CFLAGS)"
446 export FC="$(tc-getFC) $(get_abi_CFLAGS)"
447 export LD="$(tc-getLD) $(get_abi_LDFLAGS)"
448 export CHOST=$(get_abi_CHOST $1)
449 export CBUILD=$(get_abi_CHOST $1)
450 export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig
451 export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig