From patchwork Fri Apr 21 18:20:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Matthias Kaehlcke X-Patchwork-Id: 9693381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E67206038D for ; Fri, 21 Apr 2017 18:26:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DC83628636 for ; Fri, 21 Apr 2017 18:26:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFD9A28654; Fri, 21 Apr 2017 18:26:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6ACCB28636 for ; Fri, 21 Apr 2017 18:26:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423551AbdDUSVp (ORCPT ); Fri, 21 Apr 2017 14:21:45 -0400 Received: from mail-yb0-f176.google.com ([209.85.213.176]:35193 "EHLO mail-yb0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1162329AbdDUSVG (ORCPT ); Fri, 21 Apr 2017 14:21:06 -0400 Received: by mail-yb0-f176.google.com with SMTP id 6so46964923ybq.2 for ; Fri, 21 Apr 2017 11:21:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=f71T0P1KdkWSWnvXJv8k8ZCqq0V2pseTxc6DRXbasUk=; b=aG80H31VfkBzA1StrjTxUIM/hpBYQjn//AwjSrnabIstpDibJRIyezNabOynni3n8b DInTi/NBCP3kSe4iLbDpl1tWPLDQMOTAoAgwbamK2kj0zwKur3hV4k08p3dRVEZnHs3B 88krrt6/sUhP/gETFCGNFvU0CoAr8CfgWMOo2MBTAE/kEnY3F32FU4rrK9+fZH6NVgq9 2CWNsPSH/k4ehy17uAvTVDHsiZe0ktqQHVWTGx4rGr4pzxhQg5FaBMPqTPJk3DJvjFdS Ax3pc++gllzvA5UzhTNF8UyR5VYgNJuGqIiUabgCmR8xYK66mNpA5UgFZnaYDwrPF4Qh 4Xcg== X-Gm-Message-State: AN3rC/7pAW2vGbk2hUW7Aoj4MqOMoHHUJlVR+3FErAa+F6lx/NF3gWVe S5UHD+LZdLDDf0nG X-Received: by 10.98.59.9 with SMTP id i9mr14014796pfa.50.1492798849643; Fri, 21 Apr 2017 11:20:49 -0700 (PDT) Received: from mka.mtv.corp.google.com ([172.22.64.162]) by smtp.gmail.com with ESMTPSA id k1sm17351528pgk.42.2017.04.21.11.20.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 21 Apr 2017 11:20:48 -0700 (PDT) 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 Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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)