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

Diff of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.31

  ViewVC Help
Powered by ViewVC 1.1.20