public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: flameeyes@gentoo.org, "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] Support wrapping headers for multilib ABIs.
Date: Sat, 23 Mar 2013 20:56:03 +0100	[thread overview]
Message-ID: <1364068563-4230-1-git-send-email-mgorny@gentoo.org> (raw)
In-Reply-To: <514DDC5A.5040308@flameeyes.eu>

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

diff --git a/gx86/eclass/autotools-multilib.eclass b/gx86/eclass/autotools-multilib.eclass
index d7372b0..e96fdaf 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,77 @@ 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
+
+		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
+
+		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. For the original content,
+ * please see the files that are #included below.
+ */
+
+#if ${defs}
+#	include <${CHOST}/${f}>
+#else
+#	error "No ABI matched, please report a bug to bugs.gentoo.org"
+#endif
+_EOF_
+		else
+			sed -e "/^#else/i\
+#elif ${defs}\n\
+#	include <${CHOST}/${f}>" \
+				-i "${ED}/tmp/multilib-include/${f}" || die
+		fi
+	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



  parent reply	other threads:[~2013-03-23 19:55 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-23 16:25 [gentoo-dev] [PATCHES] Header wrapping support for multilib Michał Górny
2013-03-23 16:26 ` [gentoo-dev] [PATCH 1/2] Introduce multibuild_merge_root() to merge interim installs Michał Górny
2013-03-23 17:00   ` Ulrich Mueller
2013-03-23 17:28     ` Michał Górny
2013-03-24  7:47       ` Ulrich Mueller
2013-03-24 10:09         ` Michał Górny
2013-03-24 13:40           ` Ulrich Mueller
2013-03-24 14:13             ` Michał Górny
2013-03-24 20:18               ` Zac Medico
2013-03-25 22:42     ` [gentoo-dev] [PATCH] " Michał Górny
2013-03-23 17:44   ` [gentoo-dev] [PATCH 1/2] " Alec Warner
2013-03-23 18:57     ` Michał Górny
2013-03-23 18:57     ` [gentoo-dev] " Jonathan Callen
2013-03-23 19:02       ` Alec Warner
2013-03-23 16:26 ` [gentoo-dev] [PATCH 2/2] Support wrapping headers for multilib ABIs Michał Górny
2013-03-24 15:14   ` Alexis Ballier
2013-03-24 15:41     ` Michał Górny
2013-03-24 20:01       ` Alexis Ballier
2013-03-25 22:22         ` [gentoo-dev] [PATCH] " Michał Górny
2013-03-23 16:46 ` [gentoo-dev] [PATCHES] Header wrapping support for multilib Diego Elio Pettenò
2013-03-23 17:32   ` Michał Górny
2013-03-23 17:32     ` Diego Elio Pettenò
2013-03-23 19:56   ` Michał Górny [this message]
2013-03-23 20:03     ` [gentoo-dev] [PATCH] Support wrapping headers for multilib ABIs Michał Górny
2013-03-23 22:01     ` [gentoo-dev] " Jonathan Callen
2013-04-01  9:19 ` [gentoo-dev] [PATCHES] Header wrapping support for multilib Michał Górny
2013-04-02 10:59   ` Alexis Ballier
2013-04-02 11:47     ` Michał Górny
2013-04-04  8:07       ` Alexis Ballier
2013-04-04 17:53         ` Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1364068563-4230-1-git-send-email-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=flameeyes@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox