enable quilt for host builds and add some additional checks
[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 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
9 ifneq ($(QUILT),)
10 STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
11 STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
12 CONFIG_AUTOREBUILD=
13 PATCHES:=$(shell (cd ./patches && ls) 2>/dev/null)
14 define Build/Patch/Default
15 rm -rf $(PKG_BUILD_DIR)/patches
16 mkdir -p $(PKG_BUILD_DIR)/patches
17 @for patch in $(PATCHES); do ( \
18 cp "./patches/$$$$patch" $(PKG_BUILD_DIR); \
19 cd $(PKG_BUILD_DIR); \
20 quilt import -p 1 "$$$$patch"; \
21 quilt push -f >/dev/null 2>/dev/null; \
22 rm -f "$$$$patch"; \
23 ); done
24 @echo
25 touch $(PKG_BUILD_DIR)/.quilt_used
26 endef
27 $(STAMP_CONFIGURED): $(STAMP_PATCHED)
28 prepare: $(STAMP_PATCHED)
29 else
30 define Build/Patch/Default
31 @if [ -d ./patches -a "$$$$(ls ./patches | wc -l)" -gt 0 ]; then \
32 $(PATCH) $(PKG_BUILD_DIR) ./patches; \
33 fi
34 endef
35 endif
36
37 $(STAMP_PATCHED): $(STAMP_PREPARED)
38 @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
39 $(if $(strip $(PATCHES)),cd $(PKG_BUILD_DIR); quilt push -a)
40 touch $@
41
42 refresh: $(STAMP_PREPARED)
43 @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
44 echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
45 false; \
46 }
47 @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
48 echo "The source directory contains no quilt patches."; \
49 false; \
50 }
51 @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
52 echo "The patches are not sorted in the right order. Please fix."; \
53 false; \
54 }
55 mkdir -p ./patches
56 rm -f ./patches/* 2>/dev/null >/dev/null
57 @( \
58 for patch in $$(cat $(PKG_BUILD_DIR)/patches/series); do \
59 $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" ./patches; \
60 done; \
61 )