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.
7 ifneq ($(if $(DUMP),1,$(__quilt_inc)),1)
10 ifeq ($(TARGET_BUILD),1)
11 PKG_BUILD_DIR:=$(LINUX_DIR)
15 HOST_PATCH_DIR?=$(PATCH_DIR)
16 HOST_FILES_DIR?=$(FILES_DIR)
18 ifeq ($(MAKECMDGOALS),refresh)
23 QUILT_CMD:=quilt --quiltrc=-
26 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
30 @mkdir -p "$(1)/patches$(if $(3),/$(patsubst %/,%,$(3)))"
31 @if [ -s "$(2)/series" ]; then \
32 mkdir -p "$(1)/patches/$(3)"; \
33 cp "$(2)/series" "$(1)/patches/$(3)"; \
35 @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls | sort; fi; ) 2>/dev/null ); do ( \
36 cp "$(2)/$$$$patch" "$(1)/patches/$(3)"; \
37 echo "$(3)$$$$patch" >> "$(1)/patches/series"; \
39 $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
42 define PatchDir/Default
43 @if [ -d "$(2)" ] && [ "$$$$(ls $(2) | wc -l)" -gt 0 ]; then \
44 export PATCH="$(PATCH)"; \
45 if [ -s "$(2)/series" ]; then \
46 $(call filter_series,$(2)/series) | xargs -n1 \
47 $(KPATCH) "$(1)" "$(2)"; \
49 $(KPATCH) "$(1)" "$(2)"; \
55 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
59 $(call PatchDir/$(if $(strip $(HOST_QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
62 ifneq ($(PKG_BUILD_DIR),)
63 QUILT?=$(if $(wildcard $(PKG_BUILD_DIR)/.quilt_used),y)
65 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
66 override CONFIG_AUTOREBUILD=
67 quilt-check: $(STAMP_CHECKED)
71 ifneq ($(HOST_BUILD_DIR),)
72 HOST_QUILT?=$(if $(findstring command,$(origin QUILT)),$(QUILT),$(if $(wildcard $(HOST_BUILD_DIR)/.quilt_used),y))
73 ifneq ($(HOST_QUILT),)
74 HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
75 override CONFIG_AUTOREBUILD=
76 host-quilt-check: $(HOST_STAMP_CHECKED)
80 define Host/Patch/Default
81 $(if $(HOST_QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
82 $(call HostPatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
83 $(if $(HOST_QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
86 define Build/Patch/Default
87 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
88 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
89 $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
92 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
93 define Kernel/Patch/Default
94 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
95 $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
96 find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
97 $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
98 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
101 define Quilt/RefreshDir
103 -rm -f $(2)/* 2>/dev/null >/dev/null
105 for patch in $$$$($(if $(3),grep "^$(3)",cat) $(1)/patches/series | awk '{print $$$$1}'); do \
106 $(CP) -v "$(1)/patches/$$$$patch" $(2); \
111 define Quilt/Refresh/Host
112 $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
115 define Quilt/Refresh/Package
116 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
119 define Quilt/Refresh/Kernel
120 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
121 echo "All kernel patches must start with either generic/ or platform/"; \
124 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
125 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
128 define Quilt/Template
129 $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED)
130 $(if $(NO_RECONFIGURE),$($(2)STAMP_BUILT),$($(2)STAMP_CONFIGURED)): FORCE
131 $($(2)STAMP_CHECKED): $($(2)STAMP_PREPARED)
132 if [ -s "$(1)/patches/series" ]; then \
134 if $(QUILT_CMD) next >/dev/null 2>&1; then \
135 $(QUILT_CMD) push -a; \
137 $(QUILT_CMD) top >/dev/null 2>&1; \
143 $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
144 @[ -f "$(1)/.quilt_used" ] || { \
145 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
148 @[ -f "$(1)/patches/series" ] || { \
149 echo "The source directory contains no quilt patches."; \
152 @[ -n "$$$$(ls $(1)/patches/series)" -o "$$$$(cat $(1)/patches/series | md5sum)" = "$$(sort $(1)/patches/series | md5sum)" ] || { \
153 echo "The patches are not sorted in the right order. Please fix."; \
157 $(3)refresh: $(3)quilt-check
158 @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
159 @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
160 QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
161 done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
162 $(Quilt/Refresh/$(4))
164 $(3)update: $(3)quilt-check
165 $(Quilt/Refresh/$(4))
168 Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
169 Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)