Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/2] Support wrapping headers for multilib ABIs.
Date: Sat, 23 Mar 2013 16:26:36
Message-Id: 1364055998-23674-2-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES] Header wrapping support for multilib by "Michał Górny"
1 ---
2 gx86/eclass/autotools-multilib.eclass | 82 +++++++++++++++++++++++++++++++++++
3 1 file changed, 82 insertions(+)
4
5 diff --git a/gx86/eclass/autotools-multilib.eclass b/gx86/eclass/autotools-multilib.eclass
6 index d7372b0..c65c777 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,73 @@ 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 + if [[ ! -f ${ED}/tmp/multilib-include/${f} ]]; then
63 + dodir "/tmp/multilib-include/${dir}"
64 + cat > "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
65 +/* This file is auto-generated by autotools-multilib.eclass
66 + * as a multilib-friendly wrapper to /${f}. For the original content,
67 + * please see the files that are #included below.
68 + */
69 +_EOF_
70 + fi
71 +
72 + local defs
73 + case "${ABI}" in
74 + amd64)
75 + defs='defined(__x86_64__) && !defined(__ILP32__)';;
76 + x86)
77 + defs='defined(__i386__)';;
78 + x32)
79 + defs='defined(__x86_64__) && defined(__ILP32__)';;
80 + *)
81 + die "Header wrapping for ${ABI} not supported yet";;
82 + esac
83 +
84 + cat >> "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
85 +
86 +#if ${defs}
87 +# include <${CHOST}/${f}>
88 +#endif
89 +_EOF_
90 + done
91 +}
92 +
93 autotools-multilib_src_install() {
94 autotools-multilib_secure_install() {
95 autotools-utils_src_install "${@}"
96
97 + _autotools-multilib_wrap_headers
98 # Make sure all headers are the same for each ABI.
99 multilib_check_headers
100 }
101
102 multilib_foreach_abi autotools-multilib_secure_install "${@}"
103 +
104 + # merge the wrapped headers
105 + if [[ -d "${ED}"/tmp/multilib-include ]]; then
106 + multibuild_merge_root \
107 + "${ED}"/tmp/multilib-include "${ED}"/usr/include
108 + # it can fail if something else uses /tmp
109 + rmdir "${ED}"/tmp &>/dev/null
110 + fi
111 }
112 --
113 1.8.1.5

Replies