/[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.24
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2013 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.24 2013/12/28 18:23:25 jlec 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
36) 41)
37 42
38# @ECLASS-VARIABLE: MULTILIB_USEDEP 43# @ECLASS-VARIABLE: MULTILIB_USEDEP
39# @DESCRIPTION: 44# @DESCRIPTION:
40# The USE-dependency to be used on dependencies (libraries) needing 45# The USE-dependency to be used on dependencies (libraries) needing
68 local abis=( $(get_all_abis) ) 73 local abis=( $(get_all_abis) )
69 74
70 local abi i found 75 local abi i found
71 for abi in "${abis[@]}"; do 76 for abi in "${abis[@]}"; do
72 for i in "${_MULTILIB_FLAGS[@]}"; do 77 for i in "${_MULTILIB_FLAGS[@]}"; do
73 local m_abi=${i#*:} 78 local m_abis=${i#*:} m_abi
74 local m_flag=${i%:*} 79 local m_flag=${i%:*}
75 80
81 # split on ,; we can't switch IFS for function scope because
82 # paludis is broken (bug #486592), and switching it locally
83 # for the split is more complex than cheating like this
84 for m_abi in ${m_abis//,/ }; do
76 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then 85 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then
77 echo "${abi}" 86 echo "${abi}"
78 found=1 87 found=1
88 break 2
79 fi 89 fi
90 done
80 done 91 done
81 done 92 done
82 93
83 if [[ ! ${found} ]]; then 94 if [[ ! ${found} ]]; then
95 # ${ABI} can be used to override the fallback (multilib-portage),
96 # ${DEFAULT_ABI} is the safe fallback.
97 local abi=${ABI:-${DEFAULT_ABI}}
98
84 debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${DEFAULT_ABI}" 99 debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}"
85 echo ${DEFAULT_ABI} 100 debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}"
101 echo ${abi}
86 fi 102 fi
103}
104
105# @FUNCTION: _multilib_multibuild_wrapper
106# @USAGE: <argv>...
107# @INTERNAL
108# @DESCRIPTION:
109# Initialize the environment for ABI selected for multibuild.
110_multilib_multibuild_wrapper() {
111 debug-print-function ${FUNCNAME} "${@}"
112
113 local ABI=${MULTIBUILD_VARIANT}
114 multilib_toolchain_setup "${ABI}"
115 "${@}"
87} 116}
88 117
89# @FUNCTION: multilib_foreach_abi 118# @FUNCTION: multilib_foreach_abi
90# @USAGE: <argv>... 119# @USAGE: <argv>...
91# @DESCRIPTION: 120# @DESCRIPTION:
94# and runs the given commands with them. 123# and runs the given commands with them.
95# 124#
96# If multilib support is disabled, it just runs the commands. No setup 125# If multilib support is disabled, it just runs the commands. No setup
97# is done. 126# is done.
98multilib_foreach_abi() { 127multilib_foreach_abi() {
99 local initial_dir=${BUILD_DIR:-${S}} 128 debug-print-function ${FUNCNAME} "${@}"
100 129
101 local ABI 130 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
102 for ABI in $(multilib_get_enabled_abis); do 131 multibuild_foreach_variant _multilib_multibuild_wrapper "${@}"
103 multilib_toolchain_setup "${ABI}"
104 BUILD_DIR=${initial_dir%%/}-${ABI} "${@}"
105 done
106} 132}
107 133
108# @FUNCTION: multilib_parallel_foreach_abi 134# @FUNCTION: multilib_parallel_foreach_abi
109# @USAGE: <argv>... 135# @USAGE: <argv>...
110# @DESCRIPTION: 136# @DESCRIPTION:
116# If multilib support is disabled, it just runs the commands. No setup 142# If multilib support is disabled, it just runs the commands. No setup
117# is done. 143# is done.
118# 144#
119# Useful for running configure scripts. 145# Useful for running configure scripts.
120multilib_parallel_foreach_abi() { 146multilib_parallel_foreach_abi() {
121 local initial_dir=${BUILD_DIR:-${S}} 147 debug-print-function ${FUNCNAME} "${@}"
122 148
123 multijob_init 149 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
150 multibuild_parallel_foreach_variant _multilib_multibuild_wrapper "${@}"
151}
124 152
125 local ABI 153# @FUNCTION: multilib_for_best_abi
126 for ABI in $(multilib_get_enabled_abis); do 154# @USAGE: <argv>...
127 ( 155# @DESCRIPTION:
128 multijob_child_init 156# Runs the given command with setup for the 'best' (usually native) ABI.
157multilib_for_best_abi() {
158 debug-print-function ${FUNCNAME} "${@}"
129 159
130 multilib_toolchain_setup "${ABI}" 160 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
131 BUILD_DIR=${initial_dir%%/}-${ABI}
132 "${@}"
133 ) &
134 161
135 multijob_post_fork 162 multibuild_for_best_variant _multilib_multibuild_wrapper "${@}"
136 done
137
138 multijob_finish
139} 163}
140 164
141# @FUNCTION: multilib_check_headers 165# @FUNCTION: multilib_check_headers
142# @DESCRIPTION: 166# @DESCRIPTION:
143# Check whether the header files are consistent between ABIs. 167# Check whether the header files are consistent between ABIs.
175 else 199 else
176 echo "${cksum}" > "${cksum_file}" 200 echo "${cksum}" > "${cksum_file}"
177 fi 201 fi
178} 202}
179 203
204# @FUNCTION: multilib_copy_sources
205# @DESCRIPTION:
206# Create a single copy of the package sources for each enabled ABI.
207#
208# The sources are always copied from initial BUILD_DIR (or S if unset)
209# to ABI-specific build directory matching BUILD_DIR used by
210# multilib_foreach_abi().
211multilib_copy_sources() {
212 debug-print-function ${FUNCNAME} "${@}"
213
214 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
215 multibuild_copy_sources
216}
217
218# @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
219# @DESCRIPTION:
220# A list of headers to wrap for multilib support. The listed headers
221# will be moved to a non-standard location and replaced with a file
222# including them conditionally to current ABI.
223#
224# This variable has to be a bash array. Paths shall be relative to
225# installation root (${ED}), and name regular files. Recursive wrapping
226# is not supported.
227#
228# Please note that header wrapping is *discouraged*. It is preferred to
229# install all headers in a subdirectory of libdir and use pkg-config to
230# locate the headers. Some C preprocessors will not work with wrapped
231# headers.
232#
233# Example:
234# @CODE
235# MULTILIB_WRAPPED_HEADERS=(
236# /usr/include/foobar/config.h
237# )
238# @CODE
239
240# @FUNCTION: multilib_prepare_wrappers
241# @USAGE: [<install-root>]
242# @DESCRIPTION:
243# Perform the preparation of all kinds of wrappers for the current ABI.
244# This function shall be called once per each ABI, after installing
245# the files to be wrapped.
246#
247# Takes an optional custom <install-root> from which files will be
248# used. If no root is specified, uses ${ED}.
249#
250# The files to be wrapped are specified using separate variables,
251# e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
252# between the successive calls to multilib_prepare_wrappers
253# and multilib_install_wrappers.
254#
255# After all wrappers are prepared, multilib_install_wrappers shall
256# be called to commit them to the installation tree.
257multilib_prepare_wrappers() {
258 debug-print-function ${FUNCNAME} "${@}"
259
260 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
261
262 local root=${1:-${ED}}
263 local f
264
265 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
266 # drop leading slash if it's there
267 f=${f#/}
268
269 if [[ ${f} != usr/include/* ]]; then
270 die "Wrapping headers outside of /usr/include is not supported at the moment."
271 fi
272 # and then usr/include
273 f=${f#usr/include}
274
275 local dir=${f%/*}
276
277 if [[ ! -f ${ED}/tmp/multilib-include${f} ]]; then
278 dodir "/tmp/multilib-include${dir}"
279 # a generic template
280 cat > "${ED}/tmp/multilib-include${f}" <<_EOF_
281/* This file is auto-generated by multilib-build.eclass
282 * as a multilib-friendly wrapper. For the original content,
283 * please see the files that are #included below.
284 */
285
286#if defined(__x86_64__) /* amd64 */
287# if defined(__ILP32__) /* x32 ABI */
288# error "abi_x86_x32 not supported by the package."
289# else /* 64-bit ABI */
290# error "abi_x86_64 not supported by the package."
291# endif
292#elif defined(__i386__) /* plain x86 */
293# error "abi_x86_32 not supported by the package."
294#elif defined(__mips__)
295# if(_MIPS_SIM == _ABIN32) /* n32 */
296# error "abi_mips_n32 not supported by the package."
297# elif(_MIPS_SIM == _ABI64) /* n64 */
298# error "abi_mips_n64 not supported by the package."
299# elif(_MIPS_SIM == _ABIO32) /* o32 */
300# error "abi_mips_o32 not supported by the package."
301# endif
302#else
303# error "No ABI matched, please report a bug to bugs.gentoo.org"
304#endif
305_EOF_
306 fi
307
308 # Some ABIs may have install less files than others.
309 if [[ -f ${root}/usr/include${f} ]]; then
310 # $CHOST shall be set by multilib_toolchain_setup
311 dodir "/tmp/multilib-include/${CHOST}${dir}"
312 mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
313
314 # XXX: get abi_* directly
315 local abi_flag
316 case "${ABI}" in
317 amd64|amd64_fbsd)
318 abi_flag=abi_x86_64;;
319 x86|x86_fbsd)
320 abi_flag=abi_x86_32;;
321 x32)
322 abi_flag=abi_x86_x32;;
323 n32)
324 abi_flag=abi_mips_n32;;
325 n64)
326 abi_flag=abi_mips_n64;;
327 o32)
328 abi_flag=abi_mips_o32;;
329 *)
330 die "Header wrapping for ${ABI} not supported yet";;
331 esac
332
333 # Note: match a space afterwards to avoid collision potential.
334 sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
335 -i "${ED}/tmp/multilib-include${f}" || die
336 fi
337 done
338}
339
340# @FUNCTION: multilib_install_wrappers
341# @USAGE: [<install-root>]
342# @DESCRIPTION:
343# Install the previously-prepared wrappers. This function shall
344# be called once, after all wrappers were prepared.
345#
346# Takes an optional custom <install-root> to which the wrappers will be
347# installed. If no root is specified, uses ${ED}. There is no need to
348# use the same root as when preparing the wrappers.
349#
350# The files to be wrapped are specified using separate variables,
351# e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
352# between the calls to multilib_prepare_wrappers
353# and multilib_install_wrappers.
354multilib_install_wrappers() {
355 debug-print-function ${FUNCNAME} "${@}"
356
357 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
358
359 local root=${1:-${ED}}
360
361 if [[ -d "${ED}"/tmp/multilib-include ]]; then
362 multibuild_merge_root \
363 "${ED}"/tmp/multilib-include "${root}"/usr/include
364 # it can fail if something else uses /tmp
365 rmdir "${ED}"/tmp &>/dev/null
366 fi
367}
368
369# @FUNCTION: multilib_is_native_abi
370# @DESCRIPTION:
371# Determine whether the currently built ABI is the profile native.
372# Return true status (0) if that is true, otherwise false (1).
373#
374# This is often useful for configure calls when some of the options are
375# supposed to be disabled for multilib ABIs (like those used for
376# executables only).
377multilib_is_native_abi() {
378 debug-print-function ${FUNCNAME} "${@}"
379
380 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
381
382 [[ ${ABI} == ${DEFAULT_ABI} ]]
383}
384
385# @FUNCTION: multilib_build_binaries
386# @DESCRIPTION:
387# Determine whether to build binaries for the current build ABI.
388# Returns true status (0) if the current built ABI is the profile
389# native or COMPLETE_MULTILIB variable is set to yes, otherwise
390# false (1).
391#
392# The COMPLETE_MULTILIB variable can be set by users or profiles
393# when they want to build binaries for none-default ABI so e.g.
394# 32bit binaries on amd64.
395multilib_build_binaries() {
396 debug-print-function ${FUNCNAME} "${@}"
397
398 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
399
400 [[ ${COMPLETE_MULTILIB} == yes ]] || multilib_is_native_abi
401}
402
180_MULTILIB_BUILD=1 403_MULTILIB_BUILD=1
181fi 404fi

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

  ViewVC Help
Powered by ViewVC 1.1.20