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

Contents of /eclass/multilib-build.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.11 - (show annotations) (download)
Sun Apr 7 16:56:14 2013 UTC (12 months, 1 week ago) by mgorny
Branch: MAIN
Changes since 1.10: +135 -1 lines
Move header wrapping to multilib-build. Use the new code in autotools-multilib and multilib-minimal.

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

  ViewVC Help
Powered by ViewVC 1.1.20