All of lore.kernel.org
 help / color / mirror / Atom feed
From: Romain Naour <romain.naour@smile.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH v2 04/12] package/clang: install a toolchain-wrapper for the host clang cross-compiler
Date: Sat,  7 Sep 2019 11:40:19 +0200	[thread overview]
Message-ID: <20190907094027.9537-5-romain.naour@smile.fr> (raw)
In-Reply-To: <20190907094027.9537-1-romain.naour@smile.fr>

In order to use clang as a host cross-compiler for Buildroot, we need
to provide at least the path to the sysroot (using --sysroot) and
some other compiler flags.

Hoppefully, we can reuse the toolchain wrapper for gcc since
clang support most of the gcc flags used in the Buildroot's toolchain
wrapper.

Only the flag -mfused-madd (deprecated since gcc 4.6) for mips is
not supported by clang. Since Clang require gcc >= 5.x this flag
can never be used.

Since host-clang is always build by Buildroot as an internal toolchain,
we have to use a second toolchain-wrapper called toolchain-wrapper-clang
when an external toolchain is used.
Inded, the two wrapper use a different path BR_CROSS_PATH_SUFFIX in this
case.

After building the clang toolchain wrapper, create the symlinks needed
to force package infrastructure to use clang througt the wrapper.

Initially clang install the clang-8 binary and create all other symlinks:

 # clang -> clang-8
 # clang++ -> clang
 # clang-8
 # clang-cl -> clang
 # clang-cpp -> clang

Use a post install hook to rename the clang-8 binary to clang-8.br_real
and recreate all symlinks:

 # clang -> toolchain-wrapper-clang
 # clang++ -> toolchain-wrapper-clang
 # clang-8 -> toolchain-wrapper-clang
 # clang-8.br_real
 # clang++.br_real -> clang-8.br_real
 # clang.br_real -> clang-8.br_real
 # clang-cl -> toolchain-wrapper-clang
 # clang-cl.br_real -> clang-8.br_real
 # clang-cpp -> toolchain-wrapper-clang
 # clang-cpp.br_real -> clang-8.br_real

Use the previously introduced CLANG_VERSION_MAJOR variable to create
theses symlinks.

Set BR_CROSS_PATH_SUFFIX to ".br_real" as for the Buildroot's internal
GCC toolchain backend to find the "real" clang binary installed in
$(HOST_DIR)/bin.

Borrow TOOLCHAIN_WRAPPER_BUILD and TOOLCHAIN_WRAPPER_INSTALL to
build and install the specific clang toolchain wrapper.

Signed-off-by: Romain Naour <romain.naour@smile.fr>
Cc: Matt Weber <matthew.weber@rockwellcollins.com>
Cc: Valentin Korenblit <valentinkorenblit@gmail.com>
---
 package/clang/clang.mk | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/package/clang/clang.mk b/package/clang/clang.mk
index 857ec148ac..148df8e611 100644
--- a/package/clang/clang.mk
+++ b/package/clang/clang.mk
@@ -110,5 +110,39 @@ ifeq ($(BR2_TOOLCHAIN_EXTERNAL),y)
 HOST_CLANG_CONF_OPTS += -DGCC_INSTALL_PREFIX:PATH=`realpath --relative-to=$(HOST_DIR)/bin/ $(TOOLCHAIN_EXTERNAL_INSTALL_DIR)`
 endif
 
+define HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
+	$(Q)cd $(HOST_DIR)/bin; \
+	for i in clang clang-$(CLANG_VERSION_MAJOR) clang++ clang-cl clang-cpp; do \
+		case "$$i" in \
+		*clang-$(CLANG_VERSION_MAJOR)) \
+			rm -f $$i.br_real; \
+			mv $$i $$i.br_real; \
+			ln -sf toolchain-wrapper-clang $$i; \
+			;; \
+		*) \
+			ln -snf toolchain-wrapper-clang $$i; \
+			ln -snf clang-$(CLANG_VERSION_MAJOR).br_real $$i.br_real; \
+			;; \
+		esac; \
+	done
+endef
+
+define HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
+	$(HOSTCC) $(HOST_CFLAGS) $(TOOLCHAIN_WRAPPER_ARGS) \
+		-s -Wl,--hash-style=$(TOOLCHAIN_WRAPPER_HASH_STYLE) \
+		toolchain/toolchain-wrapper.c \
+		-o $(@D)/toolchain-wrapper-clang
+endef
+
+define HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
+	$(INSTALL) -D -m 0755 $(@D)/toolchain-wrapper-clang \
+		$(HOST_DIR)/bin/toolchain-wrapper-clang
+endef
+
+HOST_CLANG_TOOLCHAIN_WRAPPER_ARGS += -DBR_CROSS_PATH_SUFFIX='".br_real"'
+HOST_CLANG_POST_BUILD_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_BUILD
+HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_TOOLCHAIN_WRAPPER_INSTALL
+HOST_CLANG_POST_INSTALL_HOOKS += HOST_CLANG_INSTALL_WRAPPER_AND_SIMPLE_SYMLINKS
+
 $(eval $(cmake-package))
 $(eval $(host-cmake-package))
-- 
2.21.0

  parent reply	other threads:[~2019-09-07  9:40 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-07  9:40 [Buildroot] [PATCH v2 00/12] Add the support for Clang cross-compiler Romain Naour
2019-09-07  9:40 ` [Buildroot] [PATCH v2 01/12] package/clang: help host-clang to find our external toolchain Romain Naour
2019-09-09 14:26   ` Matthew Weber
2020-08-29 19:00   ` Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 02/12] package/llvm: add the version major variable Romain Naour
2020-08-29 19:00   ` Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 03/12] package/clang: " Romain Naour
2019-09-07  9:40 ` Romain Naour [this message]
2020-08-29 19:40   ` [Buildroot] [PATCH v2 04/12] package/clang: install a toolchain-wrapper for the host clang cross-compiler Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 05/12] linux: override CC for the case CC is not GCC Romain Naour
2020-08-30  7:57   ` Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 06/12] package/meson: use TARGET_{CC, CXX} instead of TARGET_CROSS for cc and cpp Romain Naour
2019-09-07  9:40 ` [Buildroot] [PATCH v2 07/12] package/busybox: fix applets runtime issue when building with clang cross-compiler Romain Naour
2019-09-09 14:29   ` Matthew Weber
2020-08-29 20:21   ` Arnout Vandecappelle
2020-09-14 19:58     ` Romain Naour
2019-09-07  9:40 ` [Buildroot] [PATCH v2 08/12] package/clang: add a host entry for clang Romain Naour
2020-08-29 20:34   ` Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 09/12] package/glibc: use GCC cross-compiler if Clang is used as cross-compiler Romain Naour
2019-09-07  9:40 ` [Buildroot] [PATCH v2 10/12] core: allow to use Clang " Romain Naour
2019-09-09 14:29   ` Matthew Weber
2020-08-29 21:13   ` Arnout Vandecappelle
2019-09-07  9:40 ` [Buildroot] [PATCH v2 11/12] toolchain: add a warning when Clang is used " Romain Naour
2019-09-07  9:40 ` [Buildroot] [PATCH v2 12/12] linux: don't set -Wno-attribute-alias flag " Romain Naour
2019-09-09 14:28   ` Matthew Weber
2020-08-29 18:53 ` [Buildroot] [PATCH v2 00/12] Add the support for Clang cross-compiler Arnout Vandecappelle
2020-09-14 19:53   ` Romain Naour

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=20190907094027.9537-5-romain.naour@smile.fr \
    --to=romain.naour@smile.fr \
    --cc=buildroot@busybox.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.