Skip to content

Commit 6768fa4

Browse files
committed
kbuild: add read-file macro
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 <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Reviewed-by: Alexander Lobakin <[email protected]> Tested-by: Alexander Lobakin <[email protected]>
1 parent a5db80c commit 6768fa4

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ else # !mixed-build
376376
include $(srctree)/scripts/Kbuild.include
377377

378378
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
379-
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
379+
KERNELRELEASE = $(call read-file, include/config/kernel.release)
380380
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
381381
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
382382

scripts/Kbuild.include

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ empty :=
1010
space := $(empty) $(empty)
1111
space_escape := _-_SPACE_-_
1212
pound := \#
13+
define newline
14+
15+
16+
endef
1317

1418
###
1519
# Comparison macros.
@@ -61,6 +65,16 @@ stringify = $(squote)$(quote)$1$(quote)$(squote)
6165
kbuild-dir = $(if $(filter /%,$(src)),$(src),$(srctree)/$(src))
6266
kbuild-file = $(or $(wildcard $(kbuild-dir)/Kbuild),$(kbuild-dir)/Makefile)
6367

68+
###
69+
# Read a file, replacing newlines with spaces
70+
#
71+
# Make 4.2 or later can read a file by using its builtin function.
72+
ifneq ($(filter-out 3.% 4.0 4.1, $(MAKE_VERSION)),)
73+
read-file = $(subst $(newline),$(space),$(file < $1))
74+
else
75+
read-file = $(shell cat $1 2>/dev/null)
76+
endif
77+
6478
###
6579
# Easy method for doing a status message
6680
kecho := :

scripts/Makefile.modfinal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ include $(srctree)/scripts/Kbuild.include
1313
include $(srctree)/scripts/Makefile.lib
1414

1515
# find all modules listed in modules.order
16-
modules := $(shell cat $(MODORDER))
16+
modules := $(call read-file, $(MODORDER))
1717

1818
__modfinal: $(modules)
1919
@:

scripts/Makefile.modinst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ __modinst:
99
include include/config/auto.conf
1010
include $(srctree)/scripts/Kbuild.include
1111

12-
modules := $(shell cat $(MODORDER))
12+
modules := $(call read-file, $(MODORDER))
1313

1414
ifeq ($(KBUILD_EXTMOD),)
1515
dst := $(MODLIB)/kernel

0 commit comments

Comments
 (0)