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)
17 ifeq ($(MAKECMDGOALS),refresh)
21 QUILT_CMD:=quilt --quiltrc=-
24 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
28 @if [ -s "$(2)/series" ]; then \
29 mkdir -p "$(1)/patches/$(3)"; \
30 cp "$(2)/series" "$(1)/patches/$(3)"; \
32 @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls; fi; ) 2>/dev/null ); do ( \
33 cp "$(2)/$$$$patch" "$(1)"; \
35 $(QUILT_CMD) import -P$(3)$$$$patch -p 1 "$$$$patch"; \
36 $(QUILT_CMD) push -f >/dev/null 2>/dev/null; \
39 $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
42 define PatchDir/Default
43 @if [ -d "$(2)" -a "$$$$(ls $(2) | wc -l)" -gt 0 ]; then \
44 if [ -s "$(2)/series" ]; then \
45 $(call filter_series,$(2)/series) | xargs -n1 \
46 $(PATCH) "$(1)" "$(2)"; \
48 $(PATCH) "$(1)" "$(2)"; \
54 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
57 ifneq ($(PKG_BUILD_DIR),)
58 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
60 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
61 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
62 override CONFIG_AUTOREBUILD=
63 prepare: $(STAMP_PATCHED)
64 quilt-check: $(STAMP_CHECKED)
68 ifneq ($(HOST_BUILD_DIR),)
69 HOST_QUILT?=$(strip $(shell test -f $(if $(PKG_BUILD_DIR),$(PKG_BUILD_DIR),$(HOST_BUILD_DIR))/.quilt_used && echo y))
70 ifneq ($(HOST_QUILT),)
71 HOST_STAMP_PATCHED:=$(HOST_BUILD_DIR)/.quilt_patched
72 HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
73 override CONFIG_AUTOREBUILD=
74 host-prepare: $(HOST_STAMP_PATCHED)
75 host-quilt-check: $(HOST_STAMP_CHECKED)
79 define Host/Patch/Default
80 $(if $(QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
81 $(call PatchDir,$(HOST_BUILD_DIR),$(PATCH_DIR),)
84 define Build/Patch/Default
85 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
86 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
89 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
90 define Kernel/Patch/Default
91 rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
92 $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
93 find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
94 $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
95 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
98 define Quilt/RefreshDir
100 -rm -f $(2)/* 2>/dev/null >/dev/null
102 for patch in $$$$($(if $(3),grep "^$(3)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
103 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(2); \
108 define Quilt/Refresh/Host
109 $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
112 define Quilt/Refresh/Package
113 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
116 define Quilt/Refresh/Kernel
117 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
118 echo "All kernel patches must start with either generic/ or platform/"; \
121 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
122 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
126 $($(2)STAMP_PATCHED): $($(2)STAMP_PREPARED)
129 $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null; \
130 if [ -s ".subdirs" ]; then \
132 for file in $$$$(cat .subdirs); do \
133 if [ -f $$$$file/series ]; then \
134 echo "Converting $$file/series"; \
135 $$(call filter_series,$$$$file/series) | awk -v file="$$$$file/" '$$$$0 !~ /^#/ { print file $$$$0 }' | sed -e s,//,/,g >> series; \
137 echo "Sorting patches in $$$$file"; \
138 find $$$$file/* -type f \! -name series | sed -e s,//,/,g | sort >> series; \
142 find * -type f \! -name series | sort > series; \
147 $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED) FORCE
148 $($(2)STAMP_CHECKED): $($(2)STAMP_PATCHED)
149 if [ -s "$(1)/patches/series" ]; then \
151 if $(QUILT_CMD) next >/dev/null 2>&1; then \
152 $(QUILT_CMD) push -a; \
154 $(QUILT_CMD) top >/dev/null 2>&1; \
160 $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
161 @[ -f "$(1)/.quilt_used" ] || { \
162 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
165 @[ -f "$(1)/patches/series" ] || { \
166 echo "The source directory contains no quilt patches."; \
169 @[ -n "$$$$(ls $(1)/patches/series)" -o "$$$$(cat $(1)/patches/series | md5sum)" = "$$(sort $(1)/patches/series | md5sum)" ] || { \
170 echo "The patches are not sorted in the right order. Please fix."; \
174 $(3)refresh: $(3)quilt-check
175 @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
176 @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
177 QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
178 done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
179 $(Quilt/Refresh/$(4))
181 $(3)update: $(3)quilt-check
182 $(Quilt/Refresh/$(4))
185 Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
186 Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)