lzma: use a repacked tarball instead of the original one to get rid of CRLF conversio...
[openwrt.git] / include / quilt.mk
1 #
2 # Copyright (C) 2007-2009 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7
8 ifneq ($(__quilt_inc),1)
9 __quilt_inc:=1
10
11 ifeq ($(TARGET_BUILD),1)
12 PKG_BUILD_DIR:=$(LINUX_DIR)
13 endif
14 PATCH_DIR?=./patches
15 FILES_DIR?=./files
16
17 ifeq ($(MAKECMDGOALS),refresh)
18 override QUILT=1
19 endif
20
21 QUILT_CMD:=quilt --quiltrc=-
22
23 define filter_series
24 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
25 endef
26
27 define PatchDir/Quilt
28 @if [ -s $(1)/series ]; then \
29 mkdir -p $(PKG_BUILD_DIR)/patches/$(2); \
30 cp $(1)/series $(PKG_BUILD_DIR)/patches/$(2); \
31 fi
32 @for patch in $$$$( (cd $(1) && if [ -f series ]; then $(call filter_series,series); else ls; fi; ) 2>/dev/null ); do ( \
33 cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
34 cd $(PKG_BUILD_DIR); \
35 $(QUILT_CMD) import -P$(2)$$$$patch -p 1 "$$$$patch"; \
36 $(QUILT_CMD) push -f >/dev/null 2>/dev/null; \
37 rm -f "$$$$patch"; \
38 ); done
39 $(if $(2),@echo $(2) >> $(PKG_BUILD_DIR)/patches/.subdirs)
40 endef
41
42 define PatchDir/Default
43 @if [ -d "$(1)" -a "$$$$(ls $(1) | wc -l)" -gt 0 ]; then \
44 if [ -s "$(1)/series" ]; then \
45 $(call filter_series,$(1)/series) | xargs -n1 \
46 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
47 else \
48 $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
49 fi; \
50 fi
51 endef
52
53 define PatchDir
54 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)))
55 endef
56
57 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
58 ifneq ($(QUILT),)
59 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
60 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
61 override CONFIG_AUTOREBUILD=
62 prepare: $(STAMP_PATCHED)
63 quilt-check: $(STAMP_CHECKED)
64 endif
65
66 define Build/Patch/Default
67 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
68 $(call PatchDir,$(PATCH_DIR),)
69 endef
70
71 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
72 define Kernel/Patch/Default
73 rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
74 $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
75 find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
76 $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
77 $(call PatchDir,$(PATCH_DIR),platform/)
78 endef
79
80 define Quilt/RefreshDir
81 mkdir -p $(1)
82 -rm -f $(1)/* 2>/dev/null >/dev/null
83 @( \
84 for patch in $$$$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
85 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(1); \
86 done; \
87 )
88 endef
89
90 define Quilt/Refresh/Package
91 $(call Quilt/RefreshDir,$(PATCH_DIR))
92 endef
93
94 define Quilt/Refresh/Kernel
95 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
96 echo "All kernel patches must start with either generic/ or platform/"; \
97 false; \
98 }
99 $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
100 $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
101 endef
102
103 define Quilt/Refresh
104 $(if $(TARGET_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
105 endef
106
107 define Build/Quilt
108 $(STAMP_PATCHED): $(STAMP_PREPARED)
109 @( \
110 cd $(PKG_BUILD_DIR)/patches; \
111 $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null; \
112 if [ -s ".subdirs" ]; then \
113 rm -f series; \
114 for file in $$$$(cat .subdirs); do \
115 if [ -f $$$$file/series ]; then \
116 echo "Converting $$file/series"; \
117 $$(call filter_series,$$$$file/series) | awk -v file="$$$$file/" '$$$$0 !~ /^#/ { print file $$$$0 }' | sed -e s,//,/,g >> series; \
118 else \
119 echo "Sorting patches in $$$$file"; \
120 find $$$$file/* -type f \! -name series | sed -e s,//,/,g | sort >> series; \
121 fi; \
122 done; \
123 else \
124 find * -type f \! -name series | sort > series; \
125 fi; \
126 )
127 touch $$@
128
129 $(STAMP_CONFIGURED): $(STAMP_CHECKED) FORCE
130 $(STAMP_CHECKED): $(STAMP_PATCHED)
131 if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); if $(QUILT_CMD) next >/dev/null 2>&1; then $(QUILT_CMD) push -a; else $(QUILT_CMD) top >/dev/null 2>&1; fi); fi
132 touch $$@
133
134 quilt-check: $(STAMP_PREPARED) FORCE
135 @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
136 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
137 false; \
138 }
139 @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
140 echo "The source directory contains no quilt patches."; \
141 false; \
142 }
143 @[ -n "$$$$(ls $(PKG_BUILD_DIR)/patches/series)" -o "$$$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
144 echo "The patches are not sorted in the right order. Please fix."; \
145 false; \
146 }
147
148 refresh: quilt-check
149 @cd $(PKG_BUILD_DIR); $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
150 @cd $(PKG_BUILD_DIR); while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
151 QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
152 done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
153 $(Quilt/Refresh)
154
155 update: quilt-check
156 $(Quilt/Refresh)
157 endef
158
159 endif
This page took 0.055442 seconds and 5 git commands to generate.