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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.44 - (hide annotations) (download)
Tue Apr 29 20:59:00 2014 UTC (7 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.43: +28 -28 lines
Reorder the operations in multilib_prepare_wrappers for easier reading.

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

  ViewVC Help
Powered by ViewVC 1.1.20