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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (show annotations) (download)
Thu Jan 16 20:05:12 2014 UTC (7 months, 4 weeks ago) by mgorny
Branch: MAIN
Changes since 1.26: +2 -2 lines
Typo.

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

  ViewVC Help
Powered by ViewVC 1.1.20