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

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

  ViewVC Help
Powered by ViewVC 1.1.20