Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c451dba authored by Greg Hackmann's avatar Greg Hackmann Committed by Alistair Strachan
Browse files

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: default avatarGreg Hackmann <ghackmann@google.com>
[astrachan: Added a script to check for incorrectly falling back to the
            default when CLANG_TRIPLE is unset]
Bug: 118439987
Bug: 120440614
Test: make CLANG_TRIPLE=x86_64-linux-gnu CC=clang
Signed-off-by: default avatarAlistair Strachan <astrachan@google.com>
parent 13e7e057
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -482,7 +482,11 @@ endif


ifeq ($(cc-name),clang)
ifeq ($(cc-name),clang)
ifneq ($(CROSS_COMPILE),)
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_DIR := $(dir $(shell which $(LD)))
GCC_TOOLCHAIN_DIR := $(dir $(shell which $(LD)))
CLANG_PREFIX	:= --prefix=$(GCC_TOOLCHAIN_DIR)
CLANG_PREFIX	:= --prefix=$(GCC_TOOLCHAIN_DIR)
GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
GCC_TOOLCHAIN	:= $(realpath $(GCC_TOOLCHAIN_DIR)/..)
+4 −0
Original line number Original line Diff line number Diff line
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0

$* -dM -E - </dev/null 2>&1 | grep -q __ANDROID__ && echo "y"