Andreas Wacknitz
2024-04-05 88d415640d20174302d2d8eaa6b036dfaa19730f
make-rules/prep.mk
@@ -18,124 +18,34 @@
#
# CDDL HEADER END
#
# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
#
# Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
#
.NOTPARALLEL:
# One must do all unpack and patch in sequence.
.NOTPARALLEL: (SOURCE_DIR)/.prep
include $(WS_MAKE_RULES)/prep-download.mk
UNPACK =   $(WS_TOOLS)/userland-unpack
FETCH =      $(WS_TOOLS)/userland-fetch
include $(WS_MAKE_RULES)/prep-hg.mk
include $(WS_MAKE_RULES)/prep-git.mk
include $(WS_MAKE_RULES)/prep-svn.mk
include $(WS_MAKE_RULES)/prep-unpack.mk
include $(WS_MAKE_RULES)/prep-patch.mk
ARCHIVES += $(COMPONENT_ARCHIVE)
CLEAN_PATHS += $(SOURCE_DIR)
download::
# 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.
# 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.
PATCH_DIR ?=   patches
unpack::   download
# we may need patches only for use with parfait
ifeq   ($(strip $(PARFAIT_BUILD)),yes)
PARFAIT_PATCH_DIR =   parfait
endif
PATCH_PATTERN ?=   *.patch
PATCHES =   $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f -name '$(PATCH_PATTERN)' \
            2>/dev/null | sort) $(EXTRA_PATCHES)
patch::      unpack
# 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.
define download-rule
ARCHIVES += $$(COMPONENT_ARCHIVE$(1))
CLOBBER_PATHS += $$(COMPONENT_ARCHIVE$(1))
$$(USERLAND_ARCHIVES)$$(COMPONENT_ARCHIVE$(1)):   Makefile
   $$(FETCH) --file $$@ \
      $$(COMPONENT_ARCHIVE_URL$(1):%=--url %) \
      $$(COMPONENT_ARCHIVE_HASH$(1):%=--hash %)
   $$(TOUCH) $$@
endef
# 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
# 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
# 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
# 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.
$(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)
$(SOURCE_DIR)/.prep:   component-environment-prep download unpack patch
   $(COMPONENT_PREP_ACTION)
   $(TOUCH) $@
prep::   $(SOURCE_DIR)/.prep
download::   $(ARCHIVES:%=$(USERLAND_ARCHIVES)%)
clean::
   $(PRE_CLEAN_ACTION)
   $(RM) -r $(CLEAN_PATHS)
clobber::   clean