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

Diff of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.14 Revision 1.49
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2014 Gentoo Foundation
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# $Header: /var/cvsroot/gentoo-x86/eclass/multilib-build.eclass,v 1.14 2013/06/28 02:37:52 mgorny Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/multilib-build.eclass,v 1.49 2014/05/23 07:11:53 mgorny Exp $
4 4
5# @ECLASS: multilib-build.eclass 5# @ECLASS: multilib-build.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# gx86-multilib team <multilib@gentoo.org>
8# @AUTHOR:
7# Michał Górny <mgorny@gentoo.org> 9# Author: Michał Górny <mgorny@gentoo.org>
8# @BLURB: flags and utility functions for building multilib packages 10# @BLURB: flags and utility functions for building multilib packages
9# @DESCRIPTION: 11# @DESCRIPTION:
10# The multilib-build.eclass exports USE flags and utility functions 12# The multilib-build.eclass exports USE flags and utility functions
11# necessary to build packages for multilib in a clean and uniform 13# necessary to build packages for multilib in a clean and uniform
12# manner. 14# manner.
26inherit multibuild multilib 28inherit multibuild multilib
27 29
28# @ECLASS-VARIABLE: _MULTILIB_FLAGS 30# @ECLASS-VARIABLE: _MULTILIB_FLAGS
29# @INTERNAL 31# @INTERNAL
30# @DESCRIPTION: 32# @DESCRIPTION:
31# The list of multilib flags and corresponding ABI values. 33# The list of multilib flags and corresponding ABI values. If the same
34# flag is reused for multiple ABIs (e.g. x86 on Linux&FreeBSD), multiple
35# ABIs may be separated by commas.
36#
37# Please contact multilib before modifying this list. This way we can
38# ensure that every *preliminary* work is done and the multilib can be
39# extended safely.
32_MULTILIB_FLAGS=( 40_MULTILIB_FLAGS=(
33 abi_x86_32:x86 41 abi_x86_32:x86,x86_fbsd
34 abi_x86_64:amd64 42 abi_x86_64:amd64,amd64_fbsd
35 abi_x86_x32:x32 43 abi_x86_x32:x32
44 abi_mips_n32:n32
45 abi_mips_n64:n64
46 abi_mips_o32:o32
36) 47)
48
49# @ECLASS-VARIABLE: MULTILIB_COMPAT
50# @DEFAULT_UNSET
51# @DESCRIPTION:
52# List of multilib ABIs supported by the ebuild. If unset, defaults to
53# all ABIs supported by the eclass.
54#
55# This variable is intended for use in prebuilt multilib packages that
56# can provide binaries only for a limited set of ABIs. If ABIs need to
57# be limited due to a bug in source code, package.use.mask is
58# recommended instead.
59#
60# Example use:
61# @CODE
62# # Upstream provides binaries for x86 & amd64 only
63# MULTILIB_COMPAT=( abi_x86_{32,64} )
64# @CODE
37 65
38# @ECLASS-VARIABLE: MULTILIB_USEDEP 66# @ECLASS-VARIABLE: MULTILIB_USEDEP
39# @DESCRIPTION: 67# @DESCRIPTION:
40# The USE-dependency to be used on dependencies (libraries) needing 68# The USE-dependency to be used on dependencies (libraries) needing
41# to support multilib as well. 69# to support multilib as well.
46# net-libs/libbar[ssl,${MULTILIB_USEDEP}]" 74# net-libs/libbar[ssl,${MULTILIB_USEDEP}]"
47# @CODE 75# @CODE
48 76
49_multilib_build_set_globals() { 77_multilib_build_set_globals() {
50 local flags=( "${_MULTILIB_FLAGS[@]%:*}" ) 78 local flags=( "${_MULTILIB_FLAGS[@]%:*}" )
79
80 if [[ ${MULTILIB_COMPAT[@]} ]]; then
81 # Validate MULTILIB_COMPAT and filter out the flags.
82 local f
83 for f in "${MULTILIB_COMPAT[@]}"; do
84 if ! has "${f}" "${flags[@]}"; then
85 die "Invalid value in MULTILIB_COMPAT: ${f}"
86 fi
87 done
88
89 flags=( "${MULTILIB_COMPAT[@]}" )
90 fi
91
51 local usedeps=${flags[@]/%/(-)?} 92 local usedeps=${flags[@]/%/(-)?}
52 93
53 IUSE=${flags[*]} 94 IUSE=${flags[*]}
54 MULTILIB_USEDEP=${usedeps// /,} 95 MULTILIB_USEDEP=${usedeps// /,}
55} 96}
63# If multilib is disabled, the default ABI will be returned 104# If multilib is disabled, the default ABI will be returned
64# in order to enforce consistent testing with multilib code. 105# in order to enforce consistent testing with multilib code.
65multilib_get_enabled_abis() { 106multilib_get_enabled_abis() {
66 debug-print-function ${FUNCNAME} "${@}" 107 debug-print-function ${FUNCNAME} "${@}"
67 108
109 local pairs=( $(multilib_get_enabled_abi_pairs) )
110 echo "${pairs[@]#*:}"
111}
112
113# @FUNCTION: multilib_get_enabled_abi_pairs
114# @DESCRIPTION:
115# Return the ordered list of enabled <use-flag>:<ABI> pairs
116# if multilib builds are enabled. The best (most preferred)
117# ABI will come last.
118#
119# If multilib is disabled, the default ABI will be returned
120# along with empty <use-flag>.
121multilib_get_enabled_abi_pairs() {
122 debug-print-function ${FUNCNAME} "${@}"
123
68 local abis=( $(get_all_abis) ) 124 local abis=( $(get_all_abis) )
69 125
70 local abi i found 126 local abi i found
71 for abi in "${abis[@]}"; do 127 for abi in "${abis[@]}"; do
72 for i in "${_MULTILIB_FLAGS[@]}"; do 128 for i in "${_MULTILIB_FLAGS[@]}"; do
73 local m_abi=${i#*:} 129 local m_abis=${i#*:} m_abi
74 local m_flag=${i%:*} 130 local m_flag=${i%:*}
75 131
132 # split on ,; we can't switch IFS for function scope because
133 # paludis is broken (bug #486592), and switching it locally
134 # for the split is more complex than cheating like this
135 for m_abi in ${m_abis//,/ }; do
76 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then 136 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then
77 echo "${abi}" 137 echo "${m_flag}:${abi}"
78 found=1 138 found=1
139 break 2
79 fi 140 fi
141 done
80 done 142 done
81 done 143 done
82 144
83 if [[ ! ${found} ]]; then 145 if [[ ! ${found} ]]; then
84 # ${ABI} can be used to override the fallback (multilib-portage), 146 # ${ABI} can be used to override the fallback (multilib-portage),
85 # ${DEFAULT_ABI} is the safe fallback. 147 # ${DEFAULT_ABI} is the safe fallback.
86 local abi=${ABI:-${DEFAULT_ABI}} 148 local abi=${ABI:-${DEFAULT_ABI}}
87 149
88 debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}" 150 debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}"
89 debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}" 151 debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}"
90 echo ${abi} 152 echo ":${abi}"
91 fi 153 fi
92} 154}
93 155
94# @FUNCTION: _multilib_multibuild_wrapper 156# @FUNCTION: _multilib_multibuild_wrapper
95# @USAGE: <argv>... 157# @USAGE: <argv>...
224# MULTILIB_WRAPPED_HEADERS=( 286# MULTILIB_WRAPPED_HEADERS=(
225# /usr/include/foobar/config.h 287# /usr/include/foobar/config.h
226# ) 288# )
227# @CODE 289# @CODE
228 290
291# @ECLASS-VARIABLE: MULTILIB_CHOST_TOOLS
292# @DESCRIPTION:
293# A list of tool executables to preserve for each multilib ABI.
294# The listed executables will be renamed to ${CHOST}-${basename},
295# and the native variant will be symlinked to the generic name.
296#
297# This variable has to be a bash array. Paths shall be relative to
298# installation root (${ED}), and name regular files or symbolic
299# links to regular files. Recursive wrapping is not supported.
300#
301# If symbolic link is passed, both symlink path and symlink target
302# will be changed. As a result, the symlink target is expected
303# to be wrapped as well (either by listing in MULTILIB_CHOST_TOOLS
304# or externally).
305#
306# Please note that tool wrapping is *discouraged*. It is preferred to
307# install pkg-config files for each ABI, and require reverse
308# dependencies to use that.
309#
310# Packages that search for tools properly (e.g. using AC_PATH_TOOL
311# macro) will find the wrapper executables automatically. Other packages
312# will need explicit override of tool paths.
313#
314# Example:
315# @CODE
316# MULTILIB_CHOST_TOOLS=(
317# /usr/bin/foo-config
318# )
319
320# @CODE
229# @FUNCTION: multilib_prepare_wrappers 321# @FUNCTION: multilib_prepare_wrappers
230# @USAGE: [<install-root>] 322# @USAGE: [<install-root>]
231# @DESCRIPTION: 323# @DESCRIPTION:
232# Perform the preparation of all kinds of wrappers for the current ABI. 324# Perform the preparation of all kinds of wrappers for the current ABI.
233# This function shall be called once per each ABI, after installing 325# This function shall be called once per each ABI, after installing
249 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments" 341 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
250 342
251 local root=${1:-${ED}} 343 local root=${1:-${ED}}
252 local f 344 local f
253 345
346 if [[ ${COMPLETE_MULTILIB} == yes ]]; then
347 # symlink '${CHOST}-foo -> foo' to support abi-wrapper while
348 # keeping ${CHOST}-foo calls correct.
349
350 for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
351 # drop leading slash if it's there
352 f=${f#/}
353
354 local dir=${f%/*}
355 local fn=${f##*/}
356
357 ln -s "${fn}" "${root}/${dir}/${CHOST}-${fn}" || die
358 done
359
360 return
361 fi
362
254 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do 363 for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
255 # drop leading slash if it's there 364 # drop leading slash if it's there
256 f=${f#/} 365 f=${f#/}
257 366
258 if [[ ${f} != usr/include/* ]]; then 367 local dir=${f%/*}
259 die "Wrapping headers outside of /usr/include is not supported at the moment." 368 local fn=${f##*/}
369
370 if [[ -L ${root}/${f} ]]; then
371 # rewrite the symlink target
372 local target=$(readlink "${root}/${f}")
373 local target_dir
374 local target_fn=${target##*/}
375
376 [[ ${target} == */* ]] && target_dir=${target%/*}
377
378 ln -f -s "${target_dir+${target_dir}/}${CHOST}-${target_fn}" \
379 "${root}/${f}" || die
260 fi 380 fi
381
382 mv "${root}/${f}" "${root}/${dir}/${CHOST}-${fn}" || die
383
384 # symlink the native one back
385 if multilib_is_native_abi; then
386 ln -s "${CHOST}-${fn}" "${root}/${f}" || die
387 fi
388 done
389
390 if [[ ${MULTILIB_WRAPPED_HEADERS[@]} ]]; then
391 # XXX: get abi_* directly
392 local abi_flag
393 case "${ABI}" in
394 amd64|amd64_fbsd)
395 abi_flag=abi_x86_64;;
396 x86|x86_fbsd)
397 abi_flag=abi_x86_32;;
398 x32)
399 abi_flag=abi_x86_x32;;
400 n32)
401 abi_flag=abi_mips_n32;;
402 n64)
403 abi_flag=abi_mips_n64;;
404 o32)
405 abi_flag=abi_mips_o32;;
406 esac
407
408 # If abi_flag is unset, then header wrapping is unsupported
409 # on this ABI. This could mean either that:
410 #
411 # 1) the arch doesn't support multilib at all -- in this case,
412 # the headers are not wrapped and everything works as expected,
413 #
414 # 2) someone added new ABI and forgot to update the function --
415 # in this case, the header consistency check will notice one of
416 # those ABIs has an extra header (compared to the header moved
417 # for wrapping) and will fail.
418
419 if [[ ${abi_flag} ]]; then
420 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
421 # drop leading slash if it's there
422 f=${f#/}
423
424 if [[ ${f} != usr/include/* ]]; then
425 die "Wrapping headers outside of /usr/include is not supported at the moment."
426 fi
261 # and then usr/include 427 # and then usr/include
262 f=${f#usr/include} 428 f=${f#usr/include}
263 429
264 local dir=${f%/*} 430 local dir=${f%/*}
265 431
266 # $CHOST shall be set by multilib_toolchain_setup 432 # Some ABIs may have install less files than others.
267 dodir "/tmp/multilib-include/${CHOST}${dir}" 433 if [[ -f ${root}/usr/include${f} ]]; then
268 mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
269
270 if [[ ! -f ${ED}/tmp/multilib-include${f} ]]; then 434 if [[ ! -f ${ED}/tmp/multilib-include${f} ]]; then
271 dodir "/tmp/multilib-include${dir}" 435 dodir "/tmp/multilib-include${dir}"
272 # a generic template 436 # a generic template
273 cat > "${ED}/tmp/multilib-include${f}" <<_EOF_ 437 cat > "${ED}/tmp/multilib-include${f}" <<_EOF_
274/* This file is auto-generated by multilib-build.eclass 438/* This file is auto-generated by multilib-build.eclass
275 * as a multilib-friendly wrapper. For the original content, 439 * as a multilib-friendly wrapper. For the original content,
276 * please see the files that are #included below. 440 * please see the files that are #included below.
277 */ 441 */
278 442
282# else /* 64-bit ABI */ 446# else /* 64-bit ABI */
283# error "abi_x86_64 not supported by the package." 447# error "abi_x86_64 not supported by the package."
284# endif 448# endif
285#elif defined(__i386__) /* plain x86 */ 449#elif defined(__i386__) /* plain x86 */
286# error "abi_x86_32 not supported by the package." 450# error "abi_x86_32 not supported by the package."
451#elif defined(__mips__)
452# if(_MIPS_SIM == _ABIN32) /* n32 */
453# error "abi_mips_n32 not supported by the package."
454# elif(_MIPS_SIM == _ABI64) /* n64 */
455# error "abi_mips_n64 not supported by the package."
456# elif(_MIPS_SIM == _ABIO32) /* o32 */
457# error "abi_mips_o32 not supported by the package."
458# endif
287#else 459#else
288# error "No ABI matched, please report a bug to bugs.gentoo.org" 460# error "No ABI matched, please report a bug to bugs.gentoo.org"
289#endif 461#endif
290_EOF_ 462_EOF_
463 fi
464
465 # $CHOST shall be set by multilib_toolchain_setup
466 dodir "/tmp/multilib-include/${CHOST}${dir}"
467 mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
468
469 # Note: match a space afterwards to avoid collision potential.
470 sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
471 -i "${ED}/tmp/multilib-include${f}" || die
472
473 # Hack for emul-linux-x86 compatibility.
474 # It assumes amd64 will come after x86, and will use amd64
475 # headers if no specific x86 headers were installed.
476 if [[ ${ABI} == amd64 ]]; then
477 sed -e "/abi_x86_32 /s&error.*&include <${CHOST}${f}>&" \
478 -i "${ED}/tmp/multilib-include${f}" || die
479 fi
480 fi
481 done
291 fi 482 fi
292 483 fi
293 # XXX: get abi_* directly
294 local abi_flag
295 case "${ABI}" in
296 amd64)
297 abi_flag=abi_x86_64;;
298 x86)
299 abi_flag=abi_x86_32;;
300 x32)
301 abi_flag=abi_x86_x32;;
302 *)
303 die "Header wrapping for ${ABI} not supported yet";;
304 esac
305
306 # Note: match a space afterwards to avoid collision potential.
307 sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
308 -i "${ED}/tmp/multilib-include${f}" || die
309 done
310} 484}
311 485
312# @FUNCTION: multilib_install_wrappers 486# @FUNCTION: multilib_install_wrappers
313# @USAGE: [<install-root>] 487# @USAGE: [<install-root>]
314# @DESCRIPTION: 488# @DESCRIPTION:
326multilib_install_wrappers() { 500multilib_install_wrappers() {
327 debug-print-function ${FUNCNAME} "${@}" 501 debug-print-function ${FUNCNAME} "${@}"
328 502
329 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments" 503 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
330 504
505 [[ ${COMPLETE_MULTILIB} == yes ]] && return
506
331 local root=${1:-${ED}} 507 local root=${1:-${ED}}
332 508
333 if [[ -d "${ED}"/tmp/multilib-include ]]; then 509 if [[ -d "${ED}"/tmp/multilib-include ]]; then
334 multibuild_merge_root \ 510 multibuild_merge_root \
335 "${ED}"/tmp/multilib-include "${root}"/usr/include 511 "${ED}"/tmp/multilib-include "${root}"/usr/include
336 # it can fail if something else uses /tmp 512 # it can fail if something else uses /tmp
337 rmdir "${ED}"/tmp &>/dev/null 513 rmdir "${ED}"/tmp &>/dev/null
338 fi 514 fi
339} 515}
340 516
517# @FUNCTION: multilib_is_native_abi
518# @DESCRIPTION:
519# Determine whether the currently built ABI is the profile native.
520# Return true status (0) if that is true, otherwise false (1).
521#
522# This function is not intended to be used directly. Please use
523# multilib_build_binaries instead.
524multilib_is_native_abi() {
525 debug-print-function ${FUNCNAME} "${@}"
526
527 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
528
529 [[ ${COMPLETE_MULTILIB} == yes || ${ABI} == ${DEFAULT_ABI} ]]
530}
531
532# @FUNCTION: multilib_build_binaries
533# @DESCRIPTION:
534# Determine whether to build binaries for the currently built ABI.
535# Returns true status (0) if the currently built ABI is the profile
536# native or COMPLETE_MULTILIB variable is set to 'yes', otherwise
537# false (1).
538#
539# This is often useful for configure calls when some of the options are
540# supposed to be disabled for multilib ABIs (like those used for
541# executables only).
542multilib_build_binaries() {
543 debug-print-function ${FUNCNAME} "${@}"
544
545 eqawarn "QA warning: multilib_build_binaries is deprecated. Please use the equivalent"
546 eqawarn "multilib_is_native_abi function instead."
547
548 multilib_is_native_abi "${@}"
549}
550
551# @FUNCTION: multilib_native_use_with
552# @USAGE: <flag> [<opt-name> [<opt-value>]]
553# @DESCRIPTION:
554# Output --with configure option alike use_with if USE <flag> is enabled
555# and executables are being built (multilib_is_native_abi is true).
556# Otherwise, outputs --without configure option. Arguments are the same
557# as for use_with in the EAPI.
558multilib_native_use_with() {
559 if multilib_is_native_abi; then
560 use_with "${@}"
561 else
562 echo "--without-${2:-${1}}"
563 fi
564}
565
566# @FUNCTION: multilib_native_use_enable
567# @USAGE: <flag> [<opt-name> [<opt-value>]]
568# @DESCRIPTION:
569# Output --enable configure option alike use_with if USE <flag>
570# is enabled and executables are being built (multilib_is_native_abi
571# is true). Otherwise, outputs --disable configure option. Arguments are
572# the same as for use_enable in the EAPI.
573multilib_native_use_enable() {
574 if multilib_is_native_abi; then
575 use_enable "${@}"
576 else
577 echo "--disable-${2:-${1}}"
578 fi
579}
580
581# @FUNCTION: multilib_native_usex
582# @USAGE: <flag> [<true1> [<false1> [<true2> [<false2>]]]]
583# @DESCRIPTION:
584# Output the concatenation of <true1> (or 'yes' if unspecified)
585# and <true2> if USE <flag> is enabled and executables are being built
586# (multilib_is_native_abi is true). Otherwise, output the concatenation
587# of <false1> (or 'no' if unspecified) and <false2>. Arguments
588# are the same as for usex in the EAPI.
589#
590# Note: in EAPI 4 you need to inherit eutils to use this function.
591multilib_native_usex() {
592 if multilib_is_native_abi; then
593 usex "${@}"
594 else
595 echo "${3-no}${5}"
596 fi
597}
598
341_MULTILIB_BUILD=1 599_MULTILIB_BUILD=1
342fi 600fi

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.49

  ViewVC Help
Powered by ViewVC 1.1.20