/[gentoo-x86]/eclass/multilib.eclass
Gentoo

Contents of /eclass/multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.94 - (show annotations) (download)
Mon Oct 17 19:14:14 2011 UTC (2 years, 10 months ago) by vapier
Branch: MAIN
Changes since 1.93: +2 -12 lines
simplify get_abi_var logic a bit

1 # Copyright 1999-2011 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/multilib.eclass,v 1.93 2011/10/14 22:54:35 vapier Exp $
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 ___ECLASS_RECUR_MULTILIB="yes"
14 [[ -z ${___ECLASS_RECUR_TOOLCHAIN_FUNCS} ]] && inherit toolchain-funcs
15
16 # Defaults:
17 export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
18 export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
19 export CFLAGS_default
20 export LDFLAGS_default
21 export CHOST_default=${CHOST_default:-${CHOST}}
22 export CTARGET_default=${CTARGET_default:-${CTARGET:-${CHOST_default}}}
23 export LIBDIR_default=${CONF_LIBDIR:-"lib"}
24 export KERNEL_ABI=${KERNEL_ABI:-${DEFAULT_ABI}}
25
26 # @FUNCTION: has_multilib_profile
27 # @DESCRIPTION:
28 # Return true if the current profile is a multilib profile and lists more than
29 # one abi in ${MULTILIB_ABIS}. When has_multilib_profile returns true, that
30 # profile should enable the 'multilib' use flag. This is so you can DEPEND on
31 # a package only for multilib or not multilib.
32 has_multilib_profile() {
33 [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
34 }
35
36 # @FUNCTION: get_libdir
37 # @RETURN: the libdir for the selected ABI
38 # @DESCRIPTION:
39 # This function simply returns the desired lib directory. With portage
40 # 2.0.51, we now have support for installing libraries to lib32/lib64
41 # to accomidate the needs of multilib systems. It's no longer a good idea
42 # to assume all libraries will end up in lib. Replace any (sane) instances
43 # where lib is named directly with $(get_libdir) if possible.
44 #
45 # Jeremy Huddleston <eradicator@gentoo.org> (23 Dec 2004):
46 # Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set,
47 # fall back on old behavior. Any profile that has these set should also
48 # depend on a newer version of portage (not yet released) which uses these
49 # over CONF_LIBDIR in econf, dolib, etc...
50 get_libdir() {
51 local CONF_LIBDIR
52 if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
53 # if there is an override, we want to use that... always.
54 echo ${CONF_LIBDIR_OVERRIDE}
55 else
56 get_abi_LIBDIR
57 fi
58 }
59
60 # @FUNCTION: get_abi_var
61 # @USAGE: <VAR> [ABI]
62 # @RETURN: returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
63 # @INTERNAL
64 # @DESCRIPTION:
65 # ex:
66 # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
67 #
68 # Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
69 # This will hopefully be added to portage soon...
70 #
71 # If <ABI> is not specified, ${ABI} is used.
72 # If <ABI> is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used.
73 # If <ABI> is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string.
74 get_abi_var() {
75 local flag=$1
76 local abi=${2:-${ABI:-${DEFAULT_ABI:-default}}}
77 local var="${flag}_${abi}"
78 echo ${!var}
79 }
80
81 # @FUNCTION: get_abi_CFLAGS
82 # @USAGE: [ABI]
83 # @DESCRIPTION:
84 # Alias for 'get_abi_var CFLAGS'
85 get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; }
86
87 # @FUNCTION: get_abi_LDFLAGS
88 # @USAGE: [ABI]
89 # @DESCRIPTION:
90 # Alias for 'get_abi_var LDFLAGS'
91 get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; }
92
93 # @FUNCTION: get_abi_CHOST
94 # @USAGE: [ABI]
95 # @DESCRIPTION:
96 # Alias for 'get_abi_var CHOST'
97 get_abi_CHOST() { get_abi_var CHOST "$@"; }
98
99 # @FUNCTION: get_abi_CTARGET
100 # @USAGE: [ABI]
101 # @DESCRIPTION:
102 # Alias for 'get_abi_var CTARGET'
103 get_abi_CTARGET() { get_abi_var CTARGET "$@"; }
104
105 # @FUNCTION: get_abi_FAKE_TARGETS
106 # @USAGE: [ABI]
107 # @DESCRIPTION:
108 # Alias for 'get_abi_var FAKE_TARGETS'
109 get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; }
110
111 # @FUNCTION: get_abi_LIBDIR
112 # @USAGE: [ABI]
113 # @DESCRIPTION:
114 # Alias for 'get_abi_var LIBDIR'
115 get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; }
116
117 # @FUNCTION: get_install_abis
118 # @DESCRIPTION:
119 # Return a list of the ABIs we want to install for with
120 # the last one in the list being the default.
121 get_install_abis() {
122 local order=""
123
124 if [[ -z ${MULTILIB_ABIS} ]] ; then
125 echo "default"
126 return 0
127 fi
128
129 if [[ ${EMULTILIB_PKG} == "true" ]] ; then
130 for x in ${MULTILIB_ABIS} ; do
131 if [[ ${x} != "${DEFAULT_ABI}" ]] ; then
132 has ${x} ${ABI_DENY} || order="${order} ${x}"
133 fi
134 done
135 has ${DEFAULT_ABI} ${ABI_DENY} || order="${order} ${DEFAULT_ABI}"
136
137 if [[ -n ${ABI_ALLOW} ]] ; then
138 local ordera=""
139 for x in ${order} ; do
140 if has ${x} ${ABI_ALLOW} ; then
141 ordera="${ordera} ${x}"
142 fi
143 done
144 order=${ordera}
145 fi
146 else
147 order=${DEFAULT_ABI}
148 fi
149
150 if [[ -z ${order} ]] ; then
151 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."
152 fi
153
154 echo ${order}
155 return 0
156 }
157
158 # @FUNCTION: get_all_abis
159 # @DESCRIPTION:
160 # Return a list of the ABIs supported by this profile.
161 # the last one in the list being the default.
162 get_all_abis() {
163 local order=""
164
165 if [[ -z ${MULTILIB_ABIS} ]] ; then
166 echo "default"
167 return 0
168 fi
169
170 for x in ${MULTILIB_ABIS}; do
171 if [[ ${x} != ${DEFAULT_ABI} ]] ; then
172 order="${order:+${order} }${x}"
173 fi
174 done
175 order="${order:+${order} }${DEFAULT_ABI}"
176
177 echo ${order}
178 return 0
179 }
180
181 # @FUNCTION: get_all_libdirs
182 # @DESCRIPTION:
183 # Returns a list of all the libdirs used by this profile. This includes
184 # those that might not be touched by the current ebuild and always includes
185 # "lib".
186 get_all_libdirs() {
187 local libdirs
188 local abi
189 local dir
190
191 for abi in ${MULTILIB_ABIS}; do
192 libdirs+=" $(get_abi_LIBDIR ${abi})"
193 done
194 [[ " ${libdirs} " != *" lib "* ]] && libdirs+=" lib"
195
196 echo "${libdirs}"
197 }
198
199 # @FUNCTION: is_final_abi
200 # @DESCRIPTION:
201 # Return true if ${ABI} is the last ABI on our list (or if we're not
202 # using the new multilib configuration. This can be used to determine
203 # if we're in the last (or only) run through src_{unpack,compile,install}
204 is_final_abi() {
205 has_multilib_profile || return 0
206 set -- $(get_install_abis)
207 local LAST_ABI=$#
208 [[ ${!LAST_ABI} == ${ABI} ]]
209 }
210
211 # @FUNCTION: number_abis
212 # @DESCRIPTION:
213 # echo the number of ABIs we will be installing for
214 number_abis() {
215 set -- `get_install_abis`
216 echo $#
217 }
218
219 # @FUNCTION: get_libname
220 # @USAGE: [version]
221 # @DESCRIPTION:
222 # Returns libname with proper suffix {.so,.dylib,.dll,etc} and optionally
223 # supplied version for the current platform identified by CHOST.
224 #
225 # Example:
226 # get_libname ${PV}
227 # Returns: .so.${PV} (ELF) || .${PV}.dylib (MACH) || ...
228 get_libname() {
229 local libname
230 local ver=$1
231 case ${CHOST} in
232 *-cygwin|mingw*|*-mingw*) libname="dll";;
233 *-darwin*) libname="dylib";;
234 *-mint*) libname="irrelevant";;
235 hppa*-hpux*) libname="sl";;
236 *) libname="so";;
237 esac
238
239 if [[ -z $* ]] ; then
240 echo ".${libname}"
241 else
242 for ver in "$@" ; do
243 case ${CHOST} in
244 *-darwin*) echo ".${ver}.${libname}";;
245 *-mint*) echo ".${libname}";;
246 *) echo ".${libname}.${ver}";;
247 esac
248 done
249 fi
250 }
251
252 # @FUNCTION: get_modname
253 # @USAGE:
254 # @DESCRIPTION:
255 # Returns modulename with proper suffix {.so,.bundle,etc} for the current
256 # platform identified by CHOST.
257 #
258 # Example:
259 # libfoo$(get_modname)
260 # Returns: libfoo.so (ELF) || libfoo.bundle (MACH) || ...
261 get_modname() {
262 local modname
263 local ver=$1
264 case ${CHOST} in
265 *-darwin*) modname="bundle";;
266 *) modname="so";;
267 esac
268
269 echo ".${modname}"
270 }
271
272 # This is for the toolchain to setup profile variables when pulling in
273 # a crosscompiler (and thus they aren't set in the profile)
274 multilib_env() {
275 local CTARGET=${1:-${CTARGET}}
276
277 case ${CTARGET} in
278 x86_64*)
279 export CFLAGS_x86=${CFLAGS_x86--m32}
280 export CHOST_x86=${CTARGET/x86_64/i686}
281 export CTARGET_x86=${CHOST_x86}
282 if [[ ${SYMLINK_LIB} == "yes" ]] ; then
283 export LIBDIR_x86="lib32"
284 else
285 export LIBDIR_x86="lib"
286 fi
287
288 export CFLAGS_amd64=${CFLAGS_amd64--m64}
289 export CHOST_amd64=${CTARGET}
290 export CTARGET_amd64=${CHOST_amd64}
291 export LIBDIR_amd64="lib64"
292
293 export CFLAGS_x32=${CFLAGS_x32--mx32}
294 export CHOST_x32=${CTARGET}
295 export CTARGET_x32=${CHOST_x32}
296 export LIBDIR_x32="libx32"
297
298 : ${MULTILIB_ABIS=amd64 x86}
299 : ${DEFAULT_ABI=amd64}
300 ;;
301 mips64*)
302 export CFLAGS_o32=${CFLAGS_o32--mabi=32}
303 export CHOST_o32=${CTARGET/mips64/mips}
304 export CTARGET_o32=${CHOST_o32}
305 export LIBDIR_o32="lib"
306
307 export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
308 export CHOST_n32=${CTARGET}
309 export CTARGET_n32=${CHOST_n32}
310 export LIBDIR_n32="lib32"
311
312 export CFLAGS_n64=${CFLAGS_n64--mabi=64}
313 export CHOST_n64=${CTARGET}
314 export CTARGET_n64=${CHOST_n64}
315 export LIBDIR_n64="lib64"
316
317 : ${MULTILIB_ABIS=n64 n32 o32}
318 : ${DEFAULT_ABI=n32}
319 ;;
320 powerpc64*)
321 export CFLAGS_ppc=${CFLAGS_ppc--m32}
322 export CHOST_ppc=${CTARGET/powerpc64/powerpc}
323 export CTARGET_ppc=${CHOST_ppc}
324 export LIBDIR_ppc="lib"
325
326 export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
327 export CHOST_ppc64=${CTARGET}
328 export CTARGET_ppc64=${CHOST_ppc64}
329 export LIBDIR_ppc64="lib64"
330
331 : ${MULTILIB_ABIS=ppc64 ppc}
332 : ${DEFAULT_ABI=ppc64}
333 ;;
334 s390x*)
335 export CFLAGS_s390=${CFLAGS_s390--m31} # the 31 is not a typo
336 export CHOST_s390=${CTARGET/s390x/s390}
337 export CTARGET_s390=${CHOST_s390}
338 export LIBDIR_s390="lib"
339
340 export CFLAGS_s390x=${CFLAGS_s390x--m64}
341 export CHOST_s390x=${CTARGET}
342 export CTARGET_s390x=${CHOST_s390x}
343 export LIBDIR_s390x="lib64"
344
345 : ${MULTILIB_ABIS=s390x s390}
346 : ${DEFAULT_ABI=s390x}
347 ;;
348 sparc*)
349 export CFLAGS_sparc32=${CFLAGS_sparc32}
350 export CHOST_sparc32=${CTARGET/sparc64/sparc}
351 export CTARGET_sparc32=${CHOST_sparc32}
352 export LIBDIR_sparc32="lib"
353
354 export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
355 export CHOST_sparc64=${CTARGET}
356 export CTARGET_sparc64=${CHOST_sparc64}
357 export LIBDIR_sparc64="lib64"
358
359 : ${MULTILIB_ABIS=sparc64 sparc32}
360 : ${DEFAULT_ABI=sparc64}
361 ;;
362 *)
363 : ${MULTILIB_ABIS=default}
364 : ${DEFAULT_ABI=default}
365 ;;
366 esac
367
368 export MULTILIB_ABIS DEFAULT_ABI
369 }
370
371 # @FUNCTION: multilib_toolchain_setup
372 # @DESCRIPTION:
373 # Hide multilib details here for packages which are forced to be compiled for a
374 # specific ABI when run on another ABI (like x86-specific packages on amd64)
375 multilib_toolchain_setup() {
376 local v vv
377
378 export ABI=$1
379
380 # First restore any saved state we have laying around.
381 if [[ ${__DEFAULT_ABI_SAVED} == "true" ]] ; then
382 for v in CHOST CBUILD AS CC CXX LD ; do
383 vv="__abi_saved_${v}"
384 export ${v}="${!vv}"
385 unset ${vv}
386 done
387 unset __DEFAULT_ABI_SAVED
388 fi
389
390 # We want to avoid the behind-the-back magic of gcc-config as it
391 # screws up ccache and distcc. See #196243 for more info.
392 if [[ ${ABI} != ${DEFAULT_ABI} ]] ; then
393 # Back that multilib-ass up so we can restore it later
394 for v in CHOST CBUILD AS CC CXX LD ; do
395 export __abi_saved_${v}="${!v}"
396 done
397 export __DEFAULT_ABI_SAVED="true"
398
399 # Set the CHOST native first so that we pick up the native
400 # toolchain and not a cross-compiler by accident #202811.
401 export CHOST=$(get_abi_CHOST ${DEFAULT_ABI})
402 export AS="$(tc-getAS) $(get_abi_ASFLAGS)"
403 export CC="$(tc-getCC) $(get_abi_CFLAGS)"
404 export CXX="$(tc-getCXX) $(get_abi_CFLAGS)"
405 export LD="$(tc-getLD) $(get_abi_LDFLAGS)"
406 export CHOST=$(get_abi_CHOST $1)
407 export CBUILD=$(get_abi_CHOST $1)
408 fi
409 }

  ViewVC Help
Powered by ViewVC 1.1.20