-$(STAMP_PATCHED): $(STAMP_PREPARED)
- @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
- (\
- cd $(PKG_BUILD_DIR)/patches; \
- find * -type f \! -name series | sort > series; \
- )
- [ -f "$(PKG_BUILD_DIR)/patches/series" ] && cd $(PKG_BUILD_DIR); quilt push -a
- touch $@
+define Build/Patch/Default
+ $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
+ $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
+ $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
+endef
+
+kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
+define Kernel/Patch/Default
+ rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
+ $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
+ find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
+ $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
+ $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
+endef