2 # Copyright (C) 2007-2009 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 HOST_PATCH_DIR?=$(PATCH_DIR)
17 HOST_FILES_DIR?=$(FILES_DIR)
19 ifeq ($(MAKECMDGOALS),refresh)
23 QUILT_CMD:=quilt --quiltrc=-
26 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
30 @if [ -s "$(2)/series" ]; then \
31 mkdir -p "$(1)/patches/$(3)"; \
32 cp "$(2)/series" "$(1)/patches/$(3)"; \
34 @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls; fi; ) 2>/dev/null ); do ( \
35 cp "$(2)/$$$$patch" "$(1)"; \
37 $(QUILT_CMD) import -P$(3)$$$$patch -p 1 "$$$$patch"; \
38 $(QUILT_CMD) push -f >/dev/null 2>/dev/null; \
41 $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
44 define PatchDir/Default
45 @if [ -d "$(2)" -a "$$$$(ls $(2) | wc -l)" -gt 0 ]; then \
46 if [ -s "$(2)/series" ]; then \
47 $(call filter_series,$(2)/series) | xargs -n1 \
48 $(PATCH) "$(1)" "$(2)"; \
50 $(PATCH) "$(1)" "$(2)"; \
56 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
59 ifneq ($(PKG_BUILD_DIR),)
60 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
62 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
63 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
64 override CONFIG_AUTOREBUILD=
65 prepare: $(STAMP_PATCHED)
66 quilt-check: $(STAMP_CHECKED)
70 ifneq ($(HOST_BUILD_DIR),)
71 HOST_QUILT?=$(strip $(shell test -f $(if $(PKG_BUILD_DIR),$(PKG_BUILD_DIR),$(HOST_BUILD_DIR))/.quilt_used && echo y))
72 ifneq ($(HOST_QUILT),)
73 HOST_STAMP_PATCHED:=$(HOST_BUILD_DIR)/.quilt_patched
74 HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
75 override CONFIG_AUTOREBUILD=
76 host-prepare: $(HOST_STAMP_PATCHED)
77 host-quilt-check: $(HOST_STAMP_CHECKED)
81 define Host/Patch/Default
82 $(if $(QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
83 $(call PatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
84 $(if $(QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
87 define Build/Patch/Default
88 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
89 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
90 $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
93 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
94 define Kernel/Patch/Default
95 rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
96 $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
97 find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
98 $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
99 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
102 define Quilt/RefreshDir
104 -rm -f $(2)/* 2>/dev/null >/dev/null
106 for patch in $$$$($(if $(3),grep "^$(3)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
107 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(2); \
112 define Quilt/Refresh/Host
113 $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
116 define Quilt/Refresh/Package
117 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
120 define Quilt/Refresh/Kernel
121 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
122 echo "All kernel patches must start with either generic/ or platform/"; \
125 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
126 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
129 define Quilt/Template
130 $($(2)STAMP_PATCHED): $($(2)STAMP_PREPARED)
133 $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null; \
134 if [ -s ".subdirs" ]; then \
136 for file in $$$$(cat .subdirs); do \
137 if [ -f $$$$file/series ]; then \
138 echo "Converting $$file/series"; \
139 $$(call filter_series,$$$$file/series) | awk -v file="$$$$file/" '$$$$0 !~ /^#/ { print file $$$$0 }' | sed -e s,//,/,g >> series; \
141 echo "Sorting patches in $$$$file"; \
142 find $$$$file/* -type f \! -name series | sed -e s,//,/,g | sort >> series; \
146 find * -type f \! -name series | sort > series; \
151 $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED) FORCE
152 $($(2)STAMP_CHECKED): $($(2)STAMP_PATCHED)
153 if [ -s "$(1)/patches/series" ]; then \
155 if $(QUILT_CMD) next >/dev/null 2>&1; then \
156 $(QUILT_CMD) push -a; \
158 $(QUILT_CMD) top >/dev/null 2>&1; \
164 $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
165 @[ -f "$(1)/.quilt_used" ] || { \
166 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
169 @[ -f "$(1)/patches/series" ] || { \
170 echo "The source directory contains no quilt patches."; \
173 @[ -n "$$$$(ls $(1)/patches/series)" -o "$$$$(cat $(1)/patches/series | md5sum)" = "$$(sort $(1)/patches/series | md5sum)" ] || { \
174 echo "The patches are not sorted in the right order. Please fix."; \
178 $(3)refresh: $(3)quilt-check
179 @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
180 @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
181 QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
182 done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
183 $(Quilt/Refresh/$(4))
185 $(3)update: $(3)quilt-check
186 $(Quilt/Refresh/$(4))
189 Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
190 Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)