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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.33 - (hide annotations) (download)
Thu Apr 3 21:38:08 2014 UTC (3 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.32: +5 -1 lines
Add a note not to add new ABIs without contacting multilib.

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

  ViewVC Help
Powered by ViewVC 1.1.20