kbuild: add read-file macro
authorMasahiro Yamada <masahiroy@kernel.org>
Sun, 11 Dec 2022 02:54:47 +0000 (11:54 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Tue, 13 Dec 2022 13:29:10 +0000 (22:29 +0900)
Since GNU Make 4.2, $(file ...) supports the read operater '<', which
is useful to read a file without forking a new process. No warning is
shown even if the input file is missing.

For older Make versions, it falls back to the cat command.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
Reviewed-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Tested-by: Alexander Lobakin <alexandr.lobakin@intel.com>
Makefile
scripts/Kbuild.include
scripts/Makefile.modfinal
scripts/Makefile.modinst

index ff36288ae671f35703cd2c3854246959f9b1dad8..591485152a95c3bfc3cad088d13f82e98cc69891 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -376,7 +376,7 @@ else # !mixed-build
 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)
+KERNELRELEASE = $(call read-file, include/config/kernel.release)
 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
 
index 3be7c2d7566794d5a0cbdd1d9d5e81f1192900e4..21e76ba0de170b133aaabb4e36d9b5728fcc0e6c 100644 (file)
@@ -10,6 +10,10 @@ empty   :=
 space   := $(empty) $(empty)
 space_escape := _-_SPACE_-_
 pound := \#
+define newline
+
+
+endef
 
 ###
 # Comparison macros.
@@ -61,6 +65,16 @@ stringify = $(squote)$(quote)$1$(quote)$(squote)
 kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
 kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
 
+###
+# Read a file, replacing newlines with spaces
+#
+# Make 4.2 or later can read a file by using its builtin function.
+ifneq ($(filter-out 3.% 4.0 4.1, $(MAKE_VERSION)),)
+read-file = $(subst $(newline),$(space),$(file < $1))
+else
+read-file = $(shell cat $1 2>/dev/null)
+endif
+
 ###
 # Easy method for doing a status message
        kecho := :
index 4705d32388f36f8de4603bcc924d0cb217bbacf1..83f2797e530c532ff9d638450d8ec2754034808c 100644 (file)
@@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include
 include $(srctree)/scripts/Makefile.lib
 
 # find all modules listed in modules.order
-modules := $(shell cat $(MODORDER))
+modules := $(call read-file, $(MODORDER))
 
 __modfinal: $(modules)
        @:
index f4cff42069adfa72f292bf1a0584189082344a3e..65aac6be78ec3e968ace758f003025d0b195938a 100644 (file)
@@ -9,7 +9,7 @@ __modinst:
 include include/config/auto.conf
 include $(srctree)/scripts/Kbuild.include
 
-modules := $(shell cat $(MODORDER))
+modules := $(call read-file, $(MODORDER))
 
 ifeq ($(KBUILD_EXTMOD),)
 dst := $(MODLIB)/kernel