--- a/make-rules/prep.mk Mon Apr 23 02:00:40 2012 -0700
+++ b/make-rules/prep.mk Mon Apr 23 08:30:27 2012 -0700
@@ -21,6 +21,9 @@
# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
#
+# One must do all unpack and patch in sequence.
+.NOTPARALLEL: (SOURCE_DIR)/.prep
+
UNPACK = $(WS_TOOLS)/userland-unpack
FETCH = $(WS_TOOLS)/userland-fetch
@@ -30,7 +33,8 @@
# In order to override PATCH_DIR and PATCH_PATTERN in component makefiles, they
# need to be conditionally set here. This means that the override needs to
# happen prior to including prep.mk. Otherwise other variables set here which
-# are based on those will be expanded too early for the override to take effect.
+# are based on those will be expanded too early for the override to take
+# effect.
# You also can't override PATCHES after including prep.mk; if you want to
# append filenames to PATCHES, you'll have to set $(EXTRA_PATCHES) prior to
# inclusion.
@@ -43,22 +47,20 @@
PATCH_PATTERN ?= *.patch
PATCHES = $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f -name '$(PATCH_PATTERN)' \
2>/dev/null | sort) $(EXTRA_PATCHES)
-STAMPS = $(PATCHES:$(PATCH_DIR)/%=$(SOURCE_DIR)/.%ed)
-ifeq ($(strip $(PARFAIT_BUILD)),yes)
-STAMPS += $(PATCHES:$(PARFAIT_PATCH_DIR)/%=$(SOURCE_DIR)/.%ed)
-endif
+# Rule to perform the patching.
$(SOURCE_DIR)/.%ed: $(PATCH_DIR)/%
$(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $<
$(TOUCH) $@
+# Parfait patches rule: TODO - Integrate with other patch rules
ifeq ($(strip $(PARFAIT_BUILD)),yes)
$(SOURCE_DIR)/.%ed: $(PARFAIT_PATCH_DIR)/%
$(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $<
$(TOUCH) $@
endif
-# template for download rules. add new rules with $(call download-rule, suffix)
+# Template for download rules.
define download-rule
ARCHIVES += $$(COMPONENT_ARCHIVE$(1))
CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
@@ -69,21 +71,64 @@
$$(TOUCH) $$@
endef
-# Generate the download rules from the above template
-NUM_ARCHIVES = 1 2 3 4 5 6 7
-$(eval $(call download-rule,))
-$(foreach suffix,$(NUM_ARCHIVES),$(eval $(call download-rule,_$(suffix))))
+# Template for patching rules, note that patching is actually done by the
+# %.ed pattern rule above.
+# To maintain backwards compatibility, the flag PATCH_EACH_ARCHIVE must
+# be non-empty in order to activate individual archive patching.
+define patch-rule
+ifneq ($(strip $$(PATCH_EACH_ARCHIVE)),)
+# Prepend the patch directory to each archive patch.
+#$$(COMPONENT_PATCHES$(1):%=$$(PATCH_DIR)/%)
+#PATCHDIR_PATCHES$(1) += $$(COMPONENT_PATCHES)
+PATCHDIR_PATCHES$(1) += $$(foreach patch,$$(COMPONENT_PATCHES$(1)), \
+ $$(PATCH_DIR)/$$(patch))
+else
+PATCHDIR_PATCHES = $$(PATCHES)
+endif
+# Substitute the patch dir for the source dir on the patches
+STAMPS$(1)+= $$(PATCHDIR_PATCHES$(1):$$(PATCH_DIR)/%=$$(SOURCE_DIR)/.%ed)
+ifeq ($(strip $(PARFAIT_BUILD)),yes)
+STAMPS$(1)+= $$(PATCHDIR_PATCHES$(1):$$(PARFAIT_PATCH_DIR)/%=$$(SOURCE_DIR)/.%ed)
+endif
+$$(SOURCE_DIR)/.patched$(1): $$(SOURCE_DIR)/.unpacked$(1) $$(STAMPS$(1))
+ $$(TOUCH) $$@
+endef
-$(SOURCE_DIR)/.unpacked: download Makefile $(PATCHES)
- $(RM) -r $(SOURCE_DIR)
- $(UNPACK) $(UNPACK_ARGS) $(USERLAND_ARCHIVES)$(COMPONENT_ARCHIVE)
- $(COMPONENT_POST_UNPACK_ACTION)
- $(TOUCH) $@
+# Template for unpacking rules.
+define unpack-rule
+$$(SOURCE_DIR)/.unpacked$(1): download Makefile $$(PATCHDIR_PATCHES$(1))
+ $$(RM) -r $$(COMPONENT_SRC$(1))
+ $$(UNPACK) $$(UNPACK_ARGS$(1)) \
+ $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
+ $$(COMPONENT_POST_UNPACK_ACTION$(1))
+ $$(TOUCH) $$@
+endef
-$(SOURCE_DIR)/.patched: $(SOURCE_DIR)/.unpacked $(STAMPS)
- $(TOUCH) $@
+# If an archive is defined, create a download, unpack and patch rule.
+define archive-rule
+ifneq ($(strip $$(COMPONENT_ARCHIVE$(1))),)
+$(eval $(call download-rule,$(1)))
+$(eval $(call unpack-rule,$(1)))
+$(eval $(call patch-rule,$(1)))
+ARCHIVE_STAMPS +=$$(SOURCE_DIR)/.patched$(1)
+endif
+endef
-$(SOURCE_DIR)/.prep: $(SOURCE_DIR)/.patched
+# Calculate the number of defined archives.
+# Always generate at least the basic prep rules.
+# Work out if there are any other archives to be downloaded and patched.
+NUM_EXTRA_ARCHIVES= 1 2 3 4 5 6 7 8 9
+$(eval $(call archive-rule,))
+ifneq ($(strip $(PATCH_EACH_ARCHIVE)),)
+$(foreach suffix,$(NUM_EXTRA_ARCHIVES), \
+ $(eval $(call archive-rule,_$(suffix))))
+else
+# Backwards compatibility - only download, do not unpack or patch automatically
+$(foreach suffix,$(NUM_EXTRA_ARCHIVES), \
+ $(eval $(call download-rule,_$(suffix))))
+endif
+
+$(SOURCE_DIR)/.prep: $(ARCHIVE_STAMPS)
$(COMPONENT_PREP_ACTION)
$(TOUCH) $@