Browse Source

[build] Properly handle multiple goals per BIN directory

When building multiple targets per BIN with multiple jobs, for
example:

  make -j16 bin-i386-efi/ipxe.efi{,drv,rom} bin-x86_64-efi/ipxe.efi{,drv,rom}

we would invoke a make subprocess for each goal in parallel resulting
in multiple makes running in a single BIN directory.  Fix by grouping
goals per BIN directory and invoking only one make per BIN.  It is
both safer and faster.

Signed-off-by: Piotr Jaroszyński <p.jaroszynski@gmail.com>
Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Piotr Jaroszyński 14 years ago
parent
commit
2d98d4a018
2 changed files with 17 additions and 6 deletions
  1. 1
    0
      src/Makefile
  2. 16
    6
      src/Makefile.housekeeping

+ 1
- 0
src/Makefile View File

21
 ECHO		:= echo
21
 ECHO		:= echo
22
 PRINTF		:= printf
22
 PRINTF		:= printf
23
 PERL		:= perl
23
 PERL		:= perl
24
+TRUE		:= true
24
 CC		:= $(CROSS_COMPILE)gcc
25
 CC		:= $(CROSS_COMPILE)gcc
25
 CPP		:= $(CC) -E
26
 CPP		:= $(CC) -E
26
 AS		:= $(CROSS_COMPILE)as
27
 AS		:= $(CROSS_COMPILE)as

+ 16
- 6
src/Makefile.housekeeping View File

174
 # make goals.
174
 # make goals.
175
 #
175
 #
176
 BIN_GOALS	:= $(filter bin/% bin-%,$(MAKECMDGOALS))
176
 BIN_GOALS	:= $(filter bin/% bin-%,$(MAKECMDGOALS))
177
-BIN_GOAL_BINS	:= $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
178
-NUM_BINS	:= $(words $(sort $(BIN_GOAL_BINS)))
177
+BIN_GOALS_BINS	:= $(sort $(foreach BG,$(BIN_GOALS),\
178
+				    $(firstword $(subst /, ,$(BG)))))
179
+NUM_BINS	:= $(words $(BIN_GOALS_BINS))
179
 
180
 
180
 ifeq ($(NUM_BINS),0)
181
 ifeq ($(NUM_BINS),0)
181
 
182
 
191
 # If exactly one BIN directory was specified, set BIN to match this
192
 # If exactly one BIN directory was specified, set BIN to match this
192
 # directory.
193
 # directory.
193
 #
194
 #
194
-BIN		:= $(firstword $(BIN_GOAL_BINS))
195
+BIN		:= $(firstword $(BIN_GOALS_BINS))
195
 
196
 
196
 else # NUM_BINS == 1
197
 else # NUM_BINS == 1
197
 
198
 
198
 # More than one BIN directory was specified.  We cannot handle the
199
 # More than one BIN directory was specified.  We cannot handle the
199
 # latter case within a single make invocation, so set up recursive
200
 # latter case within a single make invocation, so set up recursive
200
-# targets for each BIN directory.
201
+# targets for each BIN directory.  Use exactly one target for each BIN
202
+# directory since running multiple make invocations within the same
203
+# BIN directory is likely to cause problems.
201
 #
204
 #
202
 # Leave $(BIN) undefined.  This has implications for any target that
205
 # Leave $(BIN) undefined.  This has implications for any target that
203
 # depends on $(BIN); such targets should be made conditional upon the
206
 # depends on $(BIN); such targets should be made conditional upon the
204
 # existence of $(BIN).
207
 # existence of $(BIN).
205
 #
208
 #
206
-$(BIN_GOALS) : % : BIN_RECURSE
207
-	$(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
209
+BIN_GOALS_FIRST	:= $(foreach BGB,$(BIN_GOALS_BINS),\
210
+			     $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
211
+BIN_GOALS_OTHER	:= $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
212
+
213
+$(BIN_GOALS_FIRST) : % : BIN_RECURSE
214
+	$(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
215
+	    $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
216
+$(BIN_GOALS_OTHER) : % : BIN_RECURSE
217
+	$(Q)$(TRUE)
208
 .PHONY : BIN_RECURSE
218
 .PHONY : BIN_RECURSE
209
 
219
 
210
 endif # NUM_BINS == 1
220
 endif # NUM_BINS == 1

Loading…
Cancel
Save