-ifeq ($(KERNEL_BUILD),1)
-$(STAMP_PATCHED): $(STAMP_PREPARED)
- @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
- (\
- cd $(PKG_BUILD_DIR)/patches; \
- rm -f series; \
- for file in *; do \
- if [ -f $$file/series ]; then \
- echo "Converting $$file/series"; \
- awk -v file="$$file/" '$$0 !~ /^#/ { print file $$0 }' $$file/series >> series; \
- else \
- echo "Sorting patches in $$file"; \
- find $$file/* -type f \! -name series | sort >> series; \
- fi; \
- done; \
- )
- if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
- touch $@
-else
-$(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; \
- )
- if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
- touch $@
-endif
+define HostPatchDir
+$(call PatchDir/$(if $(strip $(HOST_QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
+endef
+
+define Host/Patch/Default
+ $(if $(HOST_QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
+ $(call HostPatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
+ $(if $(HOST_QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
+endef
+
+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
+ $(if $(QUILT),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
+ if [ -d $(GENERIC_PLATFORM_DIR)/patches$(if $(wildcard $(GENERIC_PLATFORM_DIR)/patches-$(KERNEL_PATCHVER)),-$(KERNEL_PATCHVER)) ]; then \
+ echo "generic patches directory is present. please move your patches to the pending directory" ; \
+ exit 1; \
+ fi
+ $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_BACKPORT_DIR),generic-backport/)
+ $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
+ $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_HACK_DIR),generic-hack/)
+ $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
+endef