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