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