浏览代码

[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 年前
父节点
当前提交
2d98d4a018
共有 2 个文件被更改,包括 17 次插入6 次删除
  1. 1
    0
      src/Makefile
  2. 16
    6
      src/Makefile.housekeeping

+ 1
- 0
src/Makefile 查看文件

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

+ 16
- 6
src/Makefile.housekeeping 查看文件

@@ -174,8 +174,9 @@ endif
174 174
 # make goals.
175 175
 #
176 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 181
 ifeq ($(NUM_BINS),0)
181 182
 
@@ -191,20 +192,29 @@ ifeq ($(NUM_BINS),1)
191 192
 # If exactly one BIN directory was specified, set BIN to match this
192 193
 # directory.
193 194
 #
194
-BIN		:= $(firstword $(BIN_GOAL_BINS))
195
+BIN		:= $(firstword $(BIN_GOALS_BINS))
195 196
 
196 197
 else # NUM_BINS == 1
197 198
 
198 199
 # More than one BIN directory was specified.  We cannot handle the
199 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 205
 # Leave $(BIN) undefined.  This has implications for any target that
203 206
 # depends on $(BIN); such targets should be made conditional upon the
204 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 218
 .PHONY : BIN_RECURSE
209 219
 
210 220
 endif # NUM_BINS == 1

正在加载...
取消
保存