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 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
25 @if [ -s $(1)/series ]; then \
26 mkdir -p $(PKG_BUILD_DIR)/patches/$(2); \
27 cp $(1)/series $(PKG_BUILD_DIR)/patches/$(2); \
29 @for patch in $$$$( (cd $(1) && if [ -f series ]; then $(call filter_series,series); else ls; fi; ) 2>/dev/null ); do ( \
30 cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
31 cd $(PKG_BUILD_DIR); \
32 quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
33 quilt push -f >/dev/null 2>/dev/null; \
36 $(if $(2),@echo $(2) >> $(PKG_BUILD_DIR)/patches/.subdirs)
39 define PatchDir/Default
40 @if [ -d "$(1)" -a "$$$$(ls $(1) | wc -l)" -gt 0 ]; then \
41 if [ -s "$(1)/series" ]; then \
42 $(call filter_series,$(1)/series) | xargs -n1 \
43 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
45 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
51 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)))
54 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
56 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
57 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
58 override CONFIG_AUTOREBUILD=
59 prepare: $(STAMP_PATCHED)
60 quilt-check: $(STAMP_CHECKED)
63 define Build/Patch/Default
64 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
65 $(call PatchDir,$(PATCH_DIR),)
68 define Kernel/Patch/Default
69 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
70 if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
71 if [ -d ./files ]; then \
72 $(CP) ./files/* $(LINUX_DIR)/; \
73 find $(LINUX_DIR)/ -name \*.rej | xargs rm -f; \
75 $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
76 $(call PatchDir,$(PATCH_DIR),platform/)
79 define Quilt/RefreshDir
81 -rm -f $(1)/* 2>/dev/null >/dev/null
83 for patch in $$$$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
84 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(1); \
89 define Quilt/Refresh/Package
90 $(call Quilt/RefreshDir,$(PATCH_DIR))
93 define Quilt/Refresh/Kernel
94 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
95 echo "All kernel patches must start with either generic/ or platform/"; \
98 $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
99 $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
103 $(if $(TARGET_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
107 $(STAMP_PATCHED): $(STAMP_PREPARED)
109 cd $(PKG_BUILD_DIR)/patches; \
110 quilt pop -a -f >/dev/null 2>/dev/null; \
111 if [ -s ".subdirs" ]; then \
113 for file in $$$$(cat .subdirs); do \
114 if [ -f $$$$file/series ]; then \
115 echo "Converting $$file/series"; \
116 $$(call filter_series,$$$$file/series) | awk -v file="$$$$file/" '$$$$0 !~ /^#/ { print file $$$$0 }' | sed -e s,//,/,g >> series; \
118 echo "Sorting patches in $$$$file"; \
119 find $$$$file/* -type f \! -name series | sed -e s,//,/,g | sort >> series; \
123 find * -type f \! -name series | sort > series; \
128 $(STAMP_CONFIGURED): $(STAMP_CHECKED) FORCE
129 $(STAMP_CHECKED): $(STAMP_PATCHED)
130 if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt next >/dev/null 2>&1 && quilt push -a || quilt top >/dev/null 2>&1); fi
133 quilt-check: $(STAMP_PREPARED) FORCE
134 @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
135 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
138 @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
139 echo "The source directory contains no quilt patches."; \
142 @[ -n "$$$$(ls $(PKG_BUILD_DIR)/patches/series)" -o "$$$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
143 echo "The patches are not sorted in the right order. Please fix."; \
148 @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
149 @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
151 done; ! quilt next 2>/dev/null >/dev/null