Skip to content

Commit 3812b8c

Browse files
committed
kbuild: make -r/-R effective in top Makefile for old Make versions
Adding -rR to MAKEFLAGS is important because we do not want to be bothered by built-in implicit rules or variables. One problem that used to exist in older GNU Make versions is MAKEFLAGS += -rR ... does not become effective in the current Makefile. When you are building with O= option, it becomes effective in the top Makefile since it recurses via 'sub-make' target. Otherwise, the top Makefile tries implicit rules. That is why we explicitly add empty rules for Makefiles, but we often miss to do that. In fact, adding -d option to older GNU Make versions shows it is trying a bunch of implicit pattern rules. Considering target file `scripts/Makefile.kcov'. Looking for an implicit rule for `scripts/Makefile.kcov'. Trying pattern rule with stem `Makefile.kcov'. Trying implicit prerequisite `scripts/Makefile.kcov.o'. Trying pattern rule with stem `Makefile.kcov'. Trying implicit prerequisite `scripts/Makefile.kcov.c'. Trying pattern rule with stem `Makefile.kcov'. Trying implicit prerequisite `scripts/Makefile.kcov.cc'. Trying pattern rule with stem `Makefile.kcov'. Trying implicit prerequisite `scripts/Makefile.kcov.C'. ... This issue was fixed by GNU Make commit 58dae243526b ("[Savannah #20501] Handle adding -r/-R to MAKEFLAGS in the makefile"). So, it is no longer a problem if you use GNU Make 4.0 or later. However, older versions are still widely used. So, I decided to patch the kernel Makefile to invoke sub-make regardless of O= option. This will allow further cleanups. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
1 parent f47a23c commit 3812b8c

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

Makefile

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,6 @@ NAME = Shy Crocodile
1515
PHONY := _all
1616
_all:
1717

18-
# Do not use make's built-in rules and variables
19-
# (this increases performance and avoids hard-to-debug behaviour)
20-
MAKEFLAGS += -rR
21-
22-
# Avoid funny character set dependencies
23-
unexport LC_ALL
24-
LC_COLLATE=C
25-
LC_NUMERIC=C
26-
export LC_COLLATE LC_NUMERIC
27-
28-
# Avoid interference with shell env settings
29-
unexport GREP_OPTIONS
30-
3118
# We are using a recursive build, so we need to do a little thinking
3219
# to get the ordering right.
3320
#
@@ -44,6 +31,21 @@ unexport GREP_OPTIONS
4431
# descending is started. They are now explicitly listed as the
4532
# prepare rule.
4633

34+
ifneq ($(sub-make-done),1)
35+
36+
# Do not use make's built-in rules and variables
37+
# (this increases performance and avoids hard-to-debug behaviour)
38+
MAKEFLAGS += -rR
39+
40+
# Avoid funny character set dependencies
41+
unexport LC_ALL
42+
LC_COLLATE=C
43+
LC_NUMERIC=C
44+
export LC_COLLATE LC_NUMERIC
45+
46+
# Avoid interference with shell env settings
47+
unexport GREP_OPTIONS
48+
4749
# Beautify output
4850
# ---------------------------------------------------------------------------
4951
#
@@ -111,7 +113,6 @@ export quiet Q KBUILD_VERBOSE
111113

112114
# KBUILD_SRC is not intended to be used by the regular user (for now),
113115
# it is set on invocation of make with KBUILD_OUTPUT or O= specified.
114-
ifeq ($(KBUILD_SRC),)
115116

116117
# OK, Make called in directory where kernel src resides
117118
# Do we want to locate output files in a separate directory?
@@ -141,23 +142,26 @@ $(if $(KBUILD_OUTPUT),, \
141142
# 'sub-make' below.
142143
MAKEFLAGS += --include-dir=$(CURDIR)
143144

145+
else
146+
147+
# Do not print "Entering directory ..." at all for in-tree build.
148+
MAKEFLAGS += --no-print-directory
149+
150+
endif # ifneq ($(KBUILD_OUTPUT),)
151+
144152
PHONY += $(MAKECMDGOALS) sub-make
145153

146154
$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
147155
@:
148156

149157
# Invoke a second make in the output directory, passing relevant variables
150158
sub-make:
151-
$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
159+
$(Q)$(MAKE) sub-make-done=1 \
160+
$(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
152161
-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
153162

154-
# Leave processing to above invocation of make
155-
skip-makefile := 1
156-
endif # ifneq ($(KBUILD_OUTPUT),)
157-
endif # ifeq ($(KBUILD_SRC),)
158-
163+
else # sub-make-done
159164
# We process the rest of the Makefile if this is the final invocation of make
160-
ifeq ($(skip-makefile),)
161165

162166
# Do not print "Entering directory ...",
163167
# but we want to display it when entering to the output directory
@@ -1762,7 +1766,7 @@ $(cmd_files): ; # Do not try to update included dependency files
17621766

17631767
endif # ifeq ($(config-targets),1)
17641768
endif # ifeq ($(mixed-targets),1)
1765-
endif # skip-makefile
1769+
endif # sub-make-done
17661770

17671771
PHONY += FORCE
17681772
FORCE:

0 commit comments

Comments
 (0)