]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[build] Properly handle multiple goals per BIN directory
authorPiotr Jaroszyński <p.jaroszynski@gmail.com>
Thu, 29 Jul 2010 13:17:30 +0000 (15:17 +0200)
committerMichael Brown <mcb30@ipxe.org>
Mon, 16 Aug 2010 16:26:20 +0000 (17:26 +0100)
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>
src/Makefile
src/Makefile.housekeeping

index 94a701b708a15f8dbdfc79a2c7f185d0b402bf52..950a13f699f50d8446a2f50d86970ef5b549b6cd 100644 (file)
@@ -21,6 +21,7 @@ CP            := cp
 ECHO           := echo
 PRINTF         := printf
 PERL           := perl
+TRUE           := true
 CC             := $(CROSS_COMPILE)gcc
 CPP            := $(CC) -E
 AS             := $(CROSS_COMPILE)as
index 7278c283977089b57d8102074ba1b88ae2e5590a..8f0c87f37318bb69578b3c6d079c3dfbb3de9df0 100644 (file)
@@ -174,8 +174,9 @@ endif
 # make goals.
 #
 BIN_GOALS      := $(filter bin/% bin-%,$(MAKECMDGOALS))
-BIN_GOAL_BINS  := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
-NUM_BINS       := $(words $(sort $(BIN_GOAL_BINS)))
+BIN_GOALS_BINS := $(sort $(foreach BG,$(BIN_GOALS),\
+                                   $(firstword $(subst /, ,$(BG)))))
+NUM_BINS       := $(words $(BIN_GOALS_BINS))
 
 ifeq ($(NUM_BINS),0)
 
@@ -191,20 +192,29 @@ ifeq ($(NUM_BINS),1)
 # If exactly one BIN directory was specified, set BIN to match this
 # directory.
 #
-BIN            := $(firstword $(BIN_GOAL_BINS))
+BIN            := $(firstword $(BIN_GOALS_BINS))
 
 else # NUM_BINS == 1
 
 # More than one BIN directory was specified.  We cannot handle the
 # latter case within a single make invocation, so set up recursive
-# targets for each BIN directory.
+# targets for each BIN directory.  Use exactly one target for each BIN
+# directory since running multiple make invocations within the same
+# BIN directory is likely to cause problems.
 #
 # Leave $(BIN) undefined.  This has implications for any target that
 # depends on $(BIN); such targets should be made conditional upon the
 # existence of $(BIN).
 #
-$(BIN_GOALS) : % : BIN_RECURSE
-       $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
+BIN_GOALS_FIRST        := $(foreach BGB,$(BIN_GOALS_BINS),\
+                            $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
+BIN_GOALS_OTHER        := $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
+
+$(BIN_GOALS_FIRST) : % : BIN_RECURSE
+       $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
+           $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
+$(BIN_GOALS_OTHER) : % : BIN_RECURSE
+       $(Q)$(TRUE)
 .PHONY : BIN_RECURSE
 
 endif # NUM_BINS == 1