Select lcms2 support for GIMP
[unleashed-userland.git] / make-rules / prep.mk
blobae0c1b490bb67c9137bbcd01090c902e9926c79c
2 # CDDL HEADER START
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
19 # CDDL HEADER END
21 # Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
24 # One must do all unpack and patch in sequence.
25 .NOTPARALLEL: (SOURCE_DIR)/.prep
27 UNPACK = $(WS_TOOLS)/userland-unpack
28 FETCH = $(WS_TOOLS)/userland-fetch
30 ARCHIVES += $(COMPONENT_ARCHIVE)
31 CLEAN_PATHS += $(SOURCE_DIR)
33 # In order to override PATCH_DIR and PATCH_PATTERN in component makefiles, they
34 # need to be conditionally set here. This means that the override needs to
35 # happen prior to including prep.mk. Otherwise other variables set here which
36 # are based on those will be expanded too early for the override to take
37 # effect.
38 # You also can't override PATCHES after including prep.mk; if you want to
39 # append filenames to PATCHES, you'll have to set $(EXTRA_PATCHES) prior to
40 # inclusion.
41 PATCH_DIR ?= patches
43 # we may need patches only for use with parfait
44 ifeq ($(strip $(PARFAIT_BUILD)),yes)
45 PARFAIT_PATCH_DIR = parfait
46 endif
47 PATCH_PATTERN ?= *.patch
48 PATCHES = $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f -name '$(PATCH_PATTERN)' \
49 2>/dev/null | sort) $(EXTRA_PATCHES)
51 # Rule to perform the patching.
52 $(SOURCE_DIR)/.%ed: $(PATCH_DIR)/%
53 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $<
54 $(TOUCH) $@
56 # Parfait patches rule: TODO - Integrate with other patch rules
57 ifeq ($(strip $(PARFAIT_BUILD)),yes)
58 $(SOURCE_DIR)/.%ed: $(PARFAIT_PATCH_DIR)/%
59 $(GPATCH) -d $(@D) $(GPATCH_FLAGS) < $<
60 $(TOUCH) $@
61 endif
63 # Template for download rules.
64 define download-rule
65 ARCHIVES += $$(COMPONENT_ARCHIVE$(1))
66 CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
67 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)): Makefile
68 $$(FETCH) --file $$@ \
69 $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) \
70 $$(COMPONENT_ARCHIVE_HASH$(1):%=--hash %)
71 $$(TOUCH) $$@
72 endef
74 # Template for patching rules, note that patching is actually done by the
75 # %.ed pattern rule above.
76 # To maintain backwards compatibility, the flag PATCH_EACH_ARCHIVE must
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) $$@
95 endef
97 # Template for unpacking rules.
98 define unpack-rule
99 $$(SOURCE_DIR)/.unpacked$(1): download Makefile $$(PATCHDIR_PATCHES$(1))
100 $$(RM) -r $$(COMPONENT_SRC$(1))
101 $$(UNPACK) $$(UNPACK_ARGS$(1)) \
102 $$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1))
103 $$(COMPONENT_POST_UNPACK_ACTION$(1))
104 $$(TOUCH) $$@
105 endef
107 # If an archive is defined, create a download, unpack and patch rule.
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
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 $(eval $(call archive-rule,))
121 ifneq ($(strip $(PATCH_EACH_ARCHIVE)),)
122 $(foreach suffix,$(NUM_EXTRA_ARCHIVES), \
123 $(eval $(call archive-rule,_$(suffix))))
124 else
125 # Backwards compatibility - only download, do not unpack or patch automatically
126 $(foreach suffix,$(NUM_EXTRA_ARCHIVES), \
127 $(eval $(call download-rule,_$(suffix))))
128 endif
130 $(SOURCE_DIR)/.prep: $(ARCHIVE_STAMPS)
131 $(COMPONENT_PREP_ACTION)
132 $(TOUCH) $@
134 prep:: $(SOURCE_DIR)/.prep
136 download:: $(ARCHIVES:%=$(USERLAND_ARCHIVES)%)
138 clean::
139 $(RM) -r $(CLEAN_PATHS)
141 clobber:: clean
142 $(RM) -r $(CLOBBER_PATHS)