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

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

  ViewVC Help
Powered by ViewVC 1.1.20