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

Contents of /eclass/autotools-multilib.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Mon Apr 1 09:18:57 2013 UTC (17 months, 2 weeks ago) by mgorny
Branch: MAIN
Changes since 1.12: +94 -1 lines
Support wrapping headers for multilib.

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/autotools-multilib.eclass,v 1.12 2013/02/27 21:47:38 mgorny Exp $
4
5 # @ECLASS: autotools-multilib.eclass
6 # @MAINTAINER:
7 # Michał Górny <mgorny@gentoo.org>
8 # @BLURB: autotools-utils wrapper for multilib builds
9 # @DESCRIPTION:
10 # The autotools-multilib.eclass is an autotools-utils.eclass(5) wrapper
11 # introducing support for building for more than one ABI (multilib).
12 #
13 # Inheriting this eclass sets the USE flags and exports autotools-utils
14 # phase function wrappers which build the package for each supported ABI
15 # when the relevant flag is enabled. Other than that, it works like
16 # regular autotools-utils.
17 #
18 # Note that the multilib support requires out-of-source builds to be
19 # enabled. Thus, it is impossible to use AUTOTOOLS_IN_SOURCE_BUILD with
20 # it.
21
22 # EAPI=5 is required for meaningful MULTILIB_USEDEP.
23 case ${EAPI:-0} in
24 5) ;;
25 *) die "EAPI=${EAPI} is not supported" ;;
26 esac
27
28 if [[ ${AUTOTOOLS_IN_SOURCE_BUILD} ]]; then
29 die "${ECLASS}: multilib support requires out-of-source builds."
30 fi
31
32 inherit autotools-utils multilib-build
33
34 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
35
36 # @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
37 # @DESCRIPTION:
38 # A list of headers to wrap for multilib support. The listed headers
39 # will be moved to a non-standard location and replace with a file
40 # including them conditionally to current ABI.
41 #
42 # This variable has to be a bash array. Paths shall be relative to
43 # installation root (${ED}), and name regular files. Recursive wrapping
44 # is not supported.
45 #
46 # Please note that header wrapping is *discouraged*. It is preferred to
47 # install all headers in a subdirectory of libdir and use pkg-config to
48 # locate the headers. Some C preprocessors will not work with wrapped
49 # headers.
50 #
51 # Example:
52 # @CODE
53 # MULTILIB_WRAPPED_HEADERS=(
54 # /usr/include/foobar/config.h
55 # )
56 # @CODE
57
58 autotools-multilib_src_prepare() {
59 autotools-utils_src_prepare "${@}"
60 }
61
62 autotools-multilib_src_configure() {
63 multilib_parallel_foreach_abi autotools-utils_src_configure "${@}"
64 }
65
66 autotools-multilib_src_compile() {
67 multilib_foreach_abi autotools-utils_src_compile "${@}"
68 }
69
70 autotools-multilib_src_test() {
71 multilib_foreach_abi autotools-utils_src_test "${@}"
72 }
73
74 _autotools-multilib_wrap_headers() {
75 debug-print-function ${FUNCNAME} "$@"
76 local f
77
78 for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
79 # drop leading slash if it's there
80 f=${f#/}
81
82 if [[ ${f} != usr/include/* ]]; then
83 die "Wrapping headers outside of /usr/include is not supported at the moment."
84 fi
85 # and then usr/include
86 f=${f#usr/include/}
87
88 local dir=${f%/*}
89
90 # $CHOST shall be set by multilib_toolchain_setup
91 dodir "/tmp/multilib-include/${CHOST}/${dir}"
92 mv "${ED}/usr/include/${f}" "${ED}/tmp/multilib-include/${CHOST}/${dir}/" || die
93
94 if [[ ! -f ${ED}/tmp/multilib-include/${f} ]]; then
95 dodir "/tmp/multilib-include/${dir}"
96 # a generic template
97 cat > "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
98 /* This file is auto-generated by autotools-multilib.eclass
99 * as a multilib-friendly wrapper. For the original content,
100 * please see the files that are #included below.
101 */
102
103 #if defined(__x86_64__) /* amd64 */
104 # if defined(__ILP32__) /* x32 ABI */
105 # error "abi_x86_x32 not supported by the package."
106 # else /* 64-bit ABI */
107 # error "abi_x86_64 not supported by the package."
108 # endif
109 #elif defined(__i386__) /* plain x86 */
110 # error "abi_x86_32 not supported by the package."
111 #else
112 # error "No ABI matched, please report a bug to bugs.gentoo.org"
113 #endif
114 _EOF_
115 fi
116
117 # XXX: get abi_* directly
118 local abi_flag
119 case "${ABI}" in
120 amd64)
121 abi_flag=abi_x86_64;;
122 x86)
123 abi_flag=abi_x86_32;;
124 x32)
125 abi_flag=abi_x86_x32;;
126 *)
127 die "Header wrapping for ${ABI} not supported yet";;
128 esac
129
130 # Note: match a space afterwards to avoid collision potential.
131 sed -e "/${abi_flag} /s&error.*&include <${CHOST}/${f}>&" \
132 -i "${ED}/tmp/multilib-include/${f}" || die
133 done
134 }
135
136 autotools-multilib_src_install() {
137 autotools-multilib_secure_install() {
138 autotools-utils_src_install "${@}"
139
140 _autotools-multilib_wrap_headers
141 # Make sure all headers are the same for each ABI.
142 multilib_check_headers
143 }
144
145 multilib_foreach_abi autotools-multilib_secure_install "${@}"
146
147 # merge the wrapped headers
148 if [[ -d "${ED}"/tmp/multilib-include ]]; then
149 multibuild_merge_root \
150 "${ED}"/tmp/multilib-include "${ED}"/usr/include
151 # it can fail if something else uses /tmp
152 rmdir "${ED}"/tmp &>/dev/null
153 fi
154 }

  ViewVC Help
Powered by ViewVC 1.1.20