Skip to content

Commit 0b35786

Browse files
Milton MillerSam Ravnborg
authored andcommitted
kbuild: call make once for all targets when O=.. is used
Change the invocations of make in the output directory Makefile and the main Makefile for separate object trees to pass all goals to one $(MAKE) via a new phony target "sub-make" and the existing target _all. When compiling with separate object directories, a separate make is called in the context of another directory (from the output directory the main Makefile is called, the Makefile is then restarted with current directory set to the object tree). Before this patch, when multiple make command goals are specified, each target results in a separate make invocation. With make -j, these invocations may run in parallel, resulting in multiple commands running in the same directory clobbering each others results. I did not try to address make -j for mixed dot-config and no-dot-config targets. Because the order does matter, a solution was not obvious. Perhaps a simple check for MAKEFLAGS having -j and refusing to run would be appropriate. Signed-off-by: Milton Miller <miltonm@bga.com> Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
1 parent cf851aa commit 0b35786

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎Makefile‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ $(if $(KBUILD_OUTPUT),, \
118118
# Check that OUTPUT directory is not the same as where we have kernel src
119119
$(if $(filter-out $(KBUILD_OUTPUT),$(shell /bin/pwd)),, \
120120
$(error Output directory (O=...) specifies kernel src dir))
121-
PHONY += $(MAKECMDGOALS)
122121

123-
$(filter-out _all,$(MAKECMDGOALS)) _all:
122+
PHONY += $(MAKECMDGOALS) sub-make
123+
124+
$(filter-out _all sub-make,$(MAKECMDGOALS)) _all: sub-make
125+
$(Q)@:
126+
127+
sub-make: FORCE
124128
$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
125129
KBUILD_SRC=$(CURDIR) \
126-
KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile $@
130+
KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
131+
$(filter-out _all sub-make,$(MAKECMDGOALS))
127132

128133
# Leave processing to above invocation of make
129134
skip-makefile := 1

‎scripts/mkmakefile‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ MAKEFLAGS += --no-print-directory
2626
2727
.PHONY: all \$(MAKECMDGOALS)
2828
29+
all := \$(filter-out all Makefile,\$(MAKECMDGOALS))
30+
2931
all:
30-
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT)
32+
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$(all)
3133
3234
Makefile:;
3335
34-
\$(filter-out all Makefile,\$(MAKECMDGOALS)) %/:
35-
\$(MAKE) -C \$(KERNELSRC) O=\$(KERNELOUTPUT) \$@
36+
\$(all) %/: all
37+
@:
3638
EOF

0 commit comments

Comments
 (0)