summaryrefslogtreecommitdiff
authorGreg Hackmann <ghackmann@google.com>2016-10-25 20:59:59 (GMT)
committer Alistair Strachan <astrachan@google.com>2018-11-29 01:35:40 (GMT)
commit4dcb0afde6f464bdb512ebedab5b6ebfda3b8797 (patch)
tree2ec9bc78796f4284d32ee05f42480d8703364154
parenta99d71b187de5b3e44e475e58558f6a6d945e3fd (diff)
downloadcommon-4dcb0afde6f464bdb512ebedab5b6ebfda3b8797.zip
common-4dcb0afde6f464bdb512ebedab5b6ebfda3b8797.tar.gz
common-4dcb0afde6f464bdb512ebedab5b6ebfda3b8797.tar.bz2
ANDROID: Kbuild, LLVMLinux: allow overriding clang target triple
Android has an unusual setup where the kernel needs to target [arch]-linux-gnu to avoid Android userspace-specific flags and optimizations, but AOSP doesn't ship a matching binutils. Add a new variable CLANG_TRIPLE which can override the "-target" triple used to compile the kernel, while using a different CROSS_COMPILE to pick the binutils/gcc installation. For Android you'd do something like: export CLANG_TRIPLE=aarch64-linux-gnu- export CROSS_COMPILE=aarch64-linux-android- If you don't need something like this, leave CLANG_TRIPLE unset and it will default to CROSS_COMPILE. Change-Id: I85d63599c6ab8ed458071cdf9197d85b1f7f150b Signed-off-by: Greg Hackmann <ghackmann@google.com> [astrachan: Added a script to check for incorrectly falling back to the default when CLANG_TRIPLE is unset] Bug: 118442619 Signed-off-by: Alistair Strachan <astrachan@google.com>
Diffstat
-rw-r--r--Makefile6
-rwxr-xr-xscripts/clang-android.sh4
2 files changed, 9 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 8df2ab9..d3de4b1 100644
--- a/Makefile
+++ b/Makefile
@@ -768,7 +768,11 @@ KBUILD_CFLAGS += $(stackp-flag)
ifeq ($(cc-name),clang)
ifneq ($(CROSS_COMPILE),)
-CLANG_TARGET := --target=$(notdir $(CROSS_COMPILE:%-=%))
+CLANG_TRIPLE ?= $(CROSS_COMPILE)
+CLANG_TARGET := --target=$(notdir $(CLANG_TRIPLE:%-=%))
+ifeq ($(shell $(srctree)/scripts/clang-android.sh $(CC) $(CLANG_TARGET)), y)
+$(error "Clang with Android --target detected. Did you specify CLANG_TRIPLE?")
+endif
GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..)
endif
ifneq ($(GCC_TOOLCHAIN),)
diff --git a/scripts/clang-android.sh b/scripts/clang-android.sh
new file mode 100755
index 0000000..9186c4f
--- a/dev/null
+++ b/scripts/clang-android.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+
+$* -dM -E - </dev/null 2>&1 | grep -q __ANDROID__ && echo "y"