Gentoo Archives: gentoo-commits

From: "Andreas K. Hüttel" <dilfridge@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/riscv:master commit in: eclass/
Date: Sat, 05 Sep 2020 20:50:19
Message-Id: 1599338353.6ae8eae6e8cfb6f21775135e8e076adf5255dc47.dilfridge@gentoo
1 commit: 6ae8eae6e8cfb6f21775135e8e076adf5255dc47
2 Author: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
3 AuthorDate: Sat Sep 5 20:39:13 2020 +0000
4 Commit: Andreas K. Hüttel <dilfridge <AT> gentoo <DOT> org>
5 CommitDate: Sat Sep 5 20:39:13 2020 +0000
6 URL: https://gitweb.gentoo.org/proj/riscv.git/commit/?id=6ae8eae6
7
8 Copy multilib-build.eclass from main tree
9
10 Signed-off-by: Andreas K. Hüttel <dilfridge <AT> gentoo.org>
11
12 eclass/multilib-build.eclass | 686 +++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 686 insertions(+)
14
15 diff --git a/eclass/multilib-build.eclass b/eclass/multilib-build.eclass
16 new file mode 100644
17 index 0000000..620bdce
18 --- /dev/null
19 +++ b/eclass/multilib-build.eclass
20 @@ -0,0 +1,686 @@
21 +# Copyright 2013-2020 Gentoo Authors
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: multilib-build.eclass
25 +# @MAINTAINER:
26 +# gx86-multilib team <multilib@g.o>
27 +# @AUTHOR:
28 +# Author: Michał Górny <mgorny@g.o>
29 +# @SUPPORTED_EAPIS: 4 5 6 7
30 +# @BLURB: flags and utility functions for building multilib packages
31 +# @DESCRIPTION:
32 +# The multilib-build.eclass exports USE flags and utility functions
33 +# necessary to build packages for multilib in a clean and uniform
34 +# manner.
35 +#
36 +# Please note that dependency specifications for multilib-capable
37 +# dependencies shall use the USE dependency string in ${MULTILIB_USEDEP}
38 +# to properly request multilib enabled.
39 +
40 +if [[ ! ${_MULTILIB_BUILD} ]]; then
41 +
42 +# EAPI=4 is required for meaningful MULTILIB_USEDEP.
43 +case ${EAPI:-0} in
44 + 4|5|6|7) ;;
45 + *) die "EAPI=${EAPI} is not supported" ;;
46 +esac
47 +
48 +[[ ${EAPI} == [45] ]] && inherit eutils
49 +inherit multibuild multilib
50 +
51 +# @ECLASS-VARIABLE: _MULTILIB_FLAGS
52 +# @INTERNAL
53 +# @DESCRIPTION:
54 +# The list of multilib flags and corresponding ABI values. If the same
55 +# flag is reused for multiple ABIs (e.g. x86 on Linux&FreeBSD), multiple
56 +# ABIs may be separated by commas.
57 +#
58 +# Please contact multilib before modifying this list. This way we can
59 +# ensure that every *preliminary* work is done and the multilib can be
60 +# extended safely.
61 +_MULTILIB_FLAGS=(
62 + abi_x86_32:x86,x86_fbsd,x86_freebsd,x86_linux,x86_macos,x86_solaris
63 + abi_x86_64:amd64,amd64_fbsd,x64_freebsd,amd64_linux,x64_macos,x64_solaris
64 + abi_x86_x32:x32
65 + abi_mips_n32:n32
66 + abi_mips_n64:n64
67 + abi_mips_o32:o32
68 +# abi_ppc_32:ppc,ppc_aix,ppc_macos
69 +# abi_ppc_64:ppc64
70 + abi_riscv_lp64d:lp64d
71 + abi_riscv_lp64:lp64
72 + abi_s390_32:s390
73 + abi_s390_64:s390x
74 +)
75 +readonly _MULTILIB_FLAGS
76 +
77 +# @ECLASS-VARIABLE: MULTILIB_COMPAT
78 +# @DEFAULT_UNSET
79 +# @DESCRIPTION:
80 +# List of multilib ABIs supported by the ebuild. If unset, defaults to
81 +# all ABIs supported by the eclass.
82 +#
83 +# This variable is intended for use in prebuilt multilib packages that
84 +# can provide binaries only for a limited set of ABIs. If ABIs need to
85 +# be limited due to a bug in source code, package.use.mask is to be used
86 +# instead. Along with MULTILIB_COMPAT, KEYWORDS should contain '-*'.
87 +#
88 +# Note that setting this variable effectively disables support for all
89 +# other ABIs, including other architectures. For example, specifying
90 +# abi_x86_{32,64} disables support for MIPS as well.
91 +#
92 +# The value of MULTILIB_COMPAT determines the value of IUSE. If set, it
93 +# also enables REQUIRED_USE constraints.
94 +#
95 +# Example use:
96 +# @CODE
97 +# # Upstream provides binaries for x86 & amd64 only
98 +# MULTILIB_COMPAT=( abi_x86_{32,64} )
99 +# @CODE
100 +
101 +# @ECLASS-VARIABLE: MULTILIB_USEDEP
102 +# @OUTPUT_VARIABLE
103 +# @DESCRIPTION:
104 +# The USE-dependency to be used on dependencies (libraries) needing
105 +# to support multilib as well.
106 +#
107 +# Example use:
108 +# @CODE
109 +# RDEPEND="dev-libs/libfoo[${MULTILIB_USEDEP}]
110 +# net-libs/libbar[ssl,${MULTILIB_USEDEP}]"
111 +# @CODE
112 +
113 +# @ECLASS-VARIABLE: MULTILIB_ABI_FLAG
114 +# @OUTPUT_VARIABLE
115 +# @DESCRIPTION:
116 +# The complete ABI name. Resembles the USE flag name.
117 +#
118 +# This is set within multilib_foreach_abi(),
119 +# multilib_parallel_foreach_abi() and multilib-minimal sub-phase
120 +# functions.
121 +#
122 +# It may be null (empty) when the build is done on ABI not controlled
123 +# by a USE flag (e.g. on non-multilib arch or when using multilib
124 +# portage). The build will always be done for a single ABI then.
125 +#
126 +# Example value:
127 +# @CODE
128 +# abi_x86_64
129 +# @CODE
130 +
131 +_multilib_build_set_globals() {
132 + local flags=( "${_MULTILIB_FLAGS[@]%:*}" )
133 +
134 + if [[ ${MULTILIB_COMPAT[@]} ]]; then
135 + # Validate MULTILIB_COMPAT and filter out the flags.
136 + local f
137 + for f in "${MULTILIB_COMPAT[@]}"; do
138 + if ! has "${f}" "${flags[@]}"; then
139 + die "Invalid value in MULTILIB_COMPAT: ${f}"
140 + fi
141 + done
142 +
143 + flags=( "${MULTILIB_COMPAT[@]}" )
144 +
145 + REQUIRED_USE="|| ( ${flags[*]} )"
146 + fi
147 +
148 + local usedeps=${flags[@]/%/(-)?}
149 +
150 + IUSE=${flags[*]}
151 + MULTILIB_USEDEP=${usedeps// /,}
152 + readonly MULTILIB_USEDEP
153 +}
154 +_multilib_build_set_globals
155 +unset -f _multilib_build_set_globals
156 +
157 +# @FUNCTION: multilib_get_enabled_abis
158 +# @DESCRIPTION:
159 +# Return the ordered list of enabled ABIs if multilib builds
160 +# are enabled. The best (most preferred) ABI will come last.
161 +#
162 +# If multilib is disabled, the default ABI will be returned
163 +# in order to enforce consistent testing with multilib code.
164 +multilib_get_enabled_abis() {
165 + debug-print-function ${FUNCNAME} "${@}"
166 +
167 + local pairs=( $(multilib_get_enabled_abi_pairs) )
168 + echo "${pairs[@]#*.}"
169 +}
170 +
171 +# @FUNCTION: multilib_get_enabled_abi_pairs
172 +# @DESCRIPTION:
173 +# Return the ordered list of enabled <use-flag>.<ABI> pairs
174 +# if multilib builds are enabled. The best (most preferred)
175 +# ABI will come last.
176 +#
177 +# If multilib is disabled, the default ABI will be returned
178 +# along with empty <use-flag>.
179 +multilib_get_enabled_abi_pairs() {
180 + debug-print-function ${FUNCNAME} "${@}"
181 +
182 + local abis=( $(get_all_abis) )
183 +
184 + local abi i found
185 + for abi in "${abis[@]}"; do
186 + for i in "${_MULTILIB_FLAGS[@]}"; do
187 + local m_abis=${i#*:} m_abi
188 + local m_flag=${i%:*}
189 +
190 + # split on ,; we can't switch IFS for function scope because
191 + # paludis is broken (bug #486592), and switching it locally
192 + # for the split is more complex than cheating like this
193 + for m_abi in ${m_abis//,/ }; do
194 + if [[ ${m_abi} == ${abi} ]] \
195 + && { [[ ! "${MULTILIB_COMPAT[@]}" ]] || has "${m_flag}" "${MULTILIB_COMPAT[@]}"; } \
196 + && use "${m_flag}"
197 + then
198 + echo "${m_flag}.${abi}"
199 + found=1
200 + break 2
201 + fi
202 + done
203 + done
204 + done
205 +
206 + if [[ ! ${found} ]]; then
207 + # ${ABI} can be used to override the fallback (multilib-portage),
208 + # ${DEFAULT_ABI} is the safe fallback.
209 + local abi=${ABI:-${DEFAULT_ABI}}
210 +
211 + debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}"
212 + debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}"
213 + echo ".${abi}"
214 + fi
215 +}
216 +
217 +# @FUNCTION: _multilib_multibuild_wrapper
218 +# @USAGE: <argv>...
219 +# @INTERNAL
220 +# @DESCRIPTION:
221 +# Initialize the environment for ABI selected for multibuild.
222 +_multilib_multibuild_wrapper() {
223 + debug-print-function ${FUNCNAME} "${@}"
224 +
225 + local ABI=${MULTIBUILD_VARIANT#*.}
226 + local -r MULTILIB_ABI_FLAG=${MULTIBUILD_VARIANT%.*}
227 +
228 + multilib_toolchain_setup "${ABI}"
229 + readonly ABI
230 + "${@}"
231 +}
232 +
233 +# @FUNCTION: multilib_foreach_abi
234 +# @USAGE: <argv>...
235 +# @DESCRIPTION:
236 +# If multilib support is enabled, sets the toolchain up for each
237 +# supported ABI along with the ABI variable and correct BUILD_DIR,
238 +# and runs the given commands with them.
239 +#
240 +# If multilib support is disabled, it just runs the commands. No setup
241 +# is done.
242 +multilib_foreach_abi() {
243 + debug-print-function ${FUNCNAME} "${@}"
244 +
245 + local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abi_pairs) )
246 + multibuild_foreach_variant _multilib_multibuild_wrapper "${@}"
247 +}
248 +
249 +# @FUNCTION: multilib_parallel_foreach_abi
250 +# @USAGE: <argv>...
251 +# @DESCRIPTION:
252 +# If multilib support is enabled, sets the toolchain up for each
253 +# supported ABI along with the ABI variable and correct BUILD_DIR,
254 +# and runs the given commands with them.
255 +#
256 +# If multilib support is disabled, it just runs the commands. No setup
257 +# is done.
258 +#
259 +# This function used to run multiple commands in parallel. Now it's just
260 +# a deprecated alias to multilib_foreach_abi.
261 +multilib_parallel_foreach_abi() {
262 + debug-print-function ${FUNCNAME} "${@}"
263 +
264 + local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abi_pairs) )
265 + multibuild_foreach_variant _multilib_multibuild_wrapper "${@}"
266 +}
267 +
268 +# @FUNCTION: multilib_for_best_abi
269 +# @USAGE: <argv>...
270 +# @DESCRIPTION:
271 +# Runs the given command with setup for the 'best' (usually native) ABI.
272 +multilib_for_best_abi() {
273 + debug-print-function ${FUNCNAME} "${@}"
274 +
275 + [[ ${EAPI} == [45] ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use multilib_is_native_abi() instead"
276 +
277 + eqawarn "QA warning: multilib_for_best_abi() function is deprecated and should"
278 + eqawarn "not be used. The multilib_is_native_abi() check may be used instead."
279 +
280 + local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abi_pairs) )
281 +
282 + multibuild_for_best_variant _multilib_multibuild_wrapper "${@}"
283 +}
284 +
285 +# @FUNCTION: multilib_check_headers
286 +# @DESCRIPTION:
287 +# Check whether the header files are consistent between ABIs.
288 +#
289 +# This function needs to be called after each ABI's installation phase.
290 +# It obtains the header file checksums and compares them with previous
291 +# runs (if any). Dies if header files differ.
292 +multilib_check_headers() {
293 + _multilib_header_cksum() {
294 + set -o pipefail
295 +
296 + if [[ -d ${ED%/}/usr/include ]]; then
297 + find "${ED%/}"/usr/include -type f \
298 + -exec cksum {} + | sort -k2
299 + fi
300 + }
301 +
302 + local cksum cksum_prev
303 + local cksum_file=${T}/.multilib_header_cksum
304 + cksum=$(_multilib_header_cksum) || die
305 + unset -f _multilib_header_cksum
306 +
307 + if [[ -f ${cksum_file} ]]; then
308 + cksum_prev=$(< "${cksum_file}") || die
309 +
310 + if [[ ${cksum} != ${cksum_prev} ]]; then
311 + echo "${cksum}" > "${cksum_file}.new" || die
312 +
313 + eerror "Header files have changed between ABIs."
314 +
315 + if type -p diff &>/dev/null; then
316 + eerror "$(diff -du "${cksum_file}" "${cksum_file}.new")"
317 + else
318 + eerror "Old checksums in: ${cksum_file}"
319 + eerror "New checksums in: ${cksum_file}.new"
320 + fi
321 +
322 + die "Header checksum mismatch, aborting."
323 + fi
324 + else
325 + echo "${cksum}" > "${cksum_file}" || die
326 + fi
327 +}
328 +
329 +# @FUNCTION: multilib_copy_sources
330 +# @DESCRIPTION:
331 +# Create a single copy of the package sources for each enabled ABI.
332 +#
333 +# The sources are always copied from initial BUILD_DIR (or S if unset)
334 +# to ABI-specific build directory matching BUILD_DIR used by
335 +# multilib_foreach_abi().
336 +multilib_copy_sources() {
337 + debug-print-function ${FUNCNAME} "${@}"
338 +
339 + local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abi_pairs) )
340 + multibuild_copy_sources
341 +}
342 +
343 +# @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
344 +# @DEFAULT_UNSET
345 +# @DESCRIPTION:
346 +# A list of headers to wrap for multilib support. The listed headers
347 +# will be moved to a non-standard location and replaced with a file
348 +# including them conditionally to current ABI.
349 +#
350 +# This variable has to be a bash array. Paths shall be relative to
351 +# installation root (${ED}), and name regular files. Recursive wrapping
352 +# is not supported.
353 +#
354 +# Please note that header wrapping is *discouraged*. It is preferred to
355 +# install all headers in a subdirectory of libdir and use pkg-config to
356 +# locate the headers. Some C preprocessors will not work with wrapped
357 +# headers.
358 +#
359 +# Example:
360 +# @CODE
361 +# MULTILIB_WRAPPED_HEADERS=(
362 +# /usr/include/foobar/config.h
363 +# )
364 +# @CODE
365 +
366 +# @ECLASS-VARIABLE: MULTILIB_CHOST_TOOLS
367 +# @DEFAULT_UNSET
368 +# @DESCRIPTION:
369 +# A list of tool executables to preserve for each multilib ABI.
370 +# The listed executables will be renamed to ${CHOST}-${basename},
371 +# and the native variant will be symlinked to the generic name.
372 +#
373 +# This variable has to be a bash array. Paths shall be relative to
374 +# installation root (${ED}), and name regular files or symbolic
375 +# links to regular files. Recursive wrapping is not supported.
376 +#
377 +# If symbolic link is passed, both symlink path and symlink target
378 +# will be changed. As a result, the symlink target is expected
379 +# to be wrapped as well (either by listing in MULTILIB_CHOST_TOOLS
380 +# or externally).
381 +#
382 +# Please note that tool wrapping is *discouraged*. It is preferred to
383 +# install pkg-config files for each ABI, and require reverse
384 +# dependencies to use that.
385 +#
386 +# Packages that search for tools properly (e.g. using AC_PATH_TOOL
387 +# macro) will find the wrapper executables automatically. Other packages
388 +# will need explicit override of tool paths.
389 +#
390 +# Example:
391 +# @CODE
392 +# MULTILIB_CHOST_TOOLS=(
393 +# /usr/bin/foo-config
394 +# )
395 +# @CODE
396 +
397 +# @FUNCTION: multilib_prepare_wrappers
398 +# @USAGE: [<install-root>]
399 +# @DESCRIPTION:
400 +# Perform the preparation of all kinds of wrappers for the current ABI.
401 +# This function shall be called once per each ABI, after installing
402 +# the files to be wrapped.
403 +#
404 +# Takes an optional custom <install-root> from which files will be
405 +# used. If no root is specified, uses ${ED}.
406 +#
407 +# The files to be wrapped are specified using separate variables,
408 +# e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
409 +# between the successive calls to multilib_prepare_wrappers
410 +# and multilib_install_wrappers.
411 +#
412 +# After all wrappers are prepared, multilib_install_wrappers shall
413 +# be called to commit them to the installation tree.
414 +multilib_prepare_wrappers() {
415 + debug-print-function ${FUNCNAME} "${@}"
416 +
417 + [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
418 +
419 + local root=${1:-${ED%/}}
420 + local f
421 +
422 + if [[ ${COMPLETE_MULTILIB} == yes ]]; then
423 + # symlink '${CHOST}-foo -> foo' to support abi-wrapper while
424 + # keeping ${CHOST}-foo calls correct.
425 +
426 + for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
427 + # drop leading slash if it's there
428 + f=${f#/}
429 +
430 + local dir=${f%/*}
431 + local fn=${f##*/}
432 +
433 + ln -s "${fn}" "${root}/${dir}/${CHOST}-${fn}" || die
434 + done
435 +
436 + return
437 + fi
438 +
439 + for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
440 + # drop leading slash if it's there
441 + f=${f#/}
442 +
443 + local dir=${f%/*}
444 + local fn=${f##*/}
445 +
446 + if [[ -L ${root}/${f} ]]; then
447 + # rewrite the symlink target
448 + local target
449 + target=$(readlink "${root}/${f}") || die
450 + local target_dir target_fn=${target##*/}
451 +
452 + [[ ${target} == */* ]] && target_dir=${target%/*}
453 +
454 + ln -f -s "${target_dir+${target_dir}/}${CHOST}-${target_fn}" \
455 + "${root}/${f}" || die
456 + fi
457 +
458 + mv "${root}/${f}" "${root}/${dir}/${CHOST}-${fn}" || die
459 +
460 + # symlink the native one back
461 + if multilib_is_native_abi; then
462 + ln -s "${CHOST}-${fn}" "${root}/${f}" || die
463 + fi
464 + done
465 +
466 + if [[ ${MULTILIB_WRAPPED_HEADERS[@]} ]]; then
467 + # If abi_flag is unset, then header wrapping is unsupported on
468 + # this ABI. This means the arch doesn't support multilib at all
469 + # -- in this case, the headers are not wrapped and everything
470 + # works as expected.
471 +
472 + if [[ ${MULTILIB_ABI_FLAG} ]]; then
473 + for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
474 + # drop leading slash if it's there
475 + f=${f#/}
476 +
477 + if [[ ${f} != usr/include/* ]]; then
478 + die "Wrapping headers outside of /usr/include is not supported at the moment."
479 + fi
480 + # and then usr/include
481 + f=${f#usr/include}
482 +
483 + local dir=${f%/*}
484 +
485 + # Some ABIs may have install less files than others.
486 + if [[ -f ${root}/usr/include${f} ]]; then
487 + local wrapper=${ED%/}/tmp/multilib-include${f}
488 +
489 + if [[ ! -f ${ED%/}/tmp/multilib-include${f} ]]; then
490 + dodir "/tmp/multilib-include${dir}"
491 + # a generic template
492 + cat > "${wrapper}" <<_EOF_ || die
493 +/* This file is auto-generated by multilib-build.eclass
494 + * as a multilib-friendly wrapper. For the original content,
495 + * please see the files that are #included below.
496 + */
497 +
498 +#if defined(__x86_64__) /* amd64 */
499 +# if defined(__ILP32__) /* x32 ABI */
500 +# error "abi_x86_x32 not supported by the package."
501 +# else /* 64-bit ABI */
502 +# error "abi_x86_64 not supported by the package."
503 +# endif
504 +#elif defined(__i386__) /* plain x86 */
505 +# error "abi_x86_32 not supported by the package."
506 +#elif defined(__mips__)
507 +# if(_MIPS_SIM == _ABIN32) /* n32 */
508 +# error "abi_mips_n32 not supported by the package."
509 +# elif(_MIPS_SIM == _ABI64) /* n64 */
510 +# error "abi_mips_n64 not supported by the package."
511 +# elif(_MIPS_SIM == _ABIO32) /* o32 */
512 +# error "abi_mips_o32 not supported by the package."
513 +# endif
514 +#elif defined(__riscv)
515 +# if defined(__riscv_float_abi_double)
516 +# error "abi_riscv_lp64d not supported by the package."
517 +# elif defined(__riscv_float_abi_single)
518 +# error "abi_riscv_lp64f not supported by the package."
519 +# else
520 +# error "abi_riscv_lp64 not supported by the package."
521 +# endif
522 +#elif defined(__sparc__)
523 +# if defined(__arch64__)
524 +# error "abi_sparc_64 not supported by the package."
525 +# else
526 +# error "abi_sparc_32 not supported by the package."
527 +# endif
528 +#elif defined(__s390__)
529 +# if defined(__s390x__)
530 +# error "abi_s390_64 not supported by the package."
531 +# else
532 +# error "abi_s390_32 not supported by the package."
533 +# endif
534 +#elif defined(__powerpc__) || defined(__ppc__)
535 +# if defined(__powerpc64__) || defined(__ppc64__)
536 +# error "abi_ppc_64 not supported by the package."
537 +# else
538 +# error "abi_ppc_32 not supported by the package."
539 +# endif
540 +#elif defined(SWIG) /* https://sourceforge.net/p/swig/bugs/799/ */
541 +# error "Native ABI not supported by the package."
542 +#else
543 +# error "No ABI matched, please report a bug to bugs.gentoo.org"
544 +#endif
545 +_EOF_
546 + fi
547 +
548 + if ! grep -q "${MULTILIB_ABI_FLAG} " "${wrapper}"
549 + then
550 + die "Flag ${MULTILIB_ABI_FLAG} not listed in wrapper template. Please report a bug to https://bugs.gentoo.org."
551 + fi
552 +
553 + # $CHOST shall be set by multilib_toolchain_setup
554 + dodir "/tmp/multilib-include/${CHOST}${dir}"
555 + mv "${root}/usr/include${f}" "${ED%/}/tmp/multilib-include/${CHOST}${dir}/" || die
556 +
557 + # Note: match a space afterwards to avoid collision potential.
558 + sed -e "/${MULTILIB_ABI_FLAG} /s&error.*&include <${CHOST}${f}>&" \
559 + -i "${wrapper}" || die
560 +
561 + # Needed for swig.
562 + if multilib_is_native_abi; then
563 + sed -e "/Native ABI/s&error.*&include <${CHOST}${f}>&" \
564 + -i "${wrapper}" || die
565 + fi
566 + fi
567 + done
568 + fi
569 + fi
570 +}
571 +
572 +# @FUNCTION: multilib_install_wrappers
573 +# @USAGE: [<install-root>]
574 +# @DESCRIPTION:
575 +# Install the previously-prepared wrappers. This function shall
576 +# be called once, after all wrappers were prepared.
577 +#
578 +# Takes an optional custom <install-root> to which the wrappers will be
579 +# installed. If no root is specified, uses ${ED}. There is no need to
580 +# use the same root as when preparing the wrappers.
581 +#
582 +# The files to be wrapped are specified using separate variables,
583 +# e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
584 +# between the calls to multilib_prepare_wrappers
585 +# and multilib_install_wrappers.
586 +multilib_install_wrappers() {
587 + debug-print-function ${FUNCNAME} "${@}"
588 +
589 + [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
590 +
591 + [[ ${COMPLETE_MULTILIB} == yes ]] && return
592 +
593 + local root=${1:-${ED}}
594 +
595 + if [[ -d ${ED%/}/tmp/multilib-include ]]; then
596 + multibuild_merge_root \
597 + "${ED%/}"/tmp/multilib-include "${root}"/usr/include
598 + # it can fail if something else uses /tmp
599 + rmdir "${ED%/}"/tmp &>/dev/null
600 + fi
601 +}
602 +
603 +# @FUNCTION: multilib_is_native_abi
604 +# @DESCRIPTION:
605 +# Determine whether the currently built ABI is the profile native.
606 +# Return true status (0) if that is true, otherwise false (1).
607 +multilib_is_native_abi() {
608 + debug-print-function ${FUNCNAME} "${@}"
609 +
610 + [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
611 +
612 + [[ ${COMPLETE_MULTILIB} == yes || ${ABI} == ${DEFAULT_ABI} ]]
613 +}
614 +
615 +# @FUNCTION: multilib_build_binaries
616 +# @DESCRIPTION:
617 +# Deprecated synonym for multilib_is_native_abi
618 +multilib_build_binaries() {
619 + debug-print-function ${FUNCNAME} "${@}"
620 +
621 + [[ ${EAPI} == [45] ]] || die "${FUNCNAME} is banned in EAPI ${EAPI}, use multilib_is_native_abi() instead"
622 +
623 + eqawarn "QA warning: multilib_build_binaries is deprecated. Please use the equivalent"
624 + eqawarn "multilib_is_native_abi function instead."
625 +
626 + multilib_is_native_abi "${@}"
627 +}
628 +
629 +# @FUNCTION: multilib_native_use_with
630 +# @USAGE: <flag> [<opt-name> [<opt-value>]]
631 +# @DESCRIPTION:
632 +# Output --with configure option alike use_with if USE <flag> is enabled
633 +# and executables are being built (multilib_is_native_abi is true).
634 +# Otherwise, outputs --without configure option. Arguments are the same
635 +# as for use_with in the EAPI.
636 +multilib_native_use_with() {
637 + if multilib_is_native_abi; then
638 + use_with "${@}"
639 + else
640 + echo "--without-${2:-${1}}"
641 + fi
642 +}
643 +
644 +# @FUNCTION: multilib_native_use_enable
645 +# @USAGE: <flag> [<opt-name> [<opt-value>]]
646 +# @DESCRIPTION:
647 +# Output --enable configure option alike use_enable if USE <flag>
648 +# is enabled and executables are being built (multilib_is_native_abi
649 +# is true). Otherwise, outputs --disable configure option. Arguments are
650 +# the same as for use_enable in the EAPI.
651 +multilib_native_use_enable() {
652 + if multilib_is_native_abi; then
653 + use_enable "${@}"
654 + else
655 + echo "--disable-${2:-${1}}"
656 + fi
657 +}
658 +
659 +# @FUNCTION: multilib_native_enable
660 +# @USAGE: <opt-name> [<opt-value>]
661 +# @DESCRIPTION:
662 +# Output --enable configure option if executables are being built
663 +# (multilib_is_native_abi is true). Otherwise, output --disable configure
664 +# option.
665 +multilib_native_enable() {
666 + if multilib_is_native_abi; then
667 + echo "--enable-${1}${2+=${2}}"
668 + else
669 + echo "--disable-${1}"
670 + fi
671 +}
672 +
673 +# @FUNCTION: multilib_native_with
674 +# @USAGE: <opt-name> [<opt-value>]
675 +# @DESCRIPTION:
676 +# Output --with configure option if executables are being built
677 +# (multilib_is_native_abi is true). Otherwise, output --without configure
678 +# option.
679 +multilib_native_with() {
680 + if multilib_is_native_abi; then
681 + echo "--with-${1}${2+=${2}}"
682 + else
683 + echo "--without-${1}"
684 + fi
685 +}
686 +
687 +# @FUNCTION: multilib_native_usex
688 +# @USAGE: <flag> [<true1> [<false1> [<true2> [<false2>]]]]
689 +# @DESCRIPTION:
690 +# Output the concatenation of <true1> (or 'yes' if unspecified)
691 +# and <true2> if USE <flag> is enabled and executables are being built
692 +# (multilib_is_native_abi is true). Otherwise, output the concatenation
693 +# of <false1> (or 'no' if unspecified) and <false2>. Arguments
694 +# are the same as for usex in the EAPI.
695 +#
696 +# Note: in EAPI 4 you need to inherit eutils to use this function.
697 +multilib_native_usex() {
698 + if multilib_is_native_abi; then
699 + usex "${@}"
700 + else
701 + echo "${3-no}${5}"
702 + fi
703 +}
704 +
705 +_MULTILIB_BUILD=1
706 +fi