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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Tue Sep 17 13:29:19 2013 UTC (12 months ago) by tommy
Branch: MAIN
Changes since 1.19: +12 -2 lines
Add eclass doc for multilib_build_binaries

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

  ViewVC Help
Powered by ViewVC 1.1.20