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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.50 - (show annotations) (download)
Fri May 23 07:38:36 2014 UTC (5 months, 4 weeks ago) by mgorny
Branch: MAIN
Changes since 1.49: +26 -6 lines
Export MULTILIB_ABI_FLAG for ebuild/eclass use. Bug #509478.

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

  ViewVC Help
Powered by ViewVC 1.1.20