uboot-imx6: switch to u-boot.mk
[openwrt/staging/yousong.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 ifneq ($(if $(DUMP),1,$(__quilt_inc)),1)
8 __quilt_inc:=1
9
10 ifeq ($(TARGET_BUILD),1)
11 PKG_BUILD_DIR:=$(LINUX_DIR)
12 endif
13 PATCH_DIR?=./patches
14 FILES_DIR?=./files
15 HOST_PATCH_DIR?=$(PATCH_DIR)
16 HOST_FILES_DIR?=$(FILES_DIR)
17
18 ifeq ($(MAKECMDGOALS),refresh)
19 override QUILT=1
20 override HOST_QUILT=1
21 endif
22
23 QUILT_CMD:=quilt --quiltrc=-
24
25 define filter_series
26 sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
27 endef
28
29 define PatchDir/Quilt
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)"; \
34 fi
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"; \
38 ); done
39 $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
40 endef
41
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)"; \
48 else \
49 $(KPATCH) "$(1)" "$(2)"; \
50 fi; \
51 fi
52 endef
53
54 define PatchDir
55 $(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
56 endef
57
58 define HostPatchDir
59 $(call PatchDir/$(if $(strip $(HOST_QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
60 endef
61
62 ifneq ($(PKG_BUILD_DIR),)
63 QUILT?=$(if $(wildcard $(PKG_BUILD_DIR)/.quilt_used),y)
64 ifneq ($(QUILT),)
65 STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
66 override CONFIG_AUTOREBUILD=
67 override CONFIG_AUTOREMOVE=
68 quilt-check: $(STAMP_CHECKED)
69 endif
70 endif
71
72 ifneq ($(HOST_BUILD_DIR),)
73 HOST_QUILT?=$(if $(findstring command,$(origin QUILT)),$(QUILT),$(if $(wildcard $(HOST_BUILD_DIR)/.quilt_used),y))
74 ifneq ($(HOST_QUILT),)
75 HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
76 override CONFIG_AUTOREBUILD=
77 override CONFIG_AUTOREMOVE=
78 host-quilt-check: $(HOST_STAMP_CHECKED)
79 endif
80 endif
81
82 define Host/Patch/Default
83 $(if $(HOST_QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
84 $(call HostPatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
85 $(if $(HOST_QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
86 endef
87
88 define Build/Patch/Default
89 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
90 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
91 $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
92 endef
93
94 kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
95 define Kernel/Patch/Default
96 $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
97 $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
98 find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
99 $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
100 $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
101 endef
102
103 define Quilt/RefreshDir
104 mkdir -p $(2)
105 -rm -f $(2)/* 2>/dev/null >/dev/null
106 @( \
107 for patch in $$$$($(if $(3),grep "^$(3)",cat) $(1)/patches/series | awk '{print $$$$1}'); do \
108 $(CP) -v "$(1)/patches/$$$$patch" $(2); \
109 done; \
110 )
111 endef
112
113 define Quilt/Refresh/Host
114 $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
115 endef
116
117 define Quilt/Refresh/Package
118 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
119 endef
120
121 define Quilt/Refresh/Kernel
122 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
123 echo "All kernel patches must start with either generic/ or platform/"; \
124 false; \
125 }
126 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
127 $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
128 endef
129
130 define Quilt/Template
131 $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED)
132 $(if $(NO_RECONFIGURE),$($(2)STAMP_BUILT),$($(2)STAMP_CONFIGURED)): FORCE
133 $($(2)STAMP_CHECKED): $($(2)STAMP_PREPARED)
134 if [ -s "$(1)/patches/series" ]; then \
135 (cd "$(1)"; \
136 if $(QUILT_CMD) next >/dev/null 2>&1; then \
137 $(QUILT_CMD) push -a; \
138 else \
139 $(QUILT_CMD) top >/dev/null 2>&1; \
140 fi \
141 ); \
142 fi
143 touch "$$@"
144
145 $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
146 @[ -f "$(1)/.quilt_used" ] || { \
147 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
148 false; \
149 }
150 @[ -f "$(1)/patches/series" ] || { \
151 echo "The source directory contains no quilt patches."; \
152 false; \
153 }
154 @[ -n "$$$$(ls $(1)/patches/series)" -o \
155 "$$$$(cat $(1)/patches/series | mkhash md5)" = "$$(sort $(1)/patches/series | mkhash md5)" ] || { \
156 echo "The patches are not sorted in the right order. Please fix."; \
157 false; \
158 }
159
160 $(3)refresh: $(3)quilt-check
161 @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
162 @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
163 QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
164 done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
165 $(Quilt/Refresh/$(4))
166
167 $(3)update: $(3)quilt-check
168 $(Quilt/Refresh/$(4))
169 endef
170
171 Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
172 Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)
173
174 endif