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

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

  ViewVC Help
Powered by ViewVC 1.1.20