From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423639AbdDUSWF (ORCPT ); Fri, 21 Apr 2017 14:22:05 -0400 Received: from mail-yb0-f169.google.com ([209.85.213.169]:34369 "EHLO mail-yb0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162330AbdDUSVG (ORCPT ); Fri, 21 Apr 2017 14:21:06 -0400 From: Matthias Kaehlcke To: Masahiro Yamada , Michal Marek Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Behan Webster , Grant Grundler , Greg Hackmann , Michael Davidson , Peter Foley , Matthias Kaehlcke Subject: [PATCH v2] kbuild: Add better clang cross build support Date: Fri, 21 Apr 2017 11:20:01 -0700 Message-Id: <20170421182001.139199-1-mka@chromium.org> X-Mailer: git-send-email 2.12.2.816.g2cccc81164-goog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add cross target to CC if using clang. Also add custom gcc toolchain path for fallback gcc tools. Clang will fallback to using things like ld, as, and libgcc if (respectively) one of the llvm linkers isn't available, the integrated assembler is turned off, or an appropriately cross-compiled version of compiler-rt isn't available. To this end, you can specify the path to this fallback gcc toolchain with GCC_TOOLCHAIN. From: Behan Webster Signed-off-by: Behan Webster Reviewed-by: Jan-Simon Möller Reviewed-by: Mark Charlebois Signed-off-by: Greg Hackmann Signed-off-by: Matthias Kaehlcke --- Changes in v2: - Moved new 'code' into existing ifeq clang block - Don't add -target and -gcc-toolchain to KBUILD_CPPFLAGS - Removed intermediate CLANG_FLAGS variable - Updated commit message, removed paragraph mentioning old COMPILER variable Makefile | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Makefile b/Makefile index 5039b9148d15..11c00bd3ec0c 100644 --- a/Makefile +++ b/Makefile @@ -698,6 +698,15 @@ endif KBUILD_CFLAGS += $(stackp-flag) ifeq ($(cc-name),clang) +ifneq ($(CROSS_COMPILE),) +CLANG_TARGET := -target $(notdir $(CROSS_COMPILE:%-=%)) +GCC_TOOLCHAIN := $(realpath $(dir $(shell which $(LD)))/..) +endif +ifneq ($(GCC_TOOLCHAIN),) +CLANG_GCC_TC := -gcc-toolchain $(GCC_TOOLCHAIN) +endif +KBUILD_CFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) +KBUILD_AFLAGS += $(CLANG_TARGET) $(CLANG_GCC_TC) KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,) KBUILD_CPPFLAGS += $(call cc-option,-Wno-unknown-warning-option,) KBUILD_CFLAGS += $(call cc-disable-warning, unused-variable) -- 2.12.2.816.g2cccc81164-goog