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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.29 - (show annotations) (download)
Sun Mar 30 08:41:53 2014 UTC (3 months, 3 weeks ago) by mgorny
Branch: MAIN
Changes since 1.28: +20 -3 lines
Support rewriting symlinks in MULTILIB_CHOST_TOOLS, bug #506062.

1 # Copyright 1999-2014 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.28 2014/03/29 03:00:44 vapier 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 abi_ppc_32:ppc
42 abi_ppc_64:ppc64
43 )
44
45 # @ECLASS-VARIABLE: MULTILIB_USEDEP
46 # @DESCRIPTION:
47 # The USE-dependency to be used on dependencies (libraries) needing
48 # to support multilib as well.
49 #
50 # Example use:
51 # @CODE
52 # RDEPEND="dev-libs/libfoo[${MULTILIB_USEDEP}]
53 # net-libs/libbar[ssl,${MULTILIB_USEDEP}]"
54 # @CODE
55
56 _multilib_build_set_globals() {
57 local flags=( "${_MULTILIB_FLAGS[@]%:*}" )
58 local usedeps=${flags[@]/%/(-)?}
59
60 IUSE=${flags[*]}
61 MULTILIB_USEDEP=${usedeps// /,}
62 }
63 _multilib_build_set_globals
64
65 # @FUNCTION: multilib_get_enabled_abis
66 # @DESCRIPTION:
67 # Return the ordered list of enabled ABIs if multilib builds
68 # are enabled. The best (most preferred) ABI will come last.
69 #
70 # If multilib is disabled, the default ABI will be returned
71 # in order to enforce consistent testing with multilib code.
72 multilib_get_enabled_abis() {
73 debug-print-function ${FUNCNAME} "${@}"
74
75 local abis=( $(get_all_abis) )
76
77 local abi i found
78 for abi in "${abis[@]}"; do
79 for i in "${_MULTILIB_FLAGS[@]}"; do
80 local m_abis=${i#*:} m_abi
81 local m_flag=${i%:*}
82
83 # split on ,; we can't switch IFS for function scope because
84 # paludis is broken (bug #486592), and switching it locally
85 # for the split is more complex than cheating like this
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 # @ECLASS-VARIABLE: MULTILIB_CHOST_TOOLS
243 # @DESCRIPTION:
244 # A list of tool executables to preserve for each multilib ABI.
245 # The listed executables will be renamed to ${CHOST}-${basename},
246 # and the native variant will be symlinked to the generic name.
247 #
248 # This variable has to be a bash array. Paths shall be relative to
249 # installation root (${ED}), and name regular files or symbolic
250 # links to regular files. Recursive wrapping is not supported.
251 #
252 # If symbolic link is passed, both symlink path and symlink target
253 # will be changed. As a result, the symlink target is expected
254 # to be wrapped as well (either by listing in MULTILIB_CHOST_TOOLS
255 # or externally).
256 #
257 # Please note that tool wrapping is *discouraged*. It is preferred to
258 # install pkg-config files for each ABI, and require reverse
259 # dependencies to use that.
260 #
261 # Packages that search for tools properly (e.g. using AC_PATH_TOOL
262 # macro) will find the wrapper executables automatically. Other packages
263 # will need explicit override of tool paths.
264 #
265 # Example:
266 # @CODE
267 # MULTILIB_CHOST_TOOLS=(
268 # /usr/bin/foo-config
269 # )
270
271 # @CODE
272 # @FUNCTION: multilib_prepare_wrappers
273 # @USAGE: [<install-root>]
274 # @DESCRIPTION:
275 # Perform the preparation of all kinds of wrappers for the current ABI.
276 # This function shall be called once per each ABI, after installing
277 # the files to be wrapped.
278 #
279 # Takes an optional custom <install-root> from which files will be
280 # used. If no root is specified, uses ${ED}.
281 #
282 # The files to be wrapped are specified using separate variables,
283 # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
284 # between the successive calls to multilib_prepare_wrappers
285 # and multilib_install_wrappers.
286 #
287 # After all wrappers are prepared, multilib_install_wrappers shall
288 # be called to commit them to the installation tree.
289 multilib_prepare_wrappers() {
290 debug-print-function ${FUNCNAME} "${@}"
291
292 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
293
294 local root=${1:-${ED}}
295 local f
296
297 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
298 # drop leading slash if it's there
299 f=${f#/}
300
301 if [[ ${f} != usr/include/* ]]; then
302 die "Wrapping headers outside of /usr/include is not supported at the moment."
303 fi
304 # and then usr/include
305 f=${f#usr/include}
306
307 local dir=${f%/*}
308
309 if [[ ! -f ${ED}/tmp/multilib-include${f} ]]; then
310 dodir "/tmp/multilib-include${dir}"
311 # a generic template
312 cat > "${ED}/tmp/multilib-include${f}" <<_EOF_
313 /* This file is auto-generated by multilib-build.eclass
314 * as a multilib-friendly wrapper. For the original content,
315 * please see the files that are #included below.
316 */
317
318 #if defined(__x86_64__) /* amd64 */
319 # if defined(__ILP32__) /* x32 ABI */
320 # error "abi_x86_x32 not supported by the package."
321 # else /* 64-bit ABI */
322 # error "abi_x86_64 not supported by the package."
323 # endif
324 #elif defined(__i386__) /* plain x86 */
325 # error "abi_x86_32 not supported by the package."
326 #elif defined(__mips__)
327 # if(_MIPS_SIM == _ABIN32) /* n32 */
328 # error "abi_mips_n32 not supported by the package."
329 # elif(_MIPS_SIM == _ABI64) /* n64 */
330 # error "abi_mips_n64 not supported by the package."
331 # elif(_MIPS_SIM == _ABIO32) /* o32 */
332 # error "abi_mips_o32 not supported by the package."
333 # endif
334 #else
335 # error "No ABI matched, please report a bug to bugs.gentoo.org"
336 #endif
337 _EOF_
338 fi
339
340 # Some ABIs may have install less files than others.
341 if [[ -f ${root}/usr/include${f} ]]; then
342 # $CHOST shall be set by multilib_toolchain_setup
343 dodir "/tmp/multilib-include/${CHOST}${dir}"
344 mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
345
346 # XXX: get abi_* directly
347 local abi_flag
348 case "${ABI}" in
349 amd64|amd64_fbsd)
350 abi_flag=abi_x86_64;;
351 x86|x86_fbsd)
352 abi_flag=abi_x86_32;;
353 x32)
354 abi_flag=abi_x86_x32;;
355 n32)
356 abi_flag=abi_mips_n32;;
357 n64)
358 abi_flag=abi_mips_n64;;
359 o32)
360 abi_flag=abi_mips_o32;;
361 ppc)
362 abi_flag=abi_ppc_32;;
363 ppc64)
364 abi_flag=abi_ppc_64;;
365 *)
366 die "Header wrapping for ${ABI} not supported yet";;
367 esac
368
369 # Note: match a space afterwards to avoid collision potential.
370 sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
371 -i "${ED}/tmp/multilib-include${f}" || die
372 fi
373 done
374
375 for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
376 # drop leading slash if it's there
377 f=${f#/}
378
379 local dir=${f%/*}
380 local fn=${f##*/}
381
382 if [[ -L ${root}/${f} ]]; then
383 # rewrite the symlink target
384 local target=$(readlink "${root}/${f}")
385 local target_dir
386 local target_fn=${target##*/}
387
388 [[ ${target} == */* ]] && target_dir=${target%/*}
389
390 ln -f -s "${target_dir+${target_dir}/}${CHOST}-${target_fn}" \
391 "${root}/${f}" || die
392 fi
393
394 mv "${root}/${f}" "${root}/${dir}/${CHOST}-${fn}" || die
395
396 # symlink the native one back
397 if multilib_build_binaries; then
398 ln -s "${CHOST}-${fn}" "${root}/${f}" || die
399 fi
400 done
401 }
402
403 # @FUNCTION: multilib_install_wrappers
404 # @USAGE: [<install-root>]
405 # @DESCRIPTION:
406 # Install the previously-prepared wrappers. This function shall
407 # be called once, after all wrappers were prepared.
408 #
409 # Takes an optional custom <install-root> to which the wrappers will be
410 # installed. If no root is specified, uses ${ED}. There is no need to
411 # use the same root as when preparing the wrappers.
412 #
413 # The files to be wrapped are specified using separate variables,
414 # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
415 # between the calls to multilib_prepare_wrappers
416 # and multilib_install_wrappers.
417 multilib_install_wrappers() {
418 debug-print-function ${FUNCNAME} "${@}"
419
420 [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
421
422 local root=${1:-${ED}}
423
424 if [[ -d "${ED}"/tmp/multilib-include ]]; then
425 multibuild_merge_root \
426 "${ED}"/tmp/multilib-include "${root}"/usr/include
427 # it can fail if something else uses /tmp
428 rmdir "${ED}"/tmp &>/dev/null
429 fi
430 }
431
432 # @FUNCTION: multilib_is_native_abi
433 # @DESCRIPTION:
434 # Determine whether the currently built ABI is the profile native.
435 # Return true status (0) if that is true, otherwise false (1).
436 #
437 # This function is not intended to be used directly. Please use
438 # multilib_build_binaries instead.
439 multilib_is_native_abi() {
440 debug-print-function ${FUNCNAME} "${@}"
441
442 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
443
444 [[ ${ABI} == ${DEFAULT_ABI} ]]
445 }
446
447 # @FUNCTION: multilib_build_binaries
448 # @DESCRIPTION:
449 # Determine whether to build binaries for the currently built ABI.
450 # Returns true status (0) if the currently built ABI is the profile
451 # native or COMPLETE_MULTILIB variable is set to 'yes', otherwise
452 # false (1).
453 #
454 # This is often useful for configure calls when some of the options are
455 # supposed to be disabled for multilib ABIs (like those used for
456 # executables only).
457 multilib_build_binaries() {
458 debug-print-function ${FUNCNAME} "${@}"
459
460 [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
461
462 [[ ${COMPLETE_MULTILIB} == yes ]] || multilib_is_native_abi
463 }
464
465 _MULTILIB_BUILD=1
466 fi

  ViewVC Help
Powered by ViewVC 1.1.20