From patchwork Fri Oct 13 18:02:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 10005567 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 37178602B3 for ; Fri, 13 Oct 2017 18:03:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 337FF29112 for ; Fri, 13 Oct 2017 18:03:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2848529114; Fri, 13 Oct 2017 18:03:20 +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.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 9075F29112 for ; Fri, 13 Oct 2017 18:03:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752537AbdJMSDS (ORCPT ); Fri, 13 Oct 2017 14:03:18 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:46534 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752081AbdJMSDR (ORCPT ); Fri, 13 Oct 2017 14:03:17 -0400 Received: by mail-pf0-f173.google.com with SMTP id p87so10987299pfj.3 for ; Fri, 13 Oct 2017 11:03:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=tDZIJBwfEchz5YhhwYAnaSrcAVgusOyffRqRmLrQcTs=; b=Hp23QIYg6tOydr1VJWTozSjACcPIas9LY+lfjDk+OSJzUrI/0SDARY+rklE4OOxSnD 1gUh4t5GNQCZZwKy5OrFJa0gGtREQtoskKEymaiLo8ZTF/CDcDBfcq3NcdVCBsbjvwCX ONp9/b+mnOMXpIlXD65EhagEQsVph1K8ie358= 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; bh=tDZIJBwfEchz5YhhwYAnaSrcAVgusOyffRqRmLrQcTs=; b=FcnUCg2bEqOxJDsiVykDtNqTf4heXTJsfPOAPzJNkc4DL0V6RGTIJanCDu27AvsRmt OaKtULqhi7nrGLZLcyHftertESeR32bfz6Ckx1a7wLELnSU6x8aen5NS/AZZuJrf8KU8 eCGL4/Bqe2PdZVrad0sxOQ2Aj8AUgXaDieDlz4ZsICYdEei0VzObGYNbVqLdHCeX1WuA 2akFAGtSXnTs2R3IHovxulrFkagJ9BOivjFiF7EtBIw+L8sHltiipHwzpGsvVKpURshN 0hZbb02BlEDDfN8apWdYITiG83pPvsJBoxb3J31vjvHD70yCpJmqw1vFlmrsN9xTcHVc Y3cw== X-Gm-Message-State: AMCzsaXbMoT++F3A6DErE0n3IzZj4N7uSzOuTs1skSVI/EUG5kEE2xQ3 rM5DUKr0EbnoL58zWMYPA5JDVA== X-Google-Smtp-Source: AOwi7QDBf5p0+xul7OapUOeHPQVabIkdqo2q0WagBIUgDNjipI89GnSsYYQ5qiki3PBCprOth69+zg== X-Received: by 10.84.224.65 with SMTP id a1mr2050665plt.421.1507917797093; Fri, 13 Oct 2017 11:03:17 -0700 (PDT) Received: from tictac.mtv.corp.google.com ([172.22.112.154]) by smtp.gmail.com with ESMTPSA id x27sm4322971pfe.172.2017.10.13.11.03.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Oct 2017 11:03:15 -0700 (PDT) From: Douglas Anderson To: yamada.masahiro@socionext.com Cc: groeck@chromium.org, vapier@chromium.org, mka@chromium.org, dtor@chromium.org, u.kleine-koenig@pengutronix.de, Douglas Anderson , linux-doc@vger.kernel.org, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Corbet , Michal Marek Subject: [RFC PATCH] kbuild: Allow specifying some base host CFLAGS Date: Fri, 13 Oct 2017 11:02:43 -0700 Message-Id: <20171013180243.25849-1-dianders@chromium.org> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog 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 Right now there is a way to add some CFLAGS that affect target builds, but no way to add CFLAGS that affect host builds. Let's add a way. We'll document two environment variables: CFLAGS_HOST and CXXFLAGS_HOST. We'll document that these variables get appended to by the kernel to make the final CFLAGS. That means that, though the environment can specify some flags, if there is a conflict the kernel can override and win. This works differently than KCFLAGS which is appended (and thus can override) the kernel specified CFLAGS. Why would I make KCFLAGS and CFLAGS_HOST work differently in this way? My argument is that it's about expected usage. Typically the build system invoking the kernel has some idea about some basic CFLAGS that it wants to use to build things for the host and things for the target. In general the build system would expect that its flags can be overridden if necessary (perhaps we need to turn off a warning when compiling a certain file, for instance). So, all other things being equal, the way I'm making CFLAGS_HOST is the way I'd expect things to work. So, if it's expected that the build system can pass in a base set of flags, why didn't we make KCFLAGS work that way? The short answer is: when building for the target the kernel is just "special". The build system's "target" CFLAGS are likely intended for userspace programs and likely make very little sense to use as a basis. This was talked about in the seminal commit 69ee0b352242 ("kbuild: do not pick up CFLAGS from the environment"). Basically: if the build system REALLY knows what it's doing then it can pass in flags that the kernel will use, but otherwise it should butt out. Presumably this build system that really knows what it's doing knows better than the kernel so KCFLAGS comes after the kernel's normal flags. One last note: I chose to add new variables rather than just having the build system try to pass HOSTCFLAGS in somehow (either through the environment or the command line) to avoid weird interactions with recursive invocations of make. Signed-off-by: Douglas Anderson --- Documentation/kbuild/kbuild.txt | 12 ++++++++++++ Makefile | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Documentation/kbuild/kbuild.txt b/Documentation/kbuild/kbuild.txt index ac2363ea05c5..70bf51c1b77d 100644 --- a/Documentation/kbuild/kbuild.txt +++ b/Documentation/kbuild/kbuild.txt @@ -54,6 +54,18 @@ LDFLAGS_vmlinux -------------------------------------------------- Additional options passed to final link of vmlinux. +CFLAGS_HOST +----------- +A base set of flags to pass when compiling C files for the host (not +the target). The kernel will append some of its own flags to this +set when actually calling the compiler. + +CXXFLAGS_HOST +------------- +A base set of flags to pass when compiling C++ files for the host (not +the target). The kernel will append some of its own flags to this +set when actually calling the compiler. + KBUILD_VERBOSE -------------------------------------------------- Set the kbuild verbosity. Can be assigned same values as "V=...". diff --git a/Makefile b/Makefile index 04c4191952e0..b5e9895b2a7f 100644 --- a/Makefile +++ b/Makefile @@ -359,9 +359,10 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS) HOSTCC = gcc HOSTCXX = g++ -HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ +HOSTCFLAGS := $(CFLAGS_HOST) \ + -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \ -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) -HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) +HOSTCXXFLAGS := $(CXXFLAGS_HOST) -O2 $(HOST_LFS_CFLAGS) HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) HOST_LOADLIBES := $(HOST_LFS_LIBS)