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

Contents of /eclass/multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (show annotations) (download)
Thu Oct 6 10:03:53 2005 UTC (8 years, 9 months ago) by eradicator
Branch: MAIN
Changes since 1.33: +84 -1 lines
Added multilib_env().

1 # Copyright 1999-2004 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.33 2005/09/21 02:50:37 vapier Exp $
4 #
5 # Author: Jeremy Huddleston <eradicator@gentoo.org>
6 #
7 # This eclass is for all functions pertaining to handling multilib.
8 # configurations.
9
10
11 DESCRIPTION="Based on the ${ECLASS} eclass"
12
13 # has_multilib_profile:
14 # Return true if the current profile is a multilib profile and lists more than
15 # one abi in ${MULTILIB_ABIS}. You might want to use this like
16 # 'use multilib || has_multilib_profile' until all profiles utilizing the
17 # 'multilib' use flag are removed from portage
18
19 # is_final_abi:
20 # Return true if ${ABI} is the final abi to be installed (and thus we are
21 # on our last run through a src_* function.
22
23 # number_abis:
24 # echo the number of ABIs we will be installing for
25
26 # get_install_abis:
27 # Return a list of the ABIs we want to install for with
28 # the last one in the list being the default.
29
30 # get_all_abis:
31 # Return a list of the ABIs supported by this profile.
32 # the last one in the list being the default.
33
34 # get_all_libdirs:
35 # Returns a list of all the libdirs used by this profile. This includes
36 # those that might not be touched by the current ebuild and always includes
37 # "lib".
38
39 # get_libdir:
40 # Returns the libdir for the selected ABI. This is backwards compatible
41 # and simply calls get_abi_LIBDIR() on newer profiles. You should use this
42 # to determine where to install shared objects (ex: /usr/$(get_libdir))
43
44 # get_abi_var <VAR> [<ABI>]:
45 # returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
46 #
47 # get_abi_CFLAGS:
48 # get_abi_CDEFINE:
49 # get_abi_LIBDIR:
50 # Aliases for 'get_abi_var CFLAGS', etc.
51
52 # get_ml_incdir [<include dir> [<ABI>]]
53 # include dir defaults to /usr/include
54 # ABI defaults to ${ABI} or ${DEFAULT_ABI}
55 #
56 # If a multilib include dir is associated with the passed include dir, then
57 # we return it, otherwise, we just echo back the include dir. This is
58 # neccessary when a built script greps header files rather than testing them
59 # via #include (like perl) to figure out features.
60
61 # prep_ml_includes:
62 # Some includes (include/asm, glibc, etc) are ABI dependent. In this case,
63 # We can install them in different locations for each ABI and create a common
64 # header which includes the right one based on CDEFINE_${ABI}. If your
65 # package installs ABI-specific headers, just add 'prep_ml_includes' to the
66 # end of your src_install(). It takes a list of directories that include
67 # files are installed in (default is /usr/include if none are passed).
68 #
69 # Example:
70 # src_install() {
71 # ...
72 # prep_ml_includes /usr/qt/3/include
73 # }
74
75 # create_ml_includes <include dir> <symbol 1>:<dir 1> [<symbol 2>:<dir 2> ...]
76 # If you need more control than prep_ml_includes can offer (like linux-headers
77 # for the asm-* dirs, then use create_ml_includes. The firs argument is the
78 # common dir. The remaining args are of the form <symbol>:<dir> where
79 # <symbol> is what is put in the #ifdef for choosing that dir.
80 #
81 # Ideas for this code came from debian's sparc-linux headers package.
82 #
83 # Example:
84 # create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64
85 # create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64
86
87 # get_libname [version]
88 # returns libname with proper suffix {.so,.dylib} and optionally supplied version
89 # for ELF/MACH-O shared objects
90 #
91 # Example:
92 # get_libname libfoo ${PV}
93 # Returns: libfoo.so.${PV} (ELF) || libfoo.${PV}.dylib (MACH)
94
95 ### END DOCUMENTATION ###
96
97 # Defaults:
98 export MULTILIB_ABIS=${MULTILIB_ABIS:-"default"}
99 export DEFAULT_ABI=${DEFAULT_ABI:-"default"}
100 # This causes econf to set --libdir=/usr/lib where it didn't before
101 #export ABI=${ABI:-"default"}
102 export CFLAGS_default
103 export LDFLAGS_default
104 export CHOST_default=${CHOST_default:-${CHOST}}
105 export LIBDIR_default=${CONF_LIBDIR:-"lib"}
106 export CDEFINE_default="__unix__"
107
108 # has_multilib_profile()
109 has_multilib_profile() {
110 [ -n "${MULTILIB_ABIS}" -a "${MULTILIB_ABIS}" != "${MULTILIB_ABIS/ /}" ]
111 }
112
113 # This function simply returns the desired lib directory. With portage
114 # 2.0.51, we now have support for installing libraries to lib32/lib64
115 # to accomidate the needs of multilib systems. It's no longer a good idea
116 # to assume all libraries will end up in lib. Replace any (sane) instances
117 # where lib is named directly with $(get_libdir) if possible.
118 #
119 # Travis Tilley <lv@gentoo.org> (24 Aug 2004)
120 #
121 # Jeremy Huddleston <eradicator@gentoo.org> (23 Dec 2004):
122 # Added support for ${ABI} and ${DEFAULT_ABI}. If they're both not set,
123 # fall back on old behavior. Any profile that has these set should also
124 # depend on a newer version of portage (not yet released) which uses these
125 # over CONF_LIBDIR in econf, dolib, etc...
126 get_libdir() {
127 local CONF_LIBDIR
128 if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then
129 # if there is an override, we want to use that... always.
130 echo ${CONF_LIBDIR_OVERRIDE}
131 else
132 get_abi_LIBDIR
133 fi
134 }
135
136 get_multilibdir() {
137 if has_multilib_profile; then
138 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"
139 exit 1
140 fi
141 echo ${CONF_MULTILIBDIR:=lib32}
142 }
143
144 # Sometimes you need to override the value returned by get_libdir. A good
145 # example of this is xorg-x11, where lib32 isnt a supported configuration,
146 # and where lib64 -must- be used on amd64 (for applications that need lib
147 # to be 32bit, such as adobe acrobat). Note that this override also bypasses
148 # portage version sanity checking.
149 # get_libdir_override expects one argument, the result get_libdir should
150 # return:
151 #
152 # get_libdir_override lib64
153 #
154 # Travis Tilley <lv@gentoo.org> (31 Aug 2004)
155 get_libdir_override() {
156 if has_multilib_profile; then
157 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"
158 exit 1
159 fi
160 CONF_LIBDIR="$1"
161 CONF_LIBDIR_OVERRIDE="$1"
162 LIBDIR_default="$1"
163 }
164
165 # get_abi_var <VAR> [<ABI>]
166 # returns the value of ${<VAR>_<ABI>} which should be set in make.defaults
167 #
168 # ex:
169 # CFLAGS=$(get_abi_var CFLAGS sparc32) # CFLAGS=-m32
170 #
171 # Note that the prefered method is to set CC="$(tc-getCC) $(get_abi_CFLAGS)"
172 # This will hopefully be added to portage soon...
173 #
174 # If <ABI> is not specified, ${ABI} is used.
175 # If <ABI> is not specified and ${ABI} is not defined, ${DEFAULT_ABI} is used.
176 # If <ABI> is not specified and ${ABI} and ${DEFAULT_ABI} are not defined, we return an empty string.
177 #
178 # Jeremy Huddleston <eradicator@gentoo.org>
179 get_abi_var() {
180 local flag=$1
181 local abi
182 if [ $# -gt 1 ]; then
183 abi=${2}
184 elif [ -n "${ABI}" ]; then
185 abi=${ABI}
186 elif [ -n "${DEFAULT_ABI}" ]; then
187 abi=${DEFAULT_ABI}
188 else
189 abi="default"
190 fi
191
192 local var="${flag}_${abi}"
193 echo ${!var}
194 }
195
196 get_abi_CFLAGS() { get_abi_var CFLAGS "$@"; }
197 get_abi_LDFLAGS() { get_abi_var LDFLAGS "$@"; }
198 get_abi_CHOST() { get_abi_var CHOST "$@"; }
199 get_abi_FAKE_TARGETS() { get_abi_var FAKE_TARGETS "$@"; }
200 get_abi_CDEFINE() { get_abi_var CDEFINE "$@"; }
201 get_abi_LIBDIR() { get_abi_var LIBDIR "$@"; }
202
203 # Return a list of the ABIs we want to install for with
204 # the last one in the list being the default.
205 get_install_abis() {
206 local order=""
207
208 if [[ -z ${MULTILIB_ABIS} ]] ; then
209 echo "default"
210 return 0
211 fi
212
213 if hasq multilib-pkg-force ${RESTRICT} ||
214 { hasq multilib-pkg ${FEATURES} && hasq multilib-pkg ${RESTRICT}; }; then
215 for x in ${MULTILIB_ABIS} ; do
216 if [[ ${x} != "${DEFAULT_ABI}" ]] ; then
217 hasq ${x} ${ABI_DENY} || ordera="${ordera} ${x}"
218 fi
219 done
220 hasq ${DEFAULT_ABI} ${ABI_DENY} || order="${ordera} ${DEFAULT_ABI}"
221
222 if [[ -n ${ABI_ALLOW} ]] ; then
223 local ordera=""
224 for x in ${order} ; do
225 if hasq ${x} ${ABI_ALLOW} ; then
226 ordera="${ordera} ${x}"
227 fi
228 done
229 order=${ordera}
230 fi
231 else
232 order=${DEFAULT_ABI}
233 fi
234
235 if [[ -z ${order} ]] ; then
236 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."
237 fi
238
239 echo ${order}
240 return 0
241 }
242
243 # Return a list of the ABIs supported by this profile.
244 # the last one in the list being the default.
245 get_all_abis() {
246 local order=""
247
248 if [ -z "${MULTILIB_ABIS}" ]; then
249 echo "default"
250 return 0
251 fi
252
253 for x in ${MULTILIB_ABIS}; do
254 if [ "${x}" != "${DEFAULT_ABI}" ]; then
255 order="${order:+${order }}${x}"
256 fi
257 done
258 order="${order:+${order} }${DEFAULT_ABI}"
259
260 echo ${order}
261 return 0
262 }
263
264 # get_all_libdirs()
265 # Returns a list of all the libdirs used by this profile. This includes
266 # those that might not be touched by the current ebuild.
267 get_all_libdirs() {
268 local libdirs="lib"
269 local abi
270 local dir
271
272 if has_multilib_profile; then
273 for abi in ${MULTILIB_ABIS}; do
274 [ "$(get_abi_LIBDIR ${abi})" != "lib" ] && libdirs="${libdirs} $(get_abi_LIBDIR ${abi})"
275 done
276 elif [ -n "${CONF_LIBDIR}" ]; then
277 for dir in ${CONF_LIBDIR} ${CONF_MULTILIBDIR:-lib32}; do
278 [ "${dir}" != "lib" ] && libdirs="${libdirs} ${dir}"
279 done
280 fi
281
282 echo "${libdirs}"
283 }
284
285 # Return true if ${ABI} is the last ABI on our list (or if we're not
286 # using the new multilib configuration. This can be used to determine
287 # if we're in the last (or only) run through src_{unpack,compile,install}
288 is_final_abi() {
289 has_multilib_profile || return 0
290 local ALL_ABIS=$(get_install_abis)
291 local LAST_ABI=${ALL_ABIS/* /}
292 [[ ${LAST_ABI} == ${ABI} ]]
293 }
294
295 # echo the number of ABIs we will be installing for
296 number_abis() {
297 get_install_abis | wc -w
298 }
299
300 # get_ml_incdir [<include dir> [<ABI>]]
301 # include dir defaults to /usr/include
302 # ABI defaults to ${ABI} or ${DEFAULT_ABI}
303 get_ml_incdir() {
304 local dir=/usr/include
305
306 if [[ $# -gt 0 ]]; then
307 incdir=$1
308 shift
309 fi
310
311 if [[ -z "${MULTILIB_ABIS}" ]]; then
312 echo ${incdir}
313 return 0
314 fi
315
316 local abi=${ABI-${DEFAULT_ABI}}
317 if [[ $# -gt 0 ]]; then
318 abi=$1
319 shift
320 fi
321
322 if [[ -d "${dir}/gentoo-multilib/${abi}" ]]; then
323 echo ${dir}/gentoo-multilib/${abi}
324 else
325 echo ${dir}
326 fi
327 }
328
329 # prep_ml_includes:
330 #
331 # Some includes (include/asm, glibc, etc) are ABI dependent. In this case,
332 # We can install them in different locations for each ABI and create a common
333 # header which includes the right one based on CDEFINE_${ABI}. If your
334 # package installs ABI-specific headers, just add 'prep_ml_includes' to the
335 # end of your src_install(). It takes a list of directories that include
336 # files are installed in (default is /usr/include if none are passed).
337 #
338 # Example:
339 # src_install() {
340 # ...
341 # prep_ml_includes /usr/qt/3/include
342 # }
343
344 prep_ml_includes() {
345 if [[ $(number_abis) -gt 1 ]] ; then
346 local dir
347 local dirs
348 local base
349
350 if [[ $# -eq 0 ]] ; then
351 dirs=/usr/include
352 else
353 dirs="$@"
354 fi
355
356 for dir in ${dirs} ; do
357 base=${T}/gentoo-multilib/${dir}/gentoo-multilib
358 mkdir -p "${base}"
359 [[ -d ${base}/${ABI} ]] && rm -rf "${base}/${ABI}"
360 mv "${D}/${dir}" "${base}/${ABI}"
361 done
362
363 if is_final_abi; then
364 base=${T}/gentoo-multilib
365 pushd "${base}"
366 find . | tar -c -T - -f - | tar -x --no-same-owner -f - -C ${D}
367 popd
368
369 # This 'set' stuff is required by mips profiles to properly pass
370 # CDEFINE's (which have spaces) to sub-functions
371 set --
372 for dir in ${dirs} ; do
373 set -- "$@" "${dir}"
374 local abi
375 for abi in $(get_install_abis); do
376 set -- "$@" "$(get_abi_CDEFINE ${abi}):${dir}/gentoo-multilib/${abi}"
377 done
378 create_ml_includes "$@"
379 done
380 fi
381 fi
382 }
383
384 # If you need more control than prep_ml_includes can offer (like linux-headers
385 # for the asm-* dirs, then use create_ml_includes. The firs argument is the
386 # common dir. The remaining args are of the form <symbol>:<dir> where
387 # <symbol> is what is put in the #ifdef for choosing that dir.
388 #
389 # Ideas for this code came from debian's sparc-linux headers package.
390 #
391 # Example:
392 # create_ml_includes /usr/include/asm __sparc__:/usr/include/asm-sparc __sparc64__:/usr/include/asm-sparc64
393 # create_ml_includes /usr/include/asm __i386__:/usr/include/asm-i386 __x86_64__:/usr/include/asm-x86_64
394 create_ml_includes() {
395 local dest=$1
396 shift
397 local basedirs=$(create_ml_includes-listdirs "$@")
398
399 create_ml_includes-makedestdirs ${dest} ${basedirs}
400
401 local file
402 for file in $(create_ml_includes-allfiles ${basedirs}) ; do
403 #local name=$(echo ${file} | tr '[:lower:]' '[:upper:]' | sed 's:[^[:upper:]]:_:g')
404 (
405 echo "/* Autogenerated by create_ml_includes() in multilib.eclass */"
406
407 local dir
408 for dir in ${basedirs}; do
409 if [[ -f ${D}/${dir}/${file} ]] ; then
410 echo ""
411 local sym=$(create_ml_includes-sym_for_dir ${dir} "$@")
412 if [[ ${sym/=} != "${sym}" ]] ; then
413 echo "#if ${sym}"
414 elif [[ ${sym::1} == "!" ]] ; then
415 echo "#ifndef ${sym:1}"
416 else
417 echo "#ifdef ${sym}"
418 fi
419 echo "# include <$(create_ml_includes-absolute ${dir}/${file})>"
420 echo "#endif /* ${sym} */"
421 fi
422 done
423
424 #echo "#endif /* __CREATE_ML_INCLUDES_STUB_${name}__ */"
425 ) > "${D}/${dest}/${file}"
426 done
427 }
428
429 # Helper function for create_ml_includes
430 create_ml_includes-absolute() {
431 local dst="$(create_ml_includes-tidy_path $1)"
432
433 dst=(${dst//\// })
434
435 local i
436 for ((i=0; i<${#dst[*]}; i++)); do
437 [ "${dst[i]}" == "include" ] && break
438 done
439
440 local strip_upto=$i
441
442 for ((i=strip_upto+1; i<${#dst[*]}-1; i++)); do
443 echo -n ${dst[i]}/
444 done
445
446 echo -n ${dst[i]}
447 }
448
449 # Helper function for create_ml_includes
450 create_ml_includes-tidy_path() {
451 local removed=$1
452
453 if [ -n "${removed}" ]; then
454 # Remove multiple slashes
455 while [ "${removed}" != "${removed/\/\//\/}" ]; do
456 removed=${removed/\/\//\/}
457 done
458
459 # Remove . directories
460 while [ "${removed}" != "${removed//\/.\//\/}" ]; do
461 removed=${removed//\/.\//\/}
462 done
463 [ "${removed##*/}" = "." ] && removed=${removed%/*}
464
465 # Removed .. directories
466 while [ "${removed}" != "${removed//\/..\/}" ]; do
467 local p1="${removed%%\/..\/*}"
468 local p2="${removed#*\/..\/}"
469
470 removed="${p1%\/*}/${p2}"
471 done
472
473 # Remove trailing ..
474 [ "${removed##*/}" = ".." ] && removed=${removed%/*/*}
475
476 # Remove trailing /
477 [ "${removed##*/}" = "" ] && removed=${removed%/*}
478
479 echo ${removed}
480 fi
481 }
482
483 # Helper function for create_ml_includes
484 create_ml_includes-listdirs() {
485 local dirs
486 local data
487 for data in "$@"; do
488 dirs="${dirs} ${data/*:/}"
489 done
490 echo ${dirs:1}
491 }
492
493 # Helper function for create_ml_includes
494 create_ml_includes-makedestdirs() {
495 local dest=$1
496 shift
497 local basedirs=$@
498
499 dodir ${dest}
500
501 local basedir
502 for basedir in ${basedirs}; do
503 local dir
504 for dir in $(find ${D}/${basedir} -type d); do
505 dodir ${dest}/${dir/${D}\/${basedir}/}
506 done
507 done
508 }
509
510 # Helper function for create_ml_includes
511 create_ml_includes-allfiles() {
512 local basedir file
513 for basedir in "$@" ; do
514 for file in $(find "${D}"/${basedir} -type f); do
515 echo ${file/${D}\/${basedir}\//}
516 done
517 done | sort | uniq
518 }
519
520 # Helper function for create_ml_includes
521 create_ml_includes-sym_for_dir() {
522 local dir=$1
523 shift
524 local data
525 for data in "$@"; do
526 if [[ ${data} == *:${dir} ]] ; then
527 echo ${data/:*/}
528 return 0
529 fi
530 done
531 echo "Shouldn't be here -- create_ml_includes-sym_for_dir $1 $@"
532 # exit because we'll likely be called from a subshell
533 exit 1
534 }
535
536 get_libname() {
537 local ver=$1
538 if use userland_Darwin ; then
539 if [ -z ${ver} ] ; then
540 echo ".dylib"
541 else
542 echo ".${ver}.dylib"
543 fi
544 else
545 if [ -z ${ver} ] ; then
546 echo ".so"
547 else
548 echo ".so.${ver}"
549 fi
550 fi
551 }
552
553 # This is for the toolchain to setup profile variables when pulling in
554 # a crosscompiler (and thus they aren't set in the profile)
555 multilib_env() {
556 local CTARGET=$1
557 local CTARGET_post=${CTARGET#*-}
558
559 case $(tc-arch ${CTARGET}) in
560 amd64)
561 export CFLAGS_x86=${CFLAGS_x86--m32}
562 export CHOST_x86=i686-${CTARGET_post}
563 export CTARGET_x86=i686-${CTARGET_post}
564 export CDEFINE_x86="__i386__"
565 export LIBDIR_x86="lib"
566
567 export CFLAGS_amd64=${CFLAGS_amd64--m64}
568 export CHOST_amd64=x86_64-${CTARGET_post}
569 export CTARGET_amd64=x86_64-${CTARGET_post}
570 export CDEFINE_amd64="__x86_64__"
571 export LIBDIR_amd64="lib64"
572
573 export MULTILIB_ABIS="amd64 x86"
574 export DEFAULT_ABI="amd64"
575 ;;
576 mips)
577 export CFLAGS_o32=${CFLAGS_o32--mabi=32}
578 export CHOST_o32=mips-${CTARGET_post}
579 export CTARGET_o32=mips-${CTARGET_post}
580 export CDEFINE_o32="_MIPS_SIM == _ABIO32"
581 export LIBDIR_o32="lib"
582
583 export CFLAGS_n32=${CFLAGS_n32--mabi=n32}
584 export CHOST_n32=mips64-${CTARGET_post}
585 export CTARGET_n32=mips64-${CTARGET_post}
586 export CDEFINE_n32="_MIPS_SIM == _ABIN32"
587 export LIBDIR_n32="lib32"
588
589 export CFLAGS_n64=${CFLAGS_n64--mabi=64}
590 export CHOST_n64=mips64-${CTARGET_post}
591 export CTARGET_n64=mips64-${CTARGET_post}
592 export CDEFINE_n64="_MIPS_SIM == _ABI64"
593 export LIBDIR_n64="lib64"
594
595 export MULTILIB_ABIS="n64 n32 o32"
596 export DEFAULT_ABI="n32"
597 ;;
598 ppc64)
599 export CFLAGS_ppc=${CFLAGS_ppc--m32}
600 export CHOST_ppc=powerpc-${CTARGET_post}
601 export CTARGET_ppc=powerpc-${CTARGET_post}
602 export CDEFINE_ppc="!__powerpc64__"
603 export LIBDIR_ppc="lib"
604
605 export CFLAGS_ppc64=${CFLAGS_ppc64--m64}
606 export CHOST_ppc64=powerpc64-${CTARGET_post}
607 export CTARGET_ppc64=powerpc64-${CTARGET_post}
608 export CDEFINE_ppc64="__powerpc64__"
609 export LIBDIR_ppc64="lib64"
610
611 export MULTILIB_ABIS="ppc64 ppc"
612 export DEFAULT_ABI="ppc64"
613 ;;
614 sparc)
615 export CFLAGS_sparc32=${CFLAGS_sparc32--m32}
616 export CHOST_sparc32=sparc-${CTARGET_post}
617 export CTARGET_sparc32=sparc-${CTARGET_post}
618 export CDEFINE_sparc32="!__arch64__"
619 export LIBDIR_sparc32="lib"
620
621 export CFLAGS_sparc64=${CFLAGS_sparc64--m64}
622 export CHOST_sparc64=sparc64-${CTARGET_post}
623 export CTARGET_sparc64=sparc64-${CTARGET_post}
624 export CDEFINE_sparc64="__arch64__"
625 export LIBDIR_sparc64="lib64"
626
627 export MULTILIB_ABIS="sparc64 sparc32"
628 export DEFAULT_ABI="sparc64"
629 ;;
630 *)
631 export MULTILIB_ABIS="default"
632 export DEFAULT_ABI="default"
633 esac
634 }

  ViewVC Help
Powered by ViewVC 1.1.20