source: trunk/include/quilt.mk @ 13021

Last change on this file since 13021 was 13021, checked in by nbd, 8 years ago

fix prepare error with brcm-2.4 and missing files/ (thx, thepeople)

File size: 4.7 KB
Line 
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
8ifneq ($(__quilt_inc),1)
9__quilt_inc:=1
10
11ifeq ($(TARGET_BUILD),1)
12  PKG_BUILD_DIR:=$(LINUX_DIR)
13endif
14PATCH_DIR?=./patches
15FILES_DIR?=./files
16
17ifeq ($(MAKECMDGOALS),refresh)
18  override QUILT=1
19endif
20
21define filter_series
22sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
23endef
24
25define PatchDir/Quilt
26        @if [ -s $(1)/series ]; then \
27                mkdir -p $(PKG_BUILD_DIR)/patches/$(2); \
28                cp $(1)/series $(PKG_BUILD_DIR)/patches/$(2); \
29        fi
30        @for patch in $$$$( (cd $(1) && if [ -f series ]; then $(call filter_series,series); else ls; fi; ) 2>/dev/null ); do ( \
31                cp "$(1)/$$$$patch" $(PKG_BUILD_DIR); \
32                cd $(PKG_BUILD_DIR); \
33                quilt import -P$(2)$$$$patch -p 1 "$$$$patch"; \
34                quilt push -f >/dev/null 2>/dev/null; \
35                rm -f "$$$$patch"; \
36        ); done
37        $(if $(2),@echo $(2) >> $(PKG_BUILD_DIR)/patches/.subdirs)
38endef
39
40define PatchDir/Default
41        @if [ -d "$(1)" -a "$$$$(ls $(1) | wc -l)" -gt 0 ]; then \
42                if [ -s "$(1)/series" ]; then \
43                        $(call filter_series,$(1)/series) | xargs -n1 \
44                                $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
45                else \
46                        $(PATCH) $(PKG_BUILD_DIR) "$(1)"; \
47                fi; \
48        fi
49endef
50
51define PatchDir
52$(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)))
53endef
54
55QUILT?=$(strip $(shell test -f $(PKG_BUILD_DIR)/.quilt_used && echo y))
56ifneq ($(QUILT),)
57  STAMP_PATCHED:=$(PKG_BUILD_DIR)/.quilt_patched
58  STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
59  override CONFIG_AUTOREBUILD=
60  prepare: $(STAMP_PATCHED)
61  quilt-check: $(STAMP_CHECKED)
62endif
63
64define Build/Patch/Default
65        $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
66        $(call PatchDir,$(PATCH_DIR),)
67endef
68
69kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
70define Kernel/Patch/Default
71        rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
72        $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
73        find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
74        $(call PatchDir,$(GENERIC_PATCH_DIR),generic/)
75        $(call PatchDir,$(PATCH_DIR),platform/)
76endef
77
78define Quilt/RefreshDir
79        mkdir -p $(1)
80        -rm -f $(1)/* 2>/dev/null >/dev/null
81        @( \
82                for patch in $$$$($(if $(2),grep "^$(2)",cat) $(PKG_BUILD_DIR)/patches/series | awk '{print $$$$1}'); do \
83                        $(CP) -v "$(PKG_BUILD_DIR)/patches/$$$$patch" $(1); \
84                done; \
85        )
86endef
87
88define Quilt/Refresh/Package
89        $(call Quilt/RefreshDir,$(PATCH_DIR))
90endef
91
92define Quilt/Refresh/Kernel
93        @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
94                echo "All kernel patches must start with either generic/ or platform/"; \
95                false; \
96        }
97        $(call Quilt/RefreshDir,$(GENERIC_PATCH_DIR),generic/)
98        $(call Quilt/RefreshDir,$(PATCH_DIR),platform/)
99endef
100
101define Quilt/Refresh
102$(if $(TARGET_BUILD),$(Quilt/Refresh/Kernel),$(Quilt/Refresh/Package))
103endef
104
105define Build/Quilt
106  $(STAMP_PATCHED): $(STAMP_PREPARED)
107        @( \
108                cd $(PKG_BUILD_DIR)/patches; \
109                quilt pop -a -f >/dev/null 2>/dev/null; \
110                if [ -s ".subdirs" ]; then \
111                        rm -f series; \
112                        for file in $$$$(cat .subdirs); do \
113                                if [ -f $$$$file/series ]; then \
114                                        echo "Converting $$file/series"; \
115                                        $$(call filter_series,$$$$file/series) | awk -v file="$$$$file/" '$$$$0 !~ /^#/ { print file $$$$0 }' | sed -e s,//,/,g >> series; \
116                                else \
117                                        echo "Sorting patches in $$$$file"; \
118                                        find $$$$file/* -type f \! -name series | sed -e s,//,/,g | sort >> series; \
119                                fi; \
120                        done; \
121                else \
122                        find * -type f \! -name series | sort > series; \
123                fi; \
124        )
125        touch $$@
126
127  $(STAMP_CONFIGURED): $(STAMP_CHECKED) FORCE
128  $(STAMP_CHECKED): $(STAMP_PATCHED)
129        if [ -s "$(PKG_BUILD_DIR)/patches/series" ]; then (cd $(PKG_BUILD_DIR); quilt next >/dev/null 2>&1 && quilt push -a || quilt top >/dev/null 2>&1); fi
130        touch $$@
131
132  quilt-check: $(STAMP_PREPARED) FORCE
133        @[ -f "$(PKG_BUILD_DIR)/.quilt_used" ] || { \
134                echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
135                false; \
136        }
137        @[ -f "$(PKG_BUILD_DIR)/patches/series" ] || { \
138                echo "The source directory contains no quilt patches."; \
139                false; \
140        }
141        @[ -n "$$$$(ls $(PKG_BUILD_DIR)/patches/series)" -o "$$$$(cat $(PKG_BUILD_DIR)/patches/series | md5sum)" = "$$(sort $(PKG_BUILD_DIR)/patches/series | md5sum)" ] || { \
142                echo "The patches are not sorted in the right order. Please fix."; \
143                false; \
144        }
145
146  refresh: quilt-check
147        @cd $(PKG_BUILD_DIR); quilt pop -a -f >/dev/null 2>/dev/null
148        @cd $(PKG_BUILD_DIR); while quilt next 2>/dev/null >/dev/null && quilt push; do \
149                QUILT_DIFF_OPTS="-p" quilt refresh -p ab --no-index --quiltrc=/dev/null --no-timestamps; \
150        done; ! quilt next 2>/dev/null >/dev/null
151        $(Quilt/Refresh)
152       
153  update: quilt-check
154        $(Quilt/Refresh)
155endef
156
157endif
Note: See TracBrowser for help on using the repository browser.