From patchwork Sun Feb 28 06:10:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12108113 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00D9AC433DB for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3A3B64E55 for ; Sun, 28 Feb 2021 06:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229820AbhB1GLp (ORCPT ); Sun, 28 Feb 2021 01:11:45 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:55340 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbhB1GLp (ORCPT ); Sun, 28 Feb 2021 01:11:45 -0500 Received: from oscar.flets-west.jp (softbank126026090165.bbtec.net [126.26.90.165]) (authenticated) by conuserg-07.nifty.com with ESMTP id 11S6Aagr009638; Sun, 28 Feb 2021 15:10:36 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com 11S6Aagr009638 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1614492636; bh=KEDTQhMtT2eYViKsns8H0yabNkx1k3NTqKR6OviKKQ4=; h=From:To:Cc:Subject:Date:From; b=Md5mhQERflDIRQYPFLyHsJX9rEnKHYRphyE3GUMFvUlkr6yXaUtjOoyKQ2mpPCMf+ tOiOBP9CCxgWVI7vRjKj22eU3hH6ctver4bw0x7zgAWkYnv2oekVbON9VEI+IEG/pY bw//qy24klyKYQsQJ9bFSx48Pz1es9KTaLUYuRUfcw9ztauVaEidJ12mJZTxU2M5we TTQYuccxhIiGxb/4i/1xR9G5ZK6iMlWaVa6VToUiQtBNMZsc6iEfdp20t96yEgN4pn UHa0PHNmnIAaxwWK2DOybOBLntmCgTscoNb9pOmaecnVMz6CHp87GHQBSFGTHGOKbn 8lMordguOrclg== X-Nifty-SrcIP: [126.26.90.165] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek Subject: [PATCH 1/4] kbuild: add image_name to no-sync-config-targets Date: Sun, 28 Feb 2021 15:10:25 +0900 Message-Id: <20210228061028.239459-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org 'make image_name' needs include/config/auto.conf to show the correct output because KBUILD_IMAGE depends on CONFIG options, but should not attempt to resync the configuration. Signed-off-by: Masahiro Yamada --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 633d2769b6ec..c84a9311df29 100644 --- a/Makefile +++ b/Makefile @@ -263,7 +263,8 @@ no-dot-config-targets := $(clean-targets) \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ outputmakefile -no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease +no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ + image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ config-build := From patchwork Sun Feb 28 06:10:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12108117 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA209C433E6 for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8F1F564E7A for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230173AbhB1GLr (ORCPT ); Sun, 28 Feb 2021 01:11:47 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:55337 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbhB1GLq (ORCPT ); Sun, 28 Feb 2021 01:11:46 -0500 Received: from oscar.flets-west.jp (softbank126026090165.bbtec.net [126.26.90.165]) (authenticated) by conuserg-07.nifty.com with ESMTP id 11S6Aags009638; Sun, 28 Feb 2021 15:10:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com 11S6Aags009638 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1614492637; bh=aUTqDhVEnLjOAyKo+0/IlpAwcOFUETFtjuQZffEl/jQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=esZTnLAK45Mms294tzR7hhyE8rwpcc5oOzxZLAnroGNjU8p+VRcFLG0xFHJCMS90g fDppRTZb3eWZAa5RTt7j+MIbkPmEVHvYAZZTyRYjvke7sH4j1FUdHHdrbQVRYuX3Km MtMt8562eGlPgGiKNqtY9E4noqR1wB9sWKSYSfUJaF8op1pBngzerQML+5DnQnYuei JeyU87D9e0qZdEWD8q1+zXDB+GoG8AZh9RObYjp5yfMOQPmRWlYISIBRC8n5A4mpdf Ml8UJKxwvI3JACHVwdlRapayB6yQO/jY5egajKTqKJ5BTzL6uo+pKSaprM5HHjY8i/ bilEWQDf6Bmkw== X-Nifty-SrcIP: [126.26.90.165] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek Subject: [PATCH 2/4] kbuild: prefix $(srctree)/ to some included Makefiles Date: Sun, 28 Feb 2021 15:10:26 +0900 Message-Id: <20210228061028.239459-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210228061028.239459-1-masahiroy@kernel.org> References: <20210228061028.239459-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org VPATH is used in Kbuild to make pattern rules to search for prerequisites in both $(objtree) and $(srctree). Some source files may not be real sources, but generated by tools such as flex, bison, perl. In contrast, I doubt the benefit of --include-dir=$(abs_srctree) because it is always clear which Makefiles are real sources, and which are not. So, my hope is to add $(srctree)/ prefix to all check-in Makefiles, then remove --include-dir=$(abs_srctree) flag in the future. I am touching only some Kbuild core parts for now. Treewide fixes will be needed to achieve this goal. Signed-off-by: Masahiro Yamada --- Makefile | 8 ++++---- scripts/Makefile.asm-generic | 4 ++-- scripts/Makefile.build | 8 ++++---- scripts/Makefile.clean | 2 +- scripts/Makefile.dtbinst | 2 +- scripts/Makefile.headersinst | 2 +- scripts/Makefile.modinst | 2 +- scripts/Makefile.modpost | 4 ++-- scripts/Makefile.modsign | 2 +- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c84a9311df29..2253e31a6bcf 100644 --- a/Makefile +++ b/Makefile @@ -338,14 +338,14 @@ __build_one_by_one: else # !mixed-build -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # Read KERNELRELEASE from include/config/kernel.release (if it exists) KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null) KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION -include scripts/subarch.include +include $(srctree)/scripts/subarch.include # Cross compiling and selecting different set of gcc/bin-utils # --------------------------------------------------------------------------- @@ -590,7 +590,7 @@ ifdef config-build # Read arch specific Makefile to set KBUILD_DEFCONFIG as needed. # KBUILD_DEFCONFIG may point out an alternative default configuration # used for 'make defconfig' -include arch/$(SRCARCH)/Makefile +include $(srctree)/arch/$(SRCARCH)/Makefile export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT config: outputmakefile scripts_basic FORCE @@ -677,7 +677,7 @@ RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc export RETPOLINE_CFLAGS export RETPOLINE_VDSO_CFLAGS -include arch/$(SRCARCH)/Makefile +include $(srctree)/arch/$(SRCARCH)/Makefile ifdef need-config ifdef may-sync-config diff --git a/scripts/Makefile.asm-generic b/scripts/Makefile.asm-generic index 82ad63dcd62b..1d501c57f9ef 100644 --- a/scripts/Makefile.asm-generic +++ b/scripts/Makefile.asm-generic @@ -14,10 +14,10 @@ src := $(subst /generated,,$(obj)) # $(generic)/Kbuild lists mandatory-y. Exclude um since it is a special case. ifneq ($(SRCARCH),um) -include $(generic)/Kbuild +include $(srctree)/$(generic)/Kbuild endif -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include redundant := $(filter $(mandatory-y) $(generated-y), $(generic-y)) redundant += $(foreach f, $(generic-y), $(if $(wildcard $(srctree)/$(src)/$(f)),$(f))) diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 1b6094a13034..750d6d5225af 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -35,27 +35,27 @@ subdir-ccflags-y := # Read auto.conf if it exists, otherwise ignore -include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) kbuild-file := $(if $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Kbuild,$(kbuild-dir)/Makefile) include $(kbuild-file) -include scripts/Makefile.lib +include $(srctree)/scripts/Makefile.lib # Do not include hostprogs rules unless needed. # $(sort ...) is used here to remove duplicated words and excessive spaces. hostprogs := $(sort $(hostprogs)) ifneq ($(hostprogs),) -include scripts/Makefile.host +include $(srctree)/scripts/Makefile.host endif # Do not include userprogs rules unless needed. # $(sort ...) is used here to remove duplicated words and excessive spaces. userprogs := $(sort $(userprogs)) ifneq ($(userprogs),) -include scripts/Makefile.userprogs +include $(srctree)/scripts/Makefile.userprogs endif ifndef obj diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean index 22a8172bce1f..fd6175322470 100644 --- a/scripts/Makefile.clean +++ b/scripts/Makefile.clean @@ -8,7 +8,7 @@ src := $(obj) PHONY := __clean __clean: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) diff --git a/scripts/Makefile.dtbinst b/scripts/Makefile.dtbinst index ba01f5ba2517..190d781e84f4 100644 --- a/scripts/Makefile.dtbinst +++ b/scripts/Makefile.dtbinst @@ -14,7 +14,7 @@ PHONY := __dtbs_install __dtbs_install: include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include include $(src)/Makefile dtbs := $(addprefix $(dst)/, $(dtb-y) $(if $(CONFIG_OF_ALL_DTBS),$(dtb-))) diff --git a/scripts/Makefile.headersinst b/scripts/Makefile.headersinst index 708fbd08a2c5..029d85bb0b23 100644 --- a/scripts/Makefile.headersinst +++ b/scripts/Makefile.headersinst @@ -12,7 +12,7 @@ PHONY := __headers __headers: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include src := $(srctree)/$(obj) gen := $(objtree)/$(subst include/,include/generated/,$(obj)) diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst index 5a4579e76485..ad1981233d0b 100644 --- a/scripts/Makefile.modinst +++ b/scripts/Makefile.modinst @@ -6,7 +6,7 @@ PHONY := __modinst __modinst: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include modules := $(sort $(shell cat $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)modules.order)) diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost index 066beffca09a..df57e259fac3 100644 --- a/scripts/Makefile.modpost +++ b/scripts/Makefile.modpost @@ -41,10 +41,10 @@ PHONY := __modpost __modpost: include include/config/auto.conf -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include # for ld_flags -include scripts/Makefile.lib +include $(srctree)/scripts/Makefile.lib MODPOST = scripts/mod/modpost \ $(if $(CONFIG_MODVERSIONS),-m) \ diff --git a/scripts/Makefile.modsign b/scripts/Makefile.modsign index d7325cefe709..ddf9b5ca77d7 100644 --- a/scripts/Makefile.modsign +++ b/scripts/Makefile.modsign @@ -6,7 +6,7 @@ PHONY := __modsign __modsign: -include scripts/Kbuild.include +include $(srctree)/scripts/Kbuild.include modules := $(sort $(shell cat modules.order)) From patchwork Sun Feb 28 06:10:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12108119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7DC6C433E9 for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AF8B64E76 for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230107AbhB1GLr (ORCPT ); Sun, 28 Feb 2021 01:11:47 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:55338 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhB1GLq (ORCPT ); Sun, 28 Feb 2021 01:11:46 -0500 Received: from oscar.flets-west.jp (softbank126026090165.bbtec.net [126.26.90.165]) (authenticated) by conuserg-07.nifty.com with ESMTP id 11S6Aagt009638; Sun, 28 Feb 2021 15:10:37 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com 11S6Aagt009638 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1614492637; bh=FJq1WB6jfuuQwA03yL38QkuEaI3B/IvVwfnLKPEhnqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zWqk94IXNju6rrod56k/XYMKz3fEZ0bLHtWdJ4nkcKY102BetYLxLHpkooOw5kJkO aV0U4EdCKBcssoSEoDbWEJ/YQg/sLu9TwECwDxdmBLz2siwfl9S6OtmSgC6W6AKrLj W8ftunhw3cOIJhVUcT0LRI1ZYQXEMkX4IRM/IcI53DLHznkheVmmIzMg1M8MsjqHRU PVUPPZ1l+Vbdc6FtKiyaDQFBrPYDGFfP4+f5YWpQYM/tk1M5gF8dO32dL2aCI9mmm/ V00LffCEAAEQg+jjSjVoXAA6dSJ6aE5pHCTKj/IBVkeforVCTDTC1bpCJqZIlADm0a hOUVGaEhN7pcQ== X-Nifty-SrcIP: [126.26.90.165] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek Subject: [PATCH 3/4] kbuild: spilt cc-option and friends to scripts/Makefile.compiler Date: Sun, 28 Feb 2021 15:10:27 +0900 Message-Id: <20210228061028.239459-3-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210228061028.239459-1-masahiroy@kernel.org> References: <20210228061028.239459-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org scripts/Kbuild.include is included everywhere, but macros such as cc-option are needed by build targets only. For example, when 'make clean' traverses the tree, it does not need to evaluate $(call cc-option,). Split cc-option, ld-option, etc. to scripts/Makefile.compiler, which is only included from the top Makefile and scripts/Makefile.build. Signed-off-by: Masahiro Yamada --- Makefile | 4 ++ scripts/Kbuild.include | 80 --------------------------------------- scripts/Makefile.build | 1 + scripts/Makefile.compiler | 77 +++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 80 deletions(-) create mode 100644 scripts/Makefile.compiler diff --git a/Makefile b/Makefile index 2253e31a6bcf..eec7a94f5c33 100644 --- a/Makefile +++ b/Makefile @@ -582,6 +582,10 @@ KBUILD_AFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS endif +# Include this also for config targets because some architectures need +# cc-cross-prefix to determine CROSS_COMPILE. +include $(srctree)/scripts/Makefile.compiler + ifdef config-build # =========================================================================== # *config targets only - make sure prerequisites are updated, and descend diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include index 509e0856d653..82dd1b65b7a8 100644 --- a/scripts/Kbuild.include +++ b/scripts/Kbuild.include @@ -67,86 +67,6 @@ define filechk fi endef -###### -# gcc support functions -# See documentation in Documentation/kbuild/makefiles.rst - -# cc-cross-prefix -# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) -# Return first where a gcc is found in PATH. -# If no gcc found in PATH with listed prefixes return nothing -# -# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it -# would try to directly execute the shell builtin 'command'. This workaround -# should be kept for a long time since this issue was fixed only after the -# GNU Make 4.2.1 release. -cc-cross-prefix = $(firstword $(foreach c, $(1), \ - $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) - -# output directory for tests below -TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ - -# try-run -# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) -# Exit code chooses option. "$$TMP" serves as a temporary file and is -# automatically cleaned up. -try-run = $(shell set -e; \ - TMP=$(TMPOUT)/tmp; \ - TMPO=$(TMPOUT)/tmp.o; \ - mkdir -p $(TMPOUT); \ - trap "rm -rf $(TMPOUT)" EXIT; \ - if ($(1)) >/dev/null 2>&1; \ - then echo "$(2)"; \ - else echo "$(3)"; \ - fi) - -# as-option -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) - -as-option = $(call try-run,\ - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) - -# as-instr -# Usage: cflags-y += $(call as-instr,instr,option1,option2) - -as-instr = $(call try-run,\ - printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) - -# __cc-option -# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) -__cc-option = $(call try-run,\ - $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) - -# cc-option -# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) - -cc-option = $(call __cc-option, $(CC),\ - $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) - -# cc-option-yn -# Usage: flag := $(call cc-option-yn,-march=winchip-c6) -cc-option-yn = $(call try-run,\ - $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) - -# cc-disable-warning -# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) -cc-disable-warning = $(call try-run,\ - $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) - -# cc-ifversion -# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) -cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) - -# ld-option -# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) -ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) - -# ld-ifversion -# Usage: $(call ld-ifversion, -ge, 22252, y) -ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4)) - -###### - ### # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= # Usage: diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 750d6d5225af..d74d3383666e 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -36,6 +36,7 @@ subdir-ccflags-y := -include include/config/auto.conf include $(srctree)/scripts/Kbuild.include +include $(srctree)/scripts/Makefile.compiler # The filename Kbuild has precedence over Makefile kbuild-dir := $(if $(filter /%,$(src)),$(src),$(srctree)/$(src)) diff --git a/scripts/Makefile.compiler b/scripts/Makefile.compiler new file mode 100644 index 000000000000..5f759ecc4f04 --- /dev/null +++ b/scripts/Makefile.compiler @@ -0,0 +1,77 @@ +###### +# gcc support functions +# See documentation in Documentation/kbuild/makefiles.rst + +# cc-cross-prefix +# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) +# Return first where a gcc is found in PATH. +# If no gcc found in PATH with listed prefixes return nothing +# +# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it +# would try to directly execute the shell builtin 'command'. This workaround +# should be kept for a long time since this issue was fixed only after the +# GNU Make 4.2.1 release. +cc-cross-prefix = $(firstword $(foreach c, $(1), \ + $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) + +# output directory for tests below +TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ + +# try-run +# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) +# Exit code chooses option. "$$TMP" serves as a temporary file and is +# automatically cleaned up. +try-run = $(shell set -e; \ + TMP=$(TMPOUT)/tmp; \ + TMPO=$(TMPOUT)/tmp.o; \ + mkdir -p $(TMPOUT); \ + trap "rm -rf $(TMPOUT)" EXIT; \ + if ($(1)) >/dev/null 2>&1; \ + then echo "$(2)"; \ + else echo "$(3)"; \ + fi) + +# as-option +# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) + +as-option = $(call try-run,\ + $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) + +# as-instr +# Usage: cflags-y += $(call as-instr,instr,option1,option2) + +as-instr = $(call try-run,\ + printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) + +# __cc-option +# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) +__cc-option = $(call try-run,\ + $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) + +# cc-option +# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) + +cc-option = $(call __cc-option, $(CC),\ + $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) + +# cc-option-yn +# Usage: flag := $(call cc-option-yn,-march=winchip-c6) +cc-option-yn = $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) + +# cc-disable-warning +# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) +cc-disable-warning = $(call try-run,\ + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) + +# cc-ifversion +# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) +cc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) + +# ld-option +# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) +ld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) + +# ld-ifversion +# Usage: $(call ld-ifversion, -ge, 22252, y) +ld-ifversion = $(shell [ $(CONFIG_LD_VERSION)0 $(1) $(2)0 ] && echo $(3) || echo $(4)) From patchwork Sun Feb 28 06:10:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 12108115 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D7DDC433E0 for ; Sun, 28 Feb 2021 06:12:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6674464E55 for ; Sun, 28 Feb 2021 06:12:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230087AbhB1GLq (ORCPT ); Sun, 28 Feb 2021 01:11:46 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:55342 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229785AbhB1GLp (ORCPT ); Sun, 28 Feb 2021 01:11:45 -0500 Received: from oscar.flets-west.jp (softbank126026090165.bbtec.net [126.26.90.165]) (authenticated) by conuserg-07.nifty.com with ESMTP id 11S6Aagu009638; Sun, 28 Feb 2021 15:10:38 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com 11S6Aagu009638 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1614492638; bh=wFJmglFoEgW+JEoX5Ob1iT5jv3nE+Vz/BGorJFXpFlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kMvjtPYaDJ63B6Q0ElakJfGu9jywC7hvm+/lcNi9H+GtXV2g1OObL/rmuJHB19UxC atCn9fMTdr9jNirZXBU09uKjd8AVc1WuojPA1UvhToQBZdG7wHrZZI/XdJ+Yn1I5gN juDofy0mLCPBdelV67wUT9baEdcooNTyrJLixsrhn1KMUiupaECy8ZE4l+n+JSij7j x9t/SbWmrEjKSrA17JV9IA0pSG3zNZFfAF03G0Qvur2oGtXCl2ypRw1MrDqqfujiUA RxXiAD0gOxirqhfYRNRWOOkkSYvp4ykdohVi7Az5g2kR0nPQyHgdg1c6vxcWBaZnIT VjCfClEEgi8PQ== X-Nifty-SrcIP: [126.26.90.165] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada , Michal Marek Subject: [PATCH 4/4] kbuild: include Makefile.compiler only when compiler is required Date: Sun, 28 Feb 2021 15:10:28 +0900 Message-Id: <20210228061028.239459-4-masahiroy@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210228061028.239459-1-masahiroy@kernel.org> References: <20210228061028.239459-1-masahiroy@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org Since commit f2f02ebd8f38 ("kbuild: improve cc-option to clean up all temporary files"), running 'make kernelversion' in a read-only source tree emits a bunch of warnings: mkdir: cannot create directory '.tmp_12345': Permission denied Non-build targets such as kernelversion, clean, help, etc. do not need to evaluate $(call cc-option,) and friends. Do not include Makefile.compiler so $(call cc-option,) becomes no-op. This not only fix the warnings, but also runs non-build targets much faster. Basically, all installation targets should also be non-build targets. Unfortunately, vdso_install requires the compiler because it builds vdso before installtion. This is a problem that must be fixed by a separate patch. Signed-off-by: Masahiro Yamada Reported-by: Israel Tsadok --- I am not adding Reported-by for now because a reporter sent me an email privately. If he allows me to add Reported-by, I will add it to record the credit. (Perhaps, another person might have reported a similar issue somewhere, but my memory is obsure. I cannot recall it.) Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Makefile b/Makefile index eec7a94f5c33..20724711dc71 100644 --- a/Makefile +++ b/Makefile @@ -263,6 +263,10 @@ no-dot-config-targets := $(clean-targets) \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ outputmakefile +# Installation targets should not require compiler. Unfortunately, vdso_install +# is an exception where build artifacts may be updated. This must be fixed. +no-compiler-targets := $(no-dot-config-targets) install dtbs_install \ + headers_install modules_install kernelrelease image_name no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \ image_name single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ @@ -270,6 +274,7 @@ single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/ config-build := mixed-build := need-config := 1 +need-compiler := 1 may-sync-config := 1 single-build := @@ -279,6 +284,12 @@ ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) endif endif +ifneq ($(filter $(no-compiler-targets), $(MAKECMDGOALS)),) + ifeq ($(filter-out $(no-compiler-targets), $(MAKECMDGOALS)),) + need-compiler := + endif +endif + ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) may-sync-config := @@ -584,7 +595,9 @@ endif # Include this also for config targets because some architectures need # cc-cross-prefix to determine CROSS_COMPILE. +ifdef need-compiler include $(srctree)/scripts/Makefile.compiler +endif ifdef config-build # ===========================================================================