---
 gx86/eclass/autotools-multilib.eclass | 82 +++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/gx86/eclass/autotools-multilib.eclass 
b/gx86/eclass/autotools-multilib.eclass
index d7372b0..c65c777 100644
--- a/gx86/eclass/autotools-multilib.eclass
+++ b/gx86/eclass/autotools-multilib.eclass
@@ -33,6 +33,28 @@ inherit autotools-utils multilib-build
 
 EXPORT_FUNCTIONS src_prepare src_configure src_compile src_test src_install
 
+# @ECLASS-VARIABLE: MULTILIB_WRAPPED_HEADERS
+# @DESCRIPTION:
+# A list of headers to wrap for multilib support. The listed headers
+# will be moved to a non-standard location and replace with a file
+# including them conditionally to current ABI.
+#
+# This variable has to be a bash array. Paths shall be relative to
+# installation root (${D}), and name regular files. Recursive wrapping
+# is not supported.
+#
+# Please note that header wrapping is *discouraged*. It is preferred to
+# install all headers in a subdirectory of libdir and use pkg-config to
+# locate the headers. Some C preprocessors will not work with wrapped
+# headers.
+#
+# Example:
+# @CODE
+# MULTILIB_WRAPPED_HEADERS=(
+#      /usr/include/foobar/config.h
+# )
+# @CODE
+
 autotools-multilib_src_prepare() {
        autotools-utils_src_prepare "${@}"
 }
@@ -49,13 +71,73 @@ autotools-multilib_src_test() {
        multilib_foreach_abi autotools-utils_src_test "${@}"
 }
 
+_autotools-multilib_wrap_headers() {
+       debug-print-function ${FUNCNAME} "$@"
+       local f
+
+       for f in "${MULTILIB_WRAPPED_HEADERS[@]}"; do
+               # drop leading slash if it's there
+               f=${f#/}
+
+               if [[ ${f} != usr/include/* ]]; then
+                       die "Wrapping headers outside of /usr/include is not 
supported at the moment."
+               fi
+               # and then usr/include
+               f=${f#usr/include/}
+
+               local dir=${f%/*}
+
+               # $CHOST shall be set by multilib_toolchain_setup
+               dodir "/tmp/multilib-include/${CHOST}/${dir}"
+               mv "${ED}/usr/include/${f}" 
"${ED}/tmp/multilib-include/${CHOST}/${dir}/" || die
+
+               if [[ ! -f ${ED}/tmp/multilib-include/${f} ]]; then
+                       dodir "/tmp/multilib-include/${dir}"
+                       cat > "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
+/* This file is auto-generated by autotools-multilib.eclass
+ * as a multilib-friendly wrapper to /${f}. For the original content,
+ * please see the files that are #included below.
+ */
+_EOF_
+               fi
+
+               local defs
+               case "${ABI}" in
+                       amd64)
+                               defs='defined(__x86_64__) && 
!defined(__ILP32__)';;
+                       x86)
+                               defs='defined(__i386__)';;
+                       x32)
+                               defs='defined(__x86_64__) && 
defined(__ILP32__)';;
+                       *)
+                               die "Header wrapping for ${ABI} not supported 
yet";;
+               esac
+
+               cat >> "${ED}/tmp/multilib-include/${f}" <<_EOF_ || die
+
+#if ${defs}
+#      include <${CHOST}/${f}>
+#endif
+_EOF_
+       done
+}
+
 autotools-multilib_src_install() {
        autotools-multilib_secure_install() {
                autotools-utils_src_install "${@}"
 
+               _autotools-multilib_wrap_headers
                # Make sure all headers are the same for each ABI.
                multilib_check_headers
        }
 
        multilib_foreach_abi autotools-multilib_secure_install "${@}"
+
+       # merge the wrapped headers
+       if [[ -d "${ED}"/tmp/multilib-include ]]; then
+               multibuild_merge_root \
+                       "${ED}"/tmp/multilib-include "${ED}"/usr/include
+               # it can fail if something else uses /tmp
+               rmdir "${ED}"/tmp &>/dev/null
+       fi
 }
-- 
1.8.1.5


Reply via email to