Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: aballier@g.o, "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] Support wrapping headers for multilib ABIs.
Date: Mon, 25 Mar 2013 22:22:14
Message-Id: 1364250175-29611-1-git-send-email-mgorny@gentoo.org
In Reply to: Re: [gentoo-dev] [PATCH 2/2] Support wrapping headers for multilib ABIs. by Alexis Ballier
1 This time using a template like Alexis suggested. I've only added
2 the ABIs currently supported by multilib-build. Feel free to provide me
3 with a more complete one.
4 ---
5 gx86/eclass/autotools-multilib.eclass | 93 +++++++++++++++++++++++++++++++++++
6 1 file changed, 93 insertions(+)
7
8 diff --git a/gx86/eclass/autotools-multilib.eclass b/gx86/eclass/autotools-multilib.eclass
9 index d7372b0..ccbaac6 100644
10 --- a/gx86/eclass/autotools-multilib.eclass
11 +++ b/gx86/eclass/autotools-multilib.eclass
12 @@ -33,6 +33,28 @@ inherit autotools-utils multilib-build
13
14 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
15
16 +# @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
17 +# @DESCRIPTION:
18 +# A list of headers to wrap for multilib support. The listed headers
19 +# will be moved to a non-standard location and replace with a file
20 +# including them conditionally to current ABI.
21 +#
22 +# This variable has to be a bash array. Paths shall be relative to
23 +# installation root (${ED}), and name regular files. Recursive wrapping
24 +# is not supported.
25 +#
26 +# Please note that header wrapping is *discouraged*. It is preferred to
27 +# install all headers in a subdirectory of libdir and use pkg-config to
28 +# locate the headers. Some C preprocessors will not work with wrapped
29 +# headers.
30 +#
31 +# Example:
32 +# @CODE
33 +# MULTILIB_WRAPPED_HEADERS=(
34 +# /usr/include/foobar/config.h
35 +# )
36 +# @CODE
37 +
38 autotools-multilib_src_prepare() {
39 autotools-utils_src_prepare "${@}"
40 }
41 @@ -49,13 +71,84 @@ autotools-multilib_src_test() {
42 multilib_foreach_abi autotools-utils_src_test "${@}"
43 }
44
45 +_autotools-multilib_wrap_headers() {
46 + debug-print-function ${FUNCNAME} "$@"
47 + local f
48 +
49 + for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
50 + # drop leading slash if it's there
51 + f=${f#/}
52 +
53 + if [[ ${f} != usr/include/* ]]; then
54 + die "Wrapping headers outside of /usr/include is not supported at the moment."
55 + fi
56 + # and then usr/include
57 + f=${f#usr/include/}
58 +
59 + local dir=${f%/*}
60 +
61 + # $CHOST shall be set by multilib_toolchain_setup
62 + dodir "/tmp/multilib-include/${CHOST}/${dir}"
63 + mv "${ED}/usr/include/${f}" "${ED}/tmp/multilib-include/${CHOST}/${dir}/" || die
64 +
65 + if [[ ! -f ${ED}/tmp/multilib-include/${f} ]]; then
66 + dodir "/tmp/multilib-include/${dir}"
67 + # a generic template
68 + cat > "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
69 +/* This file is auto-generated by autotools-multilib.eclass
70 + * as a multilib-friendly wrapper. For the original content,
71 + * please see the files that are #included below.
72 + */
73 +
74 +#if defined(__x86_64__) /* amd64 */
75 +# if defined(__ILP32__) /* x32 ABI */
76 +# error "abi_x86_x32 not supported by the package."
77 +# else /* 64-bit ABI */
78 +# error "abi_x86_64 not supported by the package."
79 +# endif
80 +#elif defined(__i386__) /* plain x86 */
81 +# error "abi_x86_32 not supported by the package."
82 +#else
83 +# error "No ABI matched, please report a bug to bugs.gentoo.org"
84 +#endif
85 +_EOF_
86 + fi
87 +
88 + # XXX: get abi_* directly
89 + local abi_flag
90 + case "${ABI}" in
91 + amd64)
92 + abi_flag=abi_x86_64;;
93 + x86)
94 + abi_flag=abi_x86_32;;
95 + x32)
96 + abi_flag=abi_x86_x32;;
97 + *)
98 + die "Header wrapping for ${ABI} not supported yet";;
99 + esac
100 +
101 + # Note: match a space afterwards to avoid collision potential.
102 + sed -e "/${abi_flag} /s&error.*&include <${CHOST}/${f}>&" \
103 + -i "${ED}/tmp/multilib-include/${f}" || die
104 + done
105 +}
106 +
107 autotools-multilib_src_install() {
108 autotools-multilib_secure_install() {
109 autotools-utils_src_install "${@}"
110
111 + _autotools-multilib_wrap_headers
112 # Make sure all headers are the same for each ABI.
113 multilib_check_headers
114 }
115
116 multilib_foreach_abi autotools-multilib_secure_install "${@}"
117 +
118 + # merge the wrapped headers
119 + if [[ -d "${ED}"/tmp/multilib-include ]]; then
120 + multibuild_merge_root \
121 + "${ED}"/tmp/multilib-include "${ED}"/usr/include
122 + # it can fail if something else uses /tmp
123 + rmdir "${ED}"/tmp &>/dev/null
124 + fi
125 }
126 --
127 1.8.1.5