Gentoo Archives: gentoo-dev

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

Replies