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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.22 - (show annotations) (download)
Tue Oct 1 17:42:38 2013 UTC (14 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.21: +7 -3 lines
Split ABIs without altering IFS, to work-around bug in Paludis, bug #486592.

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

  ViewVC Help
Powered by ViewVC 1.1.20