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