-QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
-ifneq ($(QUILT),)
- STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
- STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
- CONFIG_AUTOREBUILD=
- PATCHES:=$(shell cd ./patches; ls)
- define Build/Patch/Default
- rm -rf $(PKG_BUILD_DIR)/patches
- mkdir -p $(PKG_BUILD_DIR)/patches
- @for patch in $(PATCHES); do ( \
- cp "./patches/$$$$patch" $(PKG_BUILD_DIR); \
- cd $(PKG_BUILD_DIR); \
- quilt import -p 1 "$$$$patch"; \
- quilt push -f >/dev/null 2>/dev/null; \
- rm -f "$$$$patch"; \
+ifeq ($(TARGET_BUILD),1)
+ PKG_BUILD_DIR:=$(LINUX_DIR)
+endif
+
+ifneq ($(filter host-refresh refresh,$(MAKECMDGOALS)),)
+ override QUILT=1
+ override HOST_QUILT=1
+endif
+
+ifneq ($(PKG_BUILD_DIR),)
+ QUILT?=$(if $(wildcard $(PKG_BUILD_DIR)/.quilt_used),y)
+ ifneq ($(QUILT),)
+ STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
+ override CONFIG_AUTOREBUILD=
+ override CONFIG_AUTOREMOVE=
+ quilt-check: $(STAMP_CHECKED)
+ endif
+endif
+
+ifneq ($(HOST_BUILD_DIR),)
+ HOST_QUILT?=$(if $(findstring command,$(origin QUILT)),$(QUILT),$(if $(wildcard $(HOST_BUILD_DIR)/.quilt_used),y))
+ ifneq ($(HOST_QUILT),)
+ HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
+ override CONFIG_AUTOREBUILD=
+ override CONFIG_AUTOREMOVE=
+ host-quilt-check: $(HOST_STAMP_CHECKED)
+ endif
+endif
+
+ifneq ($(if $(DUMP),1,$(__quilt_inc)),1)
+__quilt_inc:=1
+
+PATCH_DIR?=./patches
+FILES_DIR?=./files
+HOST_PATCH_DIR?=$(PATCH_DIR)
+HOST_FILES_DIR?=$(FILES_DIR)
+
+QUILT_CMD:=quilt --quiltrc=-
+
+define filter_series
+sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
+endef
+
+define PatchDir/Quilt
+ @mkdir -p "$(1)/patches$(if $(3),/$(patsubst %/,%,$(3)))"
+ @if [ -s "$(2)/series" ]; then \
+ mkdir -p "$(1)/patches/$(3)"; \
+ cp "$(2)/series" "$(1)/patches/$(3)"; \
+ fi
+ @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls | sort; fi; ) 2>/dev/null ); do ( \
+ cp "$(2)/$$$$patch" "$(1)/patches/$(3)"; \
+ echo "$(3)$$$$patch" >> "$(1)/patches/series"; \