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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations) (download)
Mon Sep 30 07:27:06 2013 UTC (10 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.20: +15 -11 lines
Fix duplicate flags in MULTILIB_USEDEP. Thanks for the report and the patch to Ulrich Mueller.

1 # Copyright 1999-2013 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/multilib-build.eclass,v 1.20 2013/09/17 13:29:19 tommy Exp $
4
5 # @ECLASS: multilib-build.eclass
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # @BLURB: flags and utility functions for building multilib packages
9 # @DESCRIPTION:
10 # The multilib-build.eclass exports USE flags and utility functions
11 # necessary to build packages for multilib in a clean and uniform
12 # manner.
13 #
14 # Please note that dependency specifications for multilib-capable
15 # dependencies shall use the USE dependency string in ${MULTILIB_USEDEP}
16 # to properly request multilib enabled.
17
18 if [[ ! ${_MULTILIB_BUILD} ]]; then
19
20 # EAPI=4 is required for meaningful MULTILIB_USEDEP.
21 case ${EAPI:-0} in
22 4|5) ;;
23 *) die "EAPI=${EAPI} is not supported" ;;
24 esac
25
26 inherit multibuild multilib
27
28 # @ECLASS-VARIABLE: _MULTILIB_FLAGS
29 # @INTERNAL
30 # @DESCRIPTION:
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.
34 _MULTILIB_FLAGS=(
35 abi_x86_32:x86,x86_fbsd
36 abi_x86_64:amd64,amd64_fbsd
37 abi_x86_x32:x32
38 abi_mips_n32:n32
39 abi_mips_n64:n64
40 abi_mips_o32:o32
41 )
42
43 # @ECLASS-VARIABLE: MULTILIB_USEDEP
44 # @DESCRIPTION:
45 # The USE-dependency to be used on dependencies (libraries) needing
46 # to support multilib as well.
47 #
48 # Example use:
49 # @CODE
50 # RDEPEND="dev-libs/libfoo[${MULTILIB_USEDEP}]
51 # net-libs/libbar[ssl,${MULTILIB_USEDEP}]"
52 # @CODE
53
54 _multilib_build_set_globals() {
55 local flags=( "${_MULTILIB_FLAGS[@]%:*}" )
56 local usedeps=${flags[@]/%/(-)?}
57
58 IUSE=${flags[*]}
59 MULTILIB_USEDEP=${usedeps// /,}
60 }
61 _multilib_build_set_globals
62
63 # @FUNCTION: multilib_get_enabled_abis
64 # @DESCRIPTION:
65 # Return the ordered list of enabled ABIs if multilib builds
66 # are enabled. The best (most preferred) ABI will come last.
67 #
68 # If multilib is disabled, the default ABI will be returned
69 # in order to enforce consistent testing with multilib code.
70 multilib_get_enabled_abis() {
71 debug-print-function ${FUNCNAME} "${@}"
72
73 local abis=( $(get_all_abis) )
74
75 local IFS=,
76 local abi i found
77 for abi in "${abis[@]}"; do
78 for i in "${_MULTILIB_FLAGS[@]}"; do
79 local m_abis=${i#*:} m_abi
80 local m_flag=${i%:*}
81
82 for m_abi in ${m_abis}; do
83 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then
84 echo "${abi}"
85 found=1
86 break 2
87 fi
88 done
89 done
90 done
91
92 if [[ ! ${found} ]]; then
93 # ${ABI} can be used to override the fallback (multilib-portage),
94 # ${DEFAULT_ABI} is the safe fallback.
95 local abi=${ABI:-${DEFAULT_ABI}}
96
97 debug-print "${FUNCNAME}: no ABIs enabled, fallback to ${abi}"
98 debug-print "${FUNCNAME}: ABI=${ABI}, DEFAULT_ABI=${DEFAULT_ABI}"
99 echo ${abi}
100 fi
101 }
102
103 # @FUNCTION: _multilib_multibuild_wrapper
104 # @USAGE: <argv>...
105 # @INTERNAL
106 # @DESCRIPTION:
107 # Initialize the environment for ABI selected for multibuild.
108 _multilib_multibuild_wrapper() {
109 debug-print-function ${FUNCNAME} "${@}"
110
111 local ABI=${MULTIBUILD_VARIANT}
112 multilib_toolchain_setup "${ABI}"
113 "${@}"
114 }
115
116 # @FUNCTION: multilib_foreach_abi
117 # @USAGE: <argv>...
118 # @DESCRIPTION:
119 # If multilib support is enabled, sets the toolchain up for each
120 # supported ABI along with the ABI variable and correct BUILD_DIR,
121 # and runs the given commands with them.
122 #
123 # If multilib support is disabled, it just runs the commands. No setup
124 # is done.
125 multilib_foreach_abi() {
126 debug-print-function ${FUNCNAME} "${@}"
127
128 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
129 multibuild_foreach_variant _multilib_multibuild_wrapper "${@}"
130 }
131
132 # @FUNCTION: multilib_parallel_foreach_abi
133 # @USAGE: <argv>...
134 # @DESCRIPTION:
135 # If multilib support is enabled, sets the toolchain up for each
136 # supported ABI along with the ABI variable and correct BUILD_DIR,
137 # and runs the given commands with them. The commands are run
138 # in parallel with number of jobs being determined from MAKEOPTS.
139 #
140 # If multilib support is disabled, it just runs the commands. No setup
141 # is done.
142 #
143 # Useful for running configure scripts.
144 multilib_parallel_foreach_abi() {
145 debug-print-function ${FUNCNAME} "${@}"
146
147 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
148 multibuild_parallel_foreach_variant _multilib_multibuild_wrapper "${@}"
149 }
150
151 # @FUNCTION: multilib_for_best_abi
152 # @USAGE: <argv>...
153 # @DESCRIPTION:
154 # Runs the given command with setup for the 'best' (usually native) ABI.
155 multilib_for_best_abi() {
156 debug-print-function ${FUNCNAME} "${@}"
157
158 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
159
160 multibuild_for_best_variant _multilib_multibuild_wrapper "${@}"
161 }
162
163 # @FUNCTION: multilib_check_headers
164 # @DESCRIPTION:
165 # Check whether the header files are consistent between ABIs.
166 #
167 # This function needs to be called after each ABI's installation phase.
168 # It obtains the header file checksums and compares them with previous
169 # runs (if any). Dies if header files differ.
170 multilib_check_headers() {
171 _multilib_header_cksum() {
172 [[ -d ${ED}usr/include ]] && \
173 find "${ED}"usr/include -type f \
174 -exec cksum {} + | sort -k2
175 }
176
177 local cksum=$(_multilib_header_cksum)
178 local cksum_file=${T}/.multilib_header_cksum
179
180 if [[ -f ${cksum_file} ]]; then
181 local cksum_prev=$(< "${cksum_file}")
182
183 if [[ ${cksum} != ${cksum_prev} ]]; then
184 echo "${cksum}" > "${cksum_file}.new"
185
186 eerror "Header files have changed between ABIs."
187
188 if type -p diff &>/dev/null; then
189 eerror "$(diff -du "${cksum_file}" "${cksum_file}.new")"
190 else
191 eerror "Old checksums in: ${cksum_file}"
192 eerror "New checksums in: ${cksum_file}.new"
193 fi
194
195 die "Header checksum mismatch, aborting."
196 fi
197 else
198 echo "${cksum}" > "${cksum_file}"
199 fi
200 }
201
202 # @FUNCTION: multilib_copy_sources
203 # @DESCRIPTION:
204 # Create a single copy of the package sources for each enabled ABI.
205 #
206 # The sources are always copied from initial BUILD_DIR (or S if unset)
207 # to ABI-specific build directory matching BUILD_DIR used by
208 # multilib_foreach_abi().
209 multilib_copy_sources() {
210 debug-print-function ${FUNCNAME} "${@}"
211
212 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
213 multibuild_copy_sources
214 }
215
216 # @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
217 # @DESCRIPTION:
218 # A list of headers to wrap for multilib support. The listed headers
219 # will be moved to a non-standard location and replaced with a file
220 # including them conditionally to current ABI.
221 #
222 # This variable has to be a bash array. Paths shall be relative to
223 # installation root (${ED}), and name regular files. Recursive wrapping
224 # is not supported.
225 #
226 # Please note that header wrapping is *discouraged*. It is preferred to
227 # install all headers in a subdirectory of libdir and use pkg-config to
228 # locate the headers. Some C preprocessors will not work with wrapped
229 # headers.
230 #
231 # Example:
232 # @CODE
233 # MULTILIB_WRAPPED_HEADERS=(
234 # /usr/include/foobar/config.h
235 # )
236 # @CODE
237
238 # @FUNCTION: multilib_prepare_wrappers
239 # @USAGE: [<install-root>]
240 # @DESCRIPTION:
241 # Perform the preparation of all kinds of wrappers for the current ABI.
242 # This function shall be called once per each ABI, after installing
243 # the files to be wrapped.
244 #
245 # Takes an optional custom <install-root> from which files will be
246 # used. If no root is specified, uses ${ED}.
247 #
248 # The files to be wrapped are specified using separate variables,
249 # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
250 # between the successive calls to multilib_prepare_wrappers
251 # and multilib_install_wrappers.
252 #
253 # After all wrappers are prepared, multilib_install_wrappers shall
254 # be called to commit them to the installation tree.
255 multilib_prepare_wrappers() {
256 debug-print-function ${FUNCNAME} "${@}"
257
258 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
259
260 local root=${1:-${ED}}
261 local f
262
263 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
264 # drop leading slash if it's there
265 f=${f#/}
266
267 if [[ ${f} != usr/include/* ]]; then
268 die "Wrapping headers outside of /usr/include is not supported at the moment."
269 fi
270 # and then usr/include
271 f=${f#usr/include}
272
273 local dir=${f%/*}
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 # Some ABIs may have install less files than others.
307 if [[ -f ${root}/usr/include${f} ]]; then
308 # $CHOST shall be set by multilib_toolchain_setup
309 dodir "/tmp/multilib-include/${CHOST}${dir}"
310 mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
311
312 # XXX: get abi_* directly
313 local abi_flag
314 case "${ABI}" in
315 amd64|amd64_fbsd)
316 abi_flag=abi_x86_64;;
317 x86|x86_fbsd)
318 abi_flag=abi_x86_32;;
319 x32)
320 abi_flag=abi_x86_x32;;
321 n32)
322 abi_flag=abi_mips_n32;;
323 n64)
324 abi_flag=abi_mips_n64;;
325 o32)
326 abi_flag=abi_mips_o32;;
327 *)
328 die "Header wrapping for ${ABI} not supported yet";;
329 esac
330
331 # Note: match a space afterwards to avoid collision potential.
332 sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
333 -i "${ED}/tmp/multilib-include${f}" || die
334 fi
335 done
336 }
337
338 # @FUNCTION: multilib_install_wrappers
339 # @USAGE: [<install-root>]
340 # @DESCRIPTION:
341 # Install the previously-prepared wrappers. This function shall
342 # be called once, after all wrappers were prepared.
343 #
344 # Takes an optional custom <install-root> to which the wrappers will be
345 # installed. If no root is specified, uses ${ED}. There is no need to
346 # use the same root as when preparing the wrappers.
347 #
348 # The files to be wrapped are specified using separate variables,
349 # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
350 # between the calls to multilib_prepare_wrappers
351 # and multilib_install_wrappers.
352 multilib_install_wrappers() {
353 debug-print-function ${FUNCNAME} "${@}"
354
355 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
356
357 local root=${1:-${ED}}
358
359 if [[ -d "${ED}"/tmp/multilib-include ]]; then
360 multibuild_merge_root \
361 "${ED}"/tmp/multilib-include "${root}"/usr/include
362 # it can fail if something else uses /tmp
363 rmdir "${ED}"/tmp &>/dev/null
364 fi
365 }
366
367 # @FUNCTION: multilib_is_native_abi
368 # @DESCRIPTION:
369 # Determine whether the currently built ABI is the profile native.
370 # Return true status (0) if that is true, otherwise false (1).
371 #
372 # This is often useful for configure calls when some of the options are
373 # supposed to be disabled for multilib ABIs (like those used for
374 # executables only).
375 multilib_is_native_abi() {
376 debug-print-function ${FUNCNAME} "${@}"
377
378 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
379
380 [[ ${ABI} == ${DEFAULT_ABI} ]]
381 }
382
383 # @FUNCTION: multilib_build_binaries
384 # @DESCRIPTION:
385 # Determine wheter to build binaries for the current build ABI.
386 # Returns true status (0) if the current built ABI is the profile
387 # native or COMPLETE_MULTILIB variable is set to yes, otherwise
388 # false (1).
389 #
390 # The COMPLETE_MULTILIB variable can be set by users or profiles
391 # when they want to build binaries for none-default ABI so e.g.
392 # 32bit binaries on amd64.
393 multilib_build_binaries() {
394 debug-print-function ${FUNCNAME} "${@}"
395
396 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
397
398 [[ ${COMPLETE_MULTILIB} == yes ]] || multilib_is_native_abi
399 }
400
401 _MULTILIB_BUILD=1
402 fi

  ViewVC Help
Powered by ViewVC 1.1.20