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