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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.48 - (show annotations) (download)
Mon May 12 21:56:17 2014 UTC (2 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.47: +8 -8 lines
Do not install wrapper headers when no ABI provides a particular header.

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

  ViewVC Help
Powered by ViewVC 1.1.20