Port the mbsd_multi patch from freewrt, which adds -fhonour-copts. This will emit...
[openwrt-10.03/.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 ifeq ($(MAKECMDGOALS),refresh)
14   override QUILT=1
15 endif
16
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
27 QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
28 ifneq ($(QUILT),)
29   STAMP_PREPARED:=$(strip $(STAMP_PREPARED))_q
30   STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
31   override CONFIG_AUTOREBUILD=
32   define Build/Patch/Default
33         rm -rf $(PKG_BUILD_DIR)/patches
34         mkdir -p $(PKG_BUILD_DIR)/patches
35         $(call Quilt/Patch,$(PATCH_DIR),)
36         @echo
37         touch $(PKG_BUILD_DIR)/.quilt_used
38   endef
39   $(STAMP_CONFIGURED): $(STAMP_PATCHED) FORCE
40   prepare: $(STAMP_PATCHED)
41   quilt-check: $(STAMP_PATCHED)
42 else
43   define Build/Patch/Default
44         @if [ -d $(PATCH_DIR) -a "$$$$(ls $(PATCH_DIR) | wc -l)" -gt 0 ]; then \
45                 $(PATCH) $(PKG_BUILD_DIR) $(PATCH_DIR); \
46         fi
47   endef
48 endif
49
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
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 \
55         )
56         $(if $(strip $(QUILT)),$(call Quilt/Patch,$(PATCH_DIR),platform/), \
57                 if [ -d $(PATCH_DIR) ]; then $(PATCH) $(LINUX_DIR) $(PATCH_DIR); fi \
58         )
59         $(if $(strip $(QUILT)),touch $(PKG_BUILD_DIR)/.quilt_used)
60 endef
61
62 $(STAMP_PATCHED): $(STAMP_PREPARED)
63         @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null || true
64         (\
65                 cd $(PKG_BUILD_DIR)/patches; \
66                 find * -type f \! -name series | sort > series; \
67         )
68         if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt push -a); fi
69         touch $@
70
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
82         $(call Quilt/RefreshDir,$(PATCH_DIR))
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         }
90         $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
91         $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
92 endef
93
94 quilt-check: $(STAMP_PREPARED) FORCE
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         }
99         @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
100                 echo "The source directory contains no quilt patches."; \
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         }
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
116         $(if $(KERNEL_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
117