Improve quilt patch handling: All quilt managed patches are checked before the packag...
[lede.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)
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         cd $(PKG_BUILD_DIR); quilt push -a
40         touch $@
41
42 refresh: $(STAMP_PREPARED)
43         @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
44                 echo "The source directory was not unpacked using quilt. Please rebuild."; \
45                 false; \
46         }
47         @[ "$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
48                 echo "The patches are not sorted in the right order. Please fix."; \
49                 false; \
50         }
51         rm -f ./patches/* 2>/dev/null >/dev/null
52         @( \
53                 for patch in $$(cat $(PKG_BUILD_DIR)/patches/series); do \
54                         $(CP) -v "$(PKG_BUILD_DIR)/patches/$$patch" ./patches; \
55                 done; \
56         )