+define Build/Patch/Default
+ $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
+ $(call PatchDir,$(PATCH_DIR),)
+endef
+
+define Kernel/Patch/Default
+ $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
+ if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
+ if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
+ $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
+ $(call PatchDir,$(PATCH_DIR),platform/)
+endef
+
+define Quilt/RefreshDir
+ mkdir -p $(1)
+ -rm -f $(1)/* 2>/dev/null >/dev/null
+ @( \
+ for patch in $$$$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
+ $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(1); \
+ done; \
+ )
+endef
+
+define Quilt/Refresh/Package
+ $(call Quilt/RefreshDir,$(PATCH_DIR))
+endef
+
+define Quilt/Refresh/Kernel
+ @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
+ echo "All kernel patches must start with either generic/ or platform/"; \
+ false; \
+ }
+ $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
+ $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
+endef
+
+define Quilt/Refresh
+$(if $(TARGET_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
+endef
+