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