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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (show annotations) (download)
Sat Jul 27 17:31:47 2013 UTC (16 months ago) by aballier
Branch: MAIN
Changes since 1.15: +5 -3 lines
Add support for freebsd, bug #475294 by  Yuta SATOH

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

  ViewVC Help
Powered by ViewVC 1.1.20