x11-misc/alock: Take ownership of package
[gentoo.git] / eclass / multilib.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: multilib.eclass
6 # @MAINTAINER:
7 # amd64@gentoo.org
8 # toolchain@gentoo.org
9 # @BLURB: This eclass is for all functions pertaining to handling multilib configurations.
10 # @DESCRIPTION:
11 # This eclass is for all functions pertaining to handling multilib configurations.
12
13 if [[ -z ${_MULTILIB_ECLASS} ]]; then
14 _MULTILIB_ECLASS=1
15
16 inherit toolchain-funcs
17
18 # Defaults:
19 export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
20 export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
21 export CFLAGS_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}}
27
28 # @FUNCTION: has_multilib_profile
29 # @DESCRIPTION:
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/ /}" ]
36 }
37
38 # @FUNCTION: get_libdir
39 # @RETURN: the libdir for the selected ABI
40 # @DESCRIPTION:
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.
46 #
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
53         get_libdir() {
54                 local CONF_LIBDIR
55                 if [ -n  "${CONF_LIBDIR_OVERRIDE}" ] ; then
56                         # if there is an override, we want to use that... always.
57                         echo ${CONF_LIBDIR_OVERRIDE}
58                 else
59                         get_abi_LIBDIR
60                 fi
61         }
62 fi
63
64 # @FUNCTION: get_abi_var
65 # @USAGE: <VAR> [ABI]
66 # @RETURN: returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
67 # @INTERNAL
68 # @DESCRIPTION:
69 # ex:
70 # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
71 #
72 # Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
73 # This will hopefully be added to portage soon...
74 #
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.
78 get_abi_var() {
79         local flag=$1
80         local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}}
81         local var="${flag}_${abi}"
82         echo ${!var}
83 }
84
85 # @FUNCTION: get_abi_CFLAGS
86 # @USAGE: [ABI]
87 # @DESCRIPTION:
88 # Alias for 'get_abi_var CFLAGS'
89 get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; }
90
91 # @FUNCTION: get_abi_LDFLAGS
92 # @USAGE: [ABI]
93 # @DESCRIPTION:
94 # Alias for 'get_abi_var LDFLAGS'
95 get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; }
96
97 # @FUNCTION: get_abi_CHOST
98 # @USAGE: [ABI]
99 # @DESCRIPTION:
100 # Alias for 'get_abi_var CHOST'
101 get_abi_CHOST() { get_abi_var CHOST "$@"; }
102
103 # @FUNCTION: get_abi_CTARGET
104 # @USAGE: [ABI]
105 # @DESCRIPTION:
106 # Alias for 'get_abi_var CTARGET'
107 get_abi_CTARGET() { get_abi_var CTARGET "$@"; }
108
109 # @FUNCTION: get_abi_FAKE_TARGETS
110 # @USAGE: [ABI]
111 # @DESCRIPTION:
112 # Alias for 'get_abi_var FAKE_TARGETS'
113 get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; }
114
115 # @FUNCTION: get_abi_LIBDIR
116 # @USAGE: [ABI]
117 # @DESCRIPTION:
118 # Alias for 'get_abi_var LIBDIR'
119 get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; }
120
121 # @FUNCTION: get_install_abis
122 # @DESCRIPTION:
123 # Return a list of the ABIs we want to install for with
124 # the last one in the list being the default.
125 get_install_abis() {
126         local x order=""
127
128         if [[ -z ${MULTILIB_ABIS} ]] ; then
129                 echo "default"
130                 return 0
131         fi
132
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}"
137                         fi
138                 done
139                 has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}"
140
141                 if [[ -n ${ABI_ALLOW} ]] ; then
142                         local ordera=""
143                         for x in ${order} ; do
144                                 if has ${x} ${ABI_ALLOW} ; then
145                                         ordera="${ordera} ${x}"
146                                 fi
147                         done
148                         order=${ordera}
149                 fi
150         else
151                 order=${DEFAULT_ABI}
152         fi
153
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."
156         fi
157
158         echo ${order}
159         return 0
160 }
161
162 # @FUNCTION: get_all_abis
163 # @DESCRIPTION:
164 # Return a list of the ABIs supported by this profile.
165 # the last one in the list being the default.
166 get_all_abis() {
167         local x order="" mvar dvar
168
169         mvar="MULTILIB_ABIS"
170         dvar="DEFAULT_ABI"
171         if [[ -n $1 ]] ; then
172                 mvar="$1_${mvar}"
173                 dvar="$1_${dvar}"
174         fi
175
176         if [[ -z ${!mvar} ]] ; then
177                 echo "default"
178                 return 0
179         fi
180
181         for x in ${!mvar}; do
182                 if [[ ${x} != ${!dvar} ]] ; then
183                         order="${order:+${order} }${x}"
184                 fi
185         done
186         order="${order:+${order} }${!dvar}"
187
188         echo ${order}
189         return 0
190 }
191
192 # @FUNCTION: get_all_libdirs
193 # @DESCRIPTION:
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
196 # "lib".
197 get_all_libdirs() {
198         local libdirs abi
199
200         for abi in ${MULTILIB_ABIS}; do
201                 libdirs+=" $(get_abi_LIBDIR ${abi})"
202         done
203         [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib"
204
205         echo "${libdirs}"
206 }
207
208 # @FUNCTION: is_final_abi
209 # @DESCRIPTION:
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}
213 is_final_abi() {
214         has_multilib_profile || return 0
215         set -- $(get_install_abis)
216         local LAST_ABI=$#
217         [[ ${!LAST_ABI} == ${ABI} ]]
218 }
219
220 # @FUNCTION: number_abis
221 # @DESCRIPTION:
222 # echo the number of ABIs we will be installing for
223 number_abis() {
224         set -- `get_install_abis`
225         echo $#
226 }
227
228 # @FUNCTION: get_libname
229 # @USAGE: [version]
230 # @DESCRIPTION:
231 # Returns libname with proper suffix {.so,.dylib,.dll,etc} and optionally
232 # supplied version for the current platform identified by CHOST.
233 #
234 # Example:
235 #     get_libname ${PV}
236 #     Returns: .so.${PV} (ELF) || .${PV}.dylib (MACH) || ...
237 get_libname() {
238         local libname
239         local ver=$1
240         case ${CHOST} in
241                 *-cygwin|mingw*|*-mingw*) libname="dll";;
242                 *-darwin*)                libname="dylib";;
243                 *-mint*)                  libname="irrelevant";;
244                 hppa*-hpux*)              libname="sl";;
245                 *)                        libname="so";;
246         esac
247
248         if [[ -z $* ]] ; then
249                 echo ".${libname}"
250         else
251                 for ver in "$@" ; do
252                         case ${CHOST} in
253                                 *-darwin*) echo ".${ver}.${libname}";;
254                                 *-mint*)   echo ".${libname}";;
255                                 *)         echo ".${libname}.${ver}";;
256                         esac
257                 done
258         fi
259 }
260
261 # @FUNCTION: get_modname
262 # @USAGE:
263 # @DESCRIPTION:
264 # Returns modulename with proper suffix {.so,.bundle,etc} for the current
265 # platform identified by CHOST.
266 #
267 # Example:
268 #     libfoo$(get_modname)
269 #     Returns: libfoo.so (ELF) || libfoo.bundle (MACH) || ...
270 get_modname() {
271         local modname
272         local ver=$1
273         case ${CHOST} in
274                 *-darwin*)                modname="bundle";;
275                 *)                        modname="so";;
276         esac
277
278         echo ".${modname}"
279 }
280
281 # This is for the toolchain to setup profile variables when pulling in
282 # a crosscompiler (and thus they aren't set in the profile)
283 multilib_env() {
284         local CTARGET=${1:-${CTARGET}}
285         local cpu=${CTARGET%%*-}
286
287         case ${cpu} in
288                 aarch64*)
289                         # Not possible to do multilib with aarch64 and a single toolchain.
290                         export CFLAGS_arm=${CFLAGS_arm-}
291                         case ${cpu} in
292                         aarch64*be) export CHOST_arm="armv8b-${CTARGET#*-}";;
293                         *)          export CHOST_arm="armv8l-${CTARGET#*-}";;
294                         esac
295                         CHOST_arm=${CHOST_arm/%-gnu/-gnueabi}
296                         export CTARGET_arm=${CHOST_arm}
297                         export LIBDIR_arm="lib"
298
299                         export CFLAGS_arm64=${CFLAGS_arm64-}
300                         export CHOST_arm64=${CTARGET}
301                         export CTARGET_arm64=${CHOST_arm64}
302                         export LIBDIR_arm64="lib64"
303
304                         : ${MULTILIB_ABIS=arm64}
305                         : ${DEFAULT_ABI=arm64}
306                 ;;
307                 x86_64*)
308                         export CFLAGS_x86=${CFLAGS_x86--m32}
309                         export CHOST_x86=${CTARGET/x86_64/i686}
310                         CHOST_x86=${CHOST_x86/%-gnux32/-gnu}
311                         export CTARGET_x86=${CHOST_x86}
312                         if [[ ${SYMLINK_LIB} == "yes" ]] ; then
313                                 export LIBDIR_x86="lib32"
314                         else
315                                 export LIBDIR_x86="lib"
316                         fi
317
318                         export CFLAGS_amd64=${CFLAGS_amd64--m64}
319                         export CHOST_amd64=${CTARGET/%-gnux32/-gnu}
320                         export CTARGET_amd64=${CHOST_amd64}
321                         export LIBDIR_amd64="lib64"
322
323                         export CFLAGS_x32=${CFLAGS_x32--mx32}
324                         export CHOST_x32=${CTARGET/%-gnu/-gnux32}
325                         export CTARGET_x32=${CHOST_x32}
326                         export LIBDIR_x32="libx32"
327
328                         case ${CTARGET} in
329                         *-gnux32)
330                                 : ${MULTILIB_ABIS=x32 amd64 x86}
331                                 : ${DEFAULT_ABI=x32}
332                                 ;;
333                         *)
334                                 : ${MULTILIB_ABIS=amd64 x86}
335                                 : ${DEFAULT_ABI=amd64}
336                                 ;;
337                         esac
338                 ;;
339                 mips64*)
340                         export CFLAGS_o32=${CFLAGS_o32--mabi=32}
341                         export CHOST_o32=${CTARGET/mips64/mips}
342                         export CTARGET_o32=${CHOST_o32}
343                         export LIBDIR_o32="lib"
344
345                         export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
346                         export CHOST_n32=${CTARGET}
347                         export CTARGET_n32=${CHOST_n32}
348                         export LIBDIR_n32="lib32"
349
350                         export CFLAGS_n64=${CFLAGS_n64--mabi=64}
351                         export CHOST_n64=${CTARGET}
352                         export CTARGET_n64=${CHOST_n64}
353                         export LIBDIR_n64="lib64"
354
355                         : ${MULTILIB_ABIS=n64 n32 o32}
356                         : ${DEFAULT_ABI=n32}
357                 ;;
358                 powerpc64*)
359                         export CFLAGS_ppc=${CFLAGS_ppc--m32}
360                         export CHOST_ppc=${CTARGET/powerpc64/powerpc}
361                         export CTARGET_ppc=${CHOST_ppc}
362                         export LIBDIR_ppc="lib"
363
364                         export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
365                         export CHOST_ppc64=${CTARGET}
366                         export CTARGET_ppc64=${CHOST_ppc64}
367                         export LIBDIR_ppc64="lib64"
368
369                         : ${MULTILIB_ABIS=ppc64 ppc}
370                         : ${DEFAULT_ABI=ppc64}
371                 ;;
372                 s390x*)
373                         export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo
374                         export CHOST_s390=${CTARGET/s390x/s390}
375                         export CTARGET_s390=${CHOST_s390}
376                         export LIBDIR_s390="lib"
377
378                         export CFLAGS_s390x=${CFLAGS_s390x--m64}
379                         export CHOST_s390x=${CTARGET}
380                         export CTARGET_s390x=${CHOST_s390x}
381                         export LIBDIR_s390x="lib64"
382
383                         : ${MULTILIB_ABIS=s390x s390}
384                         : ${DEFAULT_ABI=s390x}
385                 ;;
386                 sparc64*)
387                         export CFLAGS_sparc32=${CFLAGS_sparc32--m32}
388                         export CHOST_sparc32=${CTARGET/sparc64/sparc}
389                         export CTARGET_sparc32=${CHOST_sparc32}
390                         export LIBDIR_sparc32="lib"
391
392                         export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
393                         export CHOST_sparc64=${CTARGET}
394                         export CTARGET_sparc64=${CHOST_sparc64}
395                         export LIBDIR_sparc64="lib64"
396
397                         : ${MULTILIB_ABIS=sparc64 sparc32}
398                         : ${DEFAULT_ABI=sparc64}
399                 ;;
400                 *)
401                         : ${MULTILIB_ABIS=default}
402                         : ${DEFAULT_ABI=default}
403                 ;;
404         esac
405
406         export MULTILIB_ABIS DEFAULT_ABI
407 }
408
409 # @FUNCTION: multilib_toolchain_setup
410 # @DESCRIPTION:
411 # Hide multilib details here for packages which are forced to be compiled for a
412 # specific ABI when run on another ABI (like x86-specific packages on amd64)
413 multilib_toolchain_setup() {
414         local v vv
415
416         export ABI=$1
417
418         # First restore any saved state we have laying around.
419         if [[ ${_DEFAULT_ABI_SAVED} == "true" ]] ; then
420                 for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
421                         vv="_abi_saved_${v}"
422                         [[ ${!vv+set} == "set" ]] && export ${v}="${!vv}" || unset ${v}
423                         unset ${vv}
424                 done
425                 unset _DEFAULT_ABI_SAVED
426         fi
427
428         # We want to avoid the behind-the-back magic of gcc-config as it
429         # screws up ccache and distcc.  See #196243 for more info.
430         if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then
431                 # Back that multilib-ass up so we can restore it later
432                 for v in CHOST CBUILD AS CC CXX F77 FC LD PKG_CONFIG_{LIBDIR,PATH} ; do
433                         vv="_abi_saved_${v}"
434                         [[ ${!v+set} == "set" ]] && export ${vv}="${!v}" || unset ${vv}
435                 done
436                 export _DEFAULT_ABI_SAVED="true"
437
438                 # Set the CHOST native first so that we pick up the native
439                 # toolchain and not a cross-compiler by accident #202811.
440                 export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
441                 export CC="$(tc-getCC) $(get_abi_CFLAGS)"
442                 export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
443                 export F77="$(tc-getF77) $(get_abi_CFLAGS)"
444                 export FC="$(tc-getFC) $(get_abi_CFLAGS)"
445                 export LD="$(tc-getLD) $(get_abi_LDFLAGS)"
446                 export CHOST=$(get_abi_CHOST $1)
447                 export CBUILD=$(get_abi_CHOST $1)
448                 export PKG_CONFIG_LIBDIR=${EPREFIX}/usr/$(get_libdir)/pkgconfig
449                 export PKG_CONFIG_PATH=${EPREFIX}/usr/share/pkgconfig
450         fi
451 }
452
453 fi