19 # CDDL HEADER END |
19 # CDDL HEADER END |
20 # |
20 # |
21 # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
21 # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
22 # |
22 # |
23 |
23 |
|
24 # One must do all unpack and patch in sequence. |
|
25 .NOTPARALLEL: (SOURCE_DIR)/.prep |
|
26 |
24 UNPACK = $(WS_TOOLS)/userland-unpack |
27 UNPACK = $(WS_TOOLS)/userland-unpack |
25 FETCH = $(WS_TOOLS)/userland-fetch |
28 FETCH = $(WS_TOOLS)/userland-fetch |
26 |
29 |
27 ARCHIVES += $(COMPONENT_ARCHIVE) |
30 ARCHIVES += $(COMPONENT_ARCHIVE) |
28 CLEAN_PATHS += $(SOURCE_DIR) |
31 CLEAN_PATHS += $(SOURCE_DIR) |
29 |
32 |
30 # In order to override PATCH_DIR and PATCH_PATTERN in component makefiles, they |
33 # In order to override PATCH_DIR and PATCH_PATTERN in component makefiles, they |
31 # need to be conditionally set here. This means that the override needs to |
34 # need to be conditionally set here. This means that the override needs to |
32 # happen prior to including prep.mk. Otherwise other variables set here which |
35 # happen prior to including prep.mk. Otherwise other variables set here which |
33 # are based on those will be expanded too early for the override to take effect. |
36 # are based on those will be expanded too early for the override to take |
|
37 # effect. |
34 # You also can't override PATCHES after including prep.mk; if you want to |
38 # You also can't override PATCHES after including prep.mk; if you want to |
35 # append filenames to PATCHES, you'll have to set $(EXTRA_PATCHES) prior to |
39 # append filenames to PATCHES, you'll have to set $(EXTRA_PATCHES) prior to |
36 # inclusion. |
40 # inclusion. |
37 PATCH_DIR ?= patches |
41 PATCH_DIR ?= patches |
38 |
42 |
41 PARFAIT_PATCH_DIR = parfait |
45 PARFAIT_PATCH_DIR = parfait |
42 endif |
46 endif |
43 PATCH_PATTERN ?= *.patch |
47 PATCH_PATTERN ?= *.patch |
44 PATCHES = $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f -name '$(PATCH_PATTERN)' \ |
48 PATCHES = $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f -name '$(PATCH_PATTERN)' \ |
45 2>/dev/null | sort) $(EXTRA_PATCHES) |
49 2>/dev/null | sort) $(EXTRA_PATCHES) |
46 STAMPS = $(PATCHES:$(PATCH_DIR)/%=$(SOURCE_DIR)/.%ed) |
|
47 ifeq ($(strip $(PARFAIT_BUILD)),yes) |
|
48 STAMPS += $(PATCHES:$(PARFAIT_PATCH_DIR)/%=$(SOURCE_DIR)/.%ed) |
|
49 endif |
|
50 |
50 |
|
51 # Rule to perform the patching. |
51 $(SOURCE_DIR)/.%ed: $(PATCH_DIR)/% |
52 $(SOURCE_DIR)/.%ed: $(PATCH_DIR)/% |
52 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $< |
53 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $< |
53 $(TOUCH) [email protected] |
54 $(TOUCH) [email protected] |
54 |
55 |
|
56 # Parfait patches rule: TODO - Integrate with other patch rules |
55 ifeq ($(strip $(PARFAIT_BUILD)),yes) |
57 ifeq ($(strip $(PARFAIT_BUILD)),yes) |
56 $(SOURCE_DIR)/.%ed: $(PARFAIT_PATCH_DIR)/% |
58 $(SOURCE_DIR)/.%ed: $(PARFAIT_PATCH_DIR)/% |
57 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $< |
59 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $< |
58 $(TOUCH) [email protected] |
60 $(TOUCH) [email protected] |
59 endif |
61 endif |
60 |
62 |
61 # template for download rules. add new rules with $(call download-rule, suffix) |
63 # Template for download rules. |
62 define download-rule |
64 define download-rule |
63 ARCHIVES += $$(COMPONENT_ARCHIVE$(1)) |
65 ARCHIVES += $$(COMPONENT_ARCHIVE$(1)) |
64 CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1)) |
66 CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1)) |
65 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)): Makefile |
67 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)): Makefile |
66 $$(FETCH) --file [email protected] \ |
68 $$(FETCH) --file [email protected] \ |
67 $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) \ |
69 $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) \ |
68 $$(COMPONENT_ARCHIVE_HASH$(1):%=--hash %) |
70 $$(COMPONENT_ARCHIVE_HASH$(1):%=--hash %) |
69 $$(TOUCH) [email protected] |
71 $$(TOUCH) [email protected] |
70 endef |
72 endef |
71 |
73 |
72 # Generate the download rules from the above template |
74 # Template for patching rules, note that patching is actually done by the |
73 NUM_ARCHIVES = 1 2 3 4 5 6 7 |
75 # %.ed pattern rule above. |
74 $(eval $(call download-rule,)) |
76 # To maintain backwards compatibility, the flag PATCH_EACH_ARCHIVE must |
75 $(foreach suffix,$(NUM_ARCHIVES),$(eval $(call download-rule,_$(suffix)))) |
77 # be non-empty in order to activate individual archive patching. |
|
78 define patch-rule |
|
79 ifneq ($(strip $$(PATCH_EACH_ARCHIVE)),) |
|
80 # Prepend the patch directory to each archive patch. |
|
81 #$$(COMPONENT_PATCHES$(1):%=$$(PATCH_DIR)/%) |
|
82 #PATCHDIR_PATCHES$(1) += $$(COMPONENT_PATCHES) |
|
83 PATCHDIR_PATCHES$(1) += $$(foreach patch,$$(COMPONENT_PATCHES$(1)), \ |
|
84 $$(PATCH_DIR)/$$(patch)) |
|
85 else |
|
86 PATCHDIR_PATCHES = $$(PATCHES) |
|
87 endif |
|
88 # Substitute the patch dir for the source dir on the patches |
|
89 STAMPS$(1)+= $$(PATCHDIR_PATCHES$(1):$$(PATCH_DIR)/%=$$(SOURCE_DIR)/.%ed) |
|
90 ifeq ($(strip $(PARFAIT_BUILD)),yes) |
|
91 STAMPS$(1)+= $$(PATCHDIR_PATCHES$(1):$$(PARFAIT_PATCH_DIR)/%=$$(SOURCE_DIR)/.%ed) |
|
92 endif |
|
93 $$(SOURCE_DIR)/.patched$(1): $$(SOURCE_DIR)/.unpacked$(1) $$(STAMPS$(1)) |
|
94 $$(TOUCH) [email protected] |
|
95 endef |
76 |
96 |
77 $(SOURCE_DIR)/.unpacked: download Makefile $(PATCHES) |
97 # Template for unpacking rules. |
78 $(RM) -r $(SOURCE_DIR) |
98 define unpack-rule |
79 $(UNPACK) $(UNPACK_ARGS) $(USERLAND_ARCHIVES)$(COMPONENT_ARCHIVE) |
99 $$(SOURCE_DIR)/.unpacked$(1): download Makefile $$(PATCHDIR_PATCHES$(1)) |
80 $(COMPONENT_POST_UNPACK_ACTION) |
100 $$(RM) -r $$(COMPONENT_SRC$(1)) |
81 $(TOUCH) [email protected] |
101 $$(UNPACK) $$(UNPACK_ARGS$(1)) \ |
|
102 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)) |
|
103 $$(COMPONENT_POST_UNPACK_ACTION$(1)) |
|
104 $$(TOUCH) [email protected] |
|
105 endef |
82 |
106 |
83 $(SOURCE_DIR)/.patched: $(SOURCE_DIR)/.unpacked $(STAMPS) |
107 # If an archive is defined, create a download, unpack and patch rule. |
84 $(TOUCH) [email protected] |
108 define archive-rule |
|
109 ifneq ($(strip $$(COMPONENT_ARCHIVE$(1))),) |
|
110 $(eval $(call download-rule,$(1))) |
|
111 $(eval $(call unpack-rule,$(1))) |
|
112 $(eval $(call patch-rule,$(1))) |
|
113 ARCHIVE_STAMPS +=$$(SOURCE_DIR)/.patched$(1) |
|
114 endif |
|
115 endef |
85 |
116 |
86 $(SOURCE_DIR)/.prep: $(SOURCE_DIR)/.patched |
117 # Calculate the number of defined archives. |
|
118 # Always generate at least the basic prep rules. |
|
119 # Work out if there are any other archives to be downloaded and patched. |
|
120 NUM_EXTRA_ARCHIVES= 1 2 3 4 5 6 7 8 9 |
|
121 $(eval $(call archive-rule,)) |
|
122 ifneq ($(strip $(PATCH_EACH_ARCHIVE)),) |
|
123 $(foreach suffix,$(NUM_EXTRA_ARCHIVES), \ |
|
124 $(eval $(call archive-rule,_$(suffix)))) |
|
125 else |
|
126 # Backwards compatibility - only download, do not unpack or patch automatically |
|
127 $(foreach suffix,$(NUM_EXTRA_ARCHIVES), \ |
|
128 $(eval $(call download-rule,_$(suffix)))) |
|
129 endif |
|
130 |
|
131 $(SOURCE_DIR)/.prep: $(ARCHIVE_STAMPS) |
87 $(COMPONENT_PREP_ACTION) |
132 $(COMPONENT_PREP_ACTION) |
88 $(TOUCH) [email protected] |
133 $(TOUCH) [email protected] |
89 |
134 |
90 prep:: $(SOURCE_DIR)/.prep |
135 prep:: $(SOURCE_DIR)/.prep |
91 |
136 |