Andreas Wacknitz
2024-04-05 f09dca6e20c67020d6f337fc95eec480de4d24ef
make-rules/prep-patch.mk
@@ -46,14 +46,8 @@
PATCH_PATTERN ?=   *.patch*
PATCH_DIR ?=      patches
# patches specific to parfait builds.
ifeq   ($(strip $(PARFAIT_BUILD)),yes)
PARFAIT_PATCH_DIR =   parfait
endif
PATCHES =   $(shell find $(PATCH_DIR) $(PARFAIT_PATCH_DIR) -type f \
          -name '$(PATCH_PATTERN)' 2>/dev/null | \
            LC_COLLATE=C sort)
PATCHES =   $(wildcard $(PATCH_DIR)/$(PATCH_PATTERN))
PCH_SUFFIXES = $(patsubst .patch_%,%, $(filter-out .patch,$(suffix $(PATCHES))))
@@ -73,9 +67,6 @@
ifneq ($$(PATCHES$(1)),)
PATCH_STAMPS$(1) += $$(PATCHES$(1):$(PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
ifeq   ($(strip $(PARFAIT_BUILD)),yes)
PATCH_STAMPS$(1) += $$(PATCHES$(1):$(PARFAIT_PATCH_DIR)/%=$$(SOURCE_DIR$(1))/.patched-%)
endif
# We should unpack the source that we patch before we patch it.
$$(PATCH_STAMPS$(1)):   unpack
@@ -89,7 +80,7 @@
   $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
   $(TOUCH) $$(@)
$$(SOURCE_DIR$(1))/.patched-%:   $(PARFAIT_PATCH_DIR)/% $(MAKEFILE_PREREQ)
$$(SOURCE_DIR$(1))/.patched-%:   $(MAKEFILE_PREREQ)
   $(GPATCH) -d $$(@D) $$(GPATCH_FLAGS) < $$<
   $(TOUCH) $$(@)
@@ -109,3 +100,39 @@
#
$(foreach suffix, $(PCH_SUFFIXES), $(eval $(call patch-rule,_$(suffix))))
$(eval $(call patch-rule,))   # this must be last so we don't drop *.patch_%.
# Helper target for patches refresh
refresh-patches: $(QUILT) patch
   # Unapply all patches
   for p in $(PATCHES) ; do \
      echo $$p ; \
   done | $(TAC) | while read p ; do \
      $(GPATCH) -d $(SOURCE_DIR) --strip=$(PATCH_LEVEL) --reverse < $$p \
      && continue ; \
      exit 1 ; \
   done
   # Make sure the series file does not exist
   $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series
   # Apply and refresh patches, then unapply them
   cd $(SOURCE_DIR) ; for p in $(PATCHES) ; do \
      QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null "../$$p" \
      && QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q \
      && QUILT_PATCHES=../$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p 1 --no-timestamps --no-index \
      && continue ; \
      exit 1 ; \
   done ; \
   [ ! -e $(COMPONENT_DIR)/$(PATCH_DIR)/series ] || QUILT_PATCHES=../$(PATCH_DIR) quilt pop --quiltrc /dev/null -a -q
   # cleanup
   $(RM) -r $(SOURCE_DIR)/.pc
   $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series
   # Apply and refresh patches again to get the desired patch format
   for p in $(PATCHES) ; do \
      QUILT_PATCHES=$(PATCH_DIR) $(QUILT) import --quiltrc /dev/null -p 0 "$$p" \
      && QUILT_PATCHES=$(PATCH_DIR) $(QUILT) push --quiltrc /dev/null -q \
      && QUILT_PATCHES=$(PATCH_DIR) $(QUILT) refresh --quiltrc /dev/null -p 0 --no-timestamps --no-index \
      && continue ; \
      exit 1 ; \
   done
   # final cleanup
   $(RM) -r $(COMPONENT_DIR)/.pc
   $(RM) $(COMPONENT_DIR)/$(PATCH_DIR)/series