implement quilt handling for the kernel tree ... and there was much rejoicing!
[openwrt/staging/chunkeey.git] / include / quilt.mk
1 #
2 # Copyright (C) 2007 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 ifeq ($(KERNEL_BUILD),1)
9 PKG_BUILD_DIR:=$(LINUX_DIR)
10 endif
11
12 define Quilt/Patch
13 @for patch in $$$$( (cd $(1) && ls) 2>/dev/null ); do ( \
14 cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
15 cd $(PKG_BUILD_DIR); \
16 quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
17 quilt push -f >/dev/null 2>/dev/null; \
18 rm -f "$$$$patch"; \
19 ); done
20 endef
21
22 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
23 ifneq ($(QUILT),)
24 STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
25 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
26 CONFIG_AUTOREBUILD=
27 PATCHES:=$(shell )
28 define Build/Patch/Default
29 rm -rf $(PKG_BUILD_DIR)/patches
30 mkdir -p $(PKG_BUILD_DIR)/patches
31 $(call Quilt/Patch,./patches,)
32 @echo
33 touch $(PKG_BUILD_DIR)/.quilt_used
34 endef
35 $(STAMP_CONFIGURED): $(STAMP_PATCHED)
36 prepare: $(STAMP_PATCHED)
37 else
38 define Build/Patch/Default
39 @if [ -d ./patches -a "$$$$(ls ./patches | wc -l)" -gt 0 ]; then \
40 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
41 fi
42 endef
43 endif
44
45 define Kernel/Patch/Default
46 if [ -d $(GENERIC_PLATFORM_DIR)/files ]; then $(CP) $(GENERIC_PLATFORM_DIR)/files/* $(LINUX_DIR)/; fi
47 if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi
48 $(if $(strip $(QUILT)),$(call Quilt/Patch,$(GENERIC_PLATFORM_DIR)/patches,generic/), \
49 if [ -d $(GENERIC_PLATFORM_DIR)/patches ]; then $(PATCH) $(LINUX_DIR) $(GENERIC_PLATFORM_DIR)/patches; fi \
50 )
51 $(if $(strip $(QUILT)),$(call Quilt/Patch,./patches,platform/), \
52 if [ -d ./files ]; then $(CP) ./files/* $(LINUX_DIR)/; fi \
53 )
54 touch $(PKG_BUILD_DIR)/.quilt_used
55 endef
56
57 $(STAMP_PATCHED): $(STAMP_PREPARED)
58 @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
59 [ -f "$(PKG_BUILD_DIR)/patches/series" ] && cd $(PKG_BUILD_DIR); quilt push -a
60 touch $@
61
62 define Quilt/RefreshDir
63 mkdir -p $(1)
64 -rm -f $(1)/* 2>/dev/null >/dev/null
65 @( \
66 for patch in $$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$1}'); do \
67 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" $(1); \
68 done; \
69 )
70 endef
71
72 define Quilt/Refresh/Package
73 $(call Quilt/RefreshDir,./patches)
74 endef
75
76 define Quilt/Refresh/Kernel
77 @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
78 echo "All kernel patches must start with either generic/ or platform/"; \
79 false; \
80 }
81 $(call Quilt/RefreshDir,$(GENERIC_PLATFORM_DIR)/patches,generic/)
82 $(call Quilt/RefreshDir,./patches,platform/)
83 endef
84
85 refresh: $(STAMP_PREPARED)
86 @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
87 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
88 false; \
89 }
90 @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
91 echo "The source directory contains no quilt patches."; \
92 false; \
93 }
94 @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
95 echo "The patches are not sorted in the right order. Please fix."; \
96 false; \
97 }
98 $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
99