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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.28 - (hide annotations) (download)
Sat Mar 29 03:00:44 2014 UTC (7 months, 3 weeks ago) by vapier
Branch: MAIN
Changes since 1.27: +7 -1 lines
add ABI_PPC support

1 mgorny 1.26 # Copyright 1999-2014 Gentoo Foundation
2 mgorny 1.1 # Distributed under the terms of the GNU General Public License v2
3 vapier 1.28 # $Header: /var/cvsroot/gentoo-x86/eclass/multilib-build.eclass,v 1.27 2014/01/16 20:05:12 mgorny Exp $
4 mgorny 1.1
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 mgorny 1.12 # EAPI=4 is required for meaningful MULTILIB_USEDEP.
21 mgorny 1.1 case ${EAPI:-0} in
22 mgorny 1.12 4|5) ;;
23 mgorny 1.1 *) die "EAPI=${EAPI} is not supported" ;;
24     esac
25    
26 mgorny 1.8 inherit multibuild multilib
27 mgorny 1.1
28     # @ECLASS-VARIABLE: _MULTILIB_FLAGS
29     # @INTERNAL
30     # @DESCRIPTION:
31 mgorny 1.21 # 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 mgorny 1.1 _MULTILIB_FLAGS=(
35 mgorny 1.21 abi_x86_32:x86,x86_fbsd
36     abi_x86_64:amd64,amd64_fbsd
37 mgorny 1.6 abi_x86_x32:x32
38 mattst88 1.17 abi_mips_n32:n32
39     abi_mips_n64:n64
40     abi_mips_o32:o32
41 vapier 1.28 abi_ppc_32:ppc
42     abi_ppc_64:ppc64
43 mgorny 1.1 )
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 mgorny 1.21 local m_abis=${i#*:} m_abi
81 mgorny 1.1 local m_flag=${i%:*}
82    
83 mgorny 1.22 # split on ,; we can't switch IFS for function scope because
84     # paludis is broken (bug #486592), and switching it locally
85 mgorny 1.23 # for the split is more complex than cheating like this
86     for m_abi in ${m_abis//,/ }; do
87 mgorny 1.21 if [[ ${m_abi} == ${abi} ]] && use "${m_flag}"; then
88     echo "${abi}"
89     found=1
90     break 2
91     fi
92     done
93 mgorny 1.1 done
94     done
95    
96     if [[ ! ${found} ]]; then
97 mgorny 1.7 # ${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 mgorny 1.1 fi
105     }
106    
107 mgorny 1.8 # @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 mgorny 1.1 # @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 mgorny 1.8 debug-print-function ${FUNCNAME} "${@}"
131 mgorny 1.1
132 mgorny 1.8 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
133     multibuild_foreach_variant _multilib_multibuild_wrapper "${@}"
134 mgorny 1.1 }
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 mgorny 1.8 debug-print-function ${FUNCNAME} "${@}"
150 mgorny 1.1
151 mgorny 1.8 local MULTIBUILD_VARIANTS=( $(multilib_get_enabled_abis) )
152     multibuild_parallel_foreach_variant _multilib_multibuild_wrapper "${@}"
153 mgorny 1.1 }
154    
155 mgorny 1.9 # @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 mgorny 1.2 # @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 mgorny 1.4 [[ -d ${ED}usr/include ]] && \
177 mgorny 1.2 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 mgorny 1.10 # @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 mgorny 1.11 # @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 mgorny 1.26 # @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. Recursive wrapping
250     # is not supported.
251     #
252     # Please note that tool wrapping is *discouraged*. It is preferred to
253     # install pkg-config files for each ABI, and require reverse
254     # dependencies to use that.
255     #
256     # Packages that search for tools properly (e.g. using AC_PATH_TOOL
257     # macro) will find the wrapper executables automatically. Other packages
258     # will need explicit override of tool paths.
259     #
260     # Example:
261     # @CODE
262     # MULTILIB_CHOST_TOOLS=(
263     # /usr/bin/foo-config
264     # )
265    
266     # @CODE
267 mgorny 1.11 # @FUNCTION: multilib_prepare_wrappers
268     # @USAGE: [<install-root>]
269     # @DESCRIPTION:
270     # Perform the preparation of all kinds of wrappers for the current ABI.
271     # This function shall be called once per each ABI, after installing
272     # the files to be wrapped.
273     #
274     # Takes an optional custom <install-root> from which files will be
275     # used. If no root is specified, uses ${ED}.
276     #
277     # The files to be wrapped are specified using separate variables,
278     # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
279     # between the successive calls to multilib_prepare_wrappers
280     # and multilib_install_wrappers.
281     #
282     # After all wrappers are prepared, multilib_install_wrappers shall
283     # be called to commit them to the installation tree.
284     multilib_prepare_wrappers() {
285     debug-print-function ${FUNCNAME} "${@}"
286    
287     [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
288    
289     local root=${1:-${ED}}
290     local f
291    
292     for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
293     # drop leading slash if it's there
294     f=${f#/}
295    
296     if [[ ${f} != usr/include/* ]]; then
297     die "Wrapping headers outside of /usr/include is not supported at the moment."
298     fi
299     # and then usr/include
300     f=${f#usr/include}
301    
302     local dir=${f%/*}
303    
304     if [[ ! -f ${ED}/tmp/multilib-include${f} ]]; then
305     dodir "/tmp/multilib-include${dir}"
306     # a generic template
307 mgorny 1.13 cat > "${ED}/tmp/multilib-include${f}" <<_EOF_
308 mgorny 1.11 /* This file is auto-generated by multilib-build.eclass
309     * as a multilib-friendly wrapper. For the original content,
310     * please see the files that are #included below.
311     */
312    
313     #if defined(__x86_64__) /* amd64 */
314     # if defined(__ILP32__) /* x32 ABI */
315     # error "abi_x86_x32 not supported by the package."
316     # else /* 64-bit ABI */
317     # error "abi_x86_64 not supported by the package."
318     # endif
319     #elif defined(__i386__) /* plain x86 */
320     # error "abi_x86_32 not supported by the package."
321 mattst88 1.17 #elif defined(__mips__)
322     # if(_MIPS_SIM == _ABIN32) /* n32 */
323     # error "abi_mips_n32 not supported by the package."
324     # elif(_MIPS_SIM == _ABI64) /* n64 */
325     # error "abi_mips_n64 not supported by the package."
326     # elif(_MIPS_SIM == _ABIO32) /* o32 */
327     # error "abi_mips_o32 not supported by the package."
328     # endif
329 mgorny 1.11 #else
330     # error "No ABI matched, please report a bug to bugs.gentoo.org"
331     #endif
332     _EOF_
333     fi
334    
335 mgorny 1.18 # Some ABIs may have install less files than others.
336     if [[ -f ${root}/usr/include${f} ]]; then
337     # $CHOST shall be set by multilib_toolchain_setup
338     dodir "/tmp/multilib-include/${CHOST}${dir}"
339     mv "${root}/usr/include${f}" "${ED}/tmp/multilib-include/${CHOST}${dir}/" || die
340    
341     # XXX: get abi_* directly
342     local abi_flag
343     case "${ABI}" in
344     amd64|amd64_fbsd)
345     abi_flag=abi_x86_64;;
346     x86|x86_fbsd)
347     abi_flag=abi_x86_32;;
348     x32)
349     abi_flag=abi_x86_x32;;
350     n32)
351     abi_flag=abi_mips_n32;;
352     n64)
353     abi_flag=abi_mips_n64;;
354     o32)
355     abi_flag=abi_mips_o32;;
356 vapier 1.28 ppc)
357     abi_flag=abi_ppc_32;;
358     ppc64)
359     abi_flag=abi_ppc_64;;
360 mgorny 1.18 *)
361     die "Header wrapping for ${ABI} not supported yet";;
362     esac
363    
364     # Note: match a space afterwards to avoid collision potential.
365     sed -e "/${abi_flag} /s&error.*&include <${CHOST}${f}>&" \
366     -i "${ED}/tmp/multilib-include${f}" || die
367     fi
368 mgorny 1.11 done
369 mgorny 1.26
370     for f in "${MULTILIB_CHOST_TOOLS[@]}"; do
371     # drop leading slash if it's there
372     f=${f#/}
373    
374     local dir=${f%/*}
375     local fn=${f##*/}
376    
377     mv "${root}/${f}" "${root}/${dir}/${CHOST}-${fn}" || die
378    
379     # symlink the native one back
380     if multilib_build_binaries; then
381     ln -s "${CHOST}-${fn}" "${root}/${f}" || die
382     fi
383     done
384 mgorny 1.11 }
385    
386     # @FUNCTION: multilib_install_wrappers
387     # @USAGE: [<install-root>]
388     # @DESCRIPTION:
389     # Install the previously-prepared wrappers. This function shall
390     # be called once, after all wrappers were prepared.
391     #
392     # Takes an optional custom <install-root> to which the wrappers will be
393     # installed. If no root is specified, uses ${ED}. There is no need to
394     # use the same root as when preparing the wrappers.
395     #
396     # The files to be wrapped are specified using separate variables,
397     # e.g. MULTILIB_WRAPPED_HEADERS. Those variables shall not be changed
398     # between the calls to multilib_prepare_wrappers
399     # and multilib_install_wrappers.
400     multilib_install_wrappers() {
401     debug-print-function ${FUNCNAME} "${@}"
402    
403     [[ ${#} -le 1 ]] || die "${FUNCNAME}: too many arguments"
404    
405     local root=${1:-${ED}}
406    
407     if [[ -d "${ED}"/tmp/multilib-include ]]; then
408     multibuild_merge_root \
409     "${ED}"/tmp/multilib-include "${root}"/usr/include
410     # it can fail if something else uses /tmp
411     rmdir "${ED}"/tmp &>/dev/null
412     fi
413     }
414    
415 mgorny 1.15 # @FUNCTION: multilib_is_native_abi
416     # @DESCRIPTION:
417     # Determine whether the currently built ABI is the profile native.
418     # Return true status (0) if that is true, otherwise false (1).
419     #
420 mgorny 1.25 # This function is not intended to be used directly. Please use
421     # multilib_build_binaries instead.
422 mgorny 1.15 multilib_is_native_abi() {
423     debug-print-function ${FUNCNAME} "${@}"
424    
425     [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
426    
427     [[ ${ABI} == ${DEFAULT_ABI} ]]
428     }
429    
430 tommy 1.20 # @FUNCTION: multilib_build_binaries
431     # @DESCRIPTION:
432 mgorny 1.27 # Determine whether to build binaries for the currently built ABI.
433 mgorny 1.25 # Returns true status (0) if the currently built ABI is the profile
434     # native or COMPLETE_MULTILIB variable is set to 'yes', otherwise
435 tommy 1.20 # false (1).
436     #
437 mgorny 1.25 # This is often useful for configure calls when some of the options are
438     # supposed to be disabled for multilib ABIs (like those used for
439     # executables only).
440 tommy 1.19 multilib_build_binaries() {
441     debug-print-function ${FUNCNAME} "${@}"
442    
443     [[ ${#} -eq 0 ]] || die "${FUNCNAME}: too many arguments"
444    
445     [[ ${COMPLETE_MULTILIB} == yes ]] || multilib_is_native_abi
446     }
447 tommy 1.20
448 mgorny 1.1 _MULTILIB_BUILD=1
449     fi

  ViewVC Help
Powered by ViewVC 1.1.20