2 # Copyright (C) 2007 OpenWrt.org
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
8 ifneq ($(__quilt_inc),1)
11 ifeq ($(TARGET_BUILD),1)
12 PKG_BUILD_DIR:=$(LINUX_DIR)
16 ifeq ($(MAKECMDGOALS),refresh)
21 @if [ -s $(1)/series ]; then \
22 mkdir -p $(PKG_BUILD_DIR)/patches$(if $(2),/$(2)); \
23 cp $(1)/series $(PKG_BUILD_DIR)/patches$(if $(2),/$(2))/; \
25 @for patch in $$$$( (cd $(1) && if [ -f series ]; then grep -v '^#' series; else ls; fi; ) 2>/dev/null ); do ( \
26 cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
27 cd $(PKG_BUILD_DIR); \
28 quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
29 quilt push -f >/dev/null 2>/dev/null; \
32 $(if $(2),@echo $(2) >> $(PKG_BUILD_DIR)/patches/.subdirs)
35 define PatchDir/Default
36 @if [ -d "$(1)" -a "$$$$(ls $(1) | wc -l)" -gt 0 ]; then \
37 if [ -s "$(1)/series" ]; then \
38 grep -vE '^#' $(1)/series | xargs -n1 \
39 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
41 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
47 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)))
50 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
52 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
53 override CONFIG_AUTOREBUILD=
54 $(STAMP_CONFIGURED): $(STAMP_PATCHED) FORCE
55 prepare: $(STAMP_PATCHED)
56 quilt-check: $(STAMP_PATCHED)
59 define Build/Patch/Default
60 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
61 $(call PatchDir,$(PATCH_DIR),)
64 define Kernel/Patch/Default
65 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
66 if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
67 if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
68 $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
69 $(call PatchDir,$(PATCH_DIR),platform/)
72 $(STAMP_PATCHED): $(STAMP_PREPARED)
74 cd $(PKG_BUILD_DIR)/patches; \
75 quilt pop -a -f >/dev/null 2>/dev/null; \
76 if [ -s ".subdirs" ]; then \
78 for file in $$(cat .subdirs); do \
79 if [ -f $$file/series ]; then \
80 echo "Converting $$file/series"; \
81 awk -v file="$$file/" '$$0 !~ /^#/ { print file $$0 }' $$file/series >> series; \
83 echo "Sorting patches in $$file"; \
84 find $$file/* -type f \! -name series | sort >> series; \
88 find * -type f \! -name series | sort > series; \
91 if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
94 define Quilt/RefreshDir
96 -rm -f $(1)/* 2>/dev/null >/dev/null
98 for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \
99 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \
104 define Quilt/Refresh/Package
105 $(call Quilt/RefreshDir,$(PATCH_DIR))
108 define Quilt/Refresh/Kernel
109 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
110 echo "All kernel patches must start with either generic/ or platform/"; \
113 $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
114 $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
117 quilt-check: $(STAMP_PREPARED) FORCE
118 @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
119 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
122 @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
123 echo "The source directory contains no quilt patches."; \
126 @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
127 echo "The patches are not sorted in the right order. Please fix."; \
132 @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
133 @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
135 done; ! quilt next 2>/dev/null >/dev/null
136 $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
139 $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))