Root/include/quilt.mk

Source at commit d87c24664006f80ccd12d42fd735fefda4fa50aa created 13 years 21 days ago.
By Xiangfu Liu, update opkg.conf, don't using /tmp keep packages information
1#
2# Copyright (C) 2007-2009 OpenWrt.org
3#
4# This is free software, licensed under the GNU General Public License v2.
5# See /LICENSE for more information.
6
7ifneq ($(if $(DUMP),1,$(__quilt_inc)),1)
8__quilt_inc:=1
9
10ifeq ($(TARGET_BUILD),1)
11  PKG_BUILD_DIR:=$(LINUX_DIR)
12endif
13PATCH_DIR?=./patches
14FILES_DIR?=./files
15HOST_PATCH_DIR?=$(PATCH_DIR)
16HOST_FILES_DIR?=$(FILES_DIR)
17
18ifeq ($(MAKECMDGOALS),refresh)
19  override QUILT=1
20endif
21
22QUILT_CMD:=quilt --quiltrc=-
23
24define filter_series
25sed -e s,\\\#.*,, $(1) | grep -E \[a-zA-Z0-9\]
26endef
27
28define PatchDir/Quilt
29    @mkdir -p "$(1)/patches$(if $(3),/$(patsubst %/,%,$(3)))"
30    @if [ -s "$(2)/series" ]; then \
31        mkdir -p "$(1)/patches/$(3)"; \
32        cp "$(2)/series" "$(1)/patches/$(3)"; \
33    fi
34    @for patch in $$$$( (cd "$(2)" && if [ -f series ]; then $(call filter_series,series); else ls | sort; fi; ) 2>/dev/null ); do ( \
35        cp "$(2)/$$$$patch" "$(1)/patches/$(3)"; \
36        echo "$(3)$$$$patch" >> "$(1)/patches/series"; \
37    ); done
38    $(if $(3),@echo $(3) >> "$(1)/patches/.subdirs")
39endef
40
41define PatchDir/Default
42    @if [ -d "$(2)" -a "$$$$(ls $(2) | wc -l)" -gt 0 ]; then \
43        if [ -s "$(2)/series" ]; then \
44            $(call filter_series,$(2)/series) | xargs -n1 \
45                $(PATCH) "$(1)" "$(2)"; \
46        else \
47            $(PATCH) "$(1)" "$(2)"; \
48        fi; \
49    fi
50endef
51
52define PatchDir
53$(call PatchDir/$(if $(strip $(QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
54endef
55
56define HostPatchDir
57$(call PatchDir/$(if $(strip $(HOST_QUILT)),Quilt,Default),$(strip $(1)),$(strip $(2)),$(strip $(3)))
58endef
59
60ifneq ($(PKG_BUILD_DIR),)
61  QUILT?=$(if $(wildcard $(PKG_BUILD_DIR)/.quilt_used),y)
62  ifneq ($(QUILT),)
63    STAMP_CHECKED:=$(PKG_BUILD_DIR)/.quilt_checked
64    override CONFIG_AUTOREBUILD=
65    quilt-check: $(STAMP_CHECKED)
66  endif
67endif
68
69ifneq ($(HOST_BUILD_DIR),)
70  HOST_QUILT?=$(if $(findstring command,$(origin QUILT)),$(QUILT),$(if $(wildcard $(HOST_BUILD_DIR)/.quilt_used),y))
71  ifneq ($(HOST_QUILT),)
72    HOST_STAMP_CHECKED:=$(HOST_BUILD_DIR)/.quilt_checked
73    override CONFIG_AUTOREBUILD=
74    host-quilt-check: $(HOST_STAMP_CHECKED)
75  endif
76endif
77
78define Host/Patch/Default
79    $(if $(HOST_QUILT),rm -rf $(HOST_BUILD_DIR)/patches; mkdir -p $(HOST_BUILD_DIR)/patches)
80    $(call HostPatchDir,$(HOST_BUILD_DIR),$(HOST_PATCH_DIR),)
81    $(if $(HOST_QUILT),touch $(HOST_BUILD_DIR)/.quilt_used)
82endef
83
84define Build/Patch/Default
85    $(if $(QUILT),rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches)
86    $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),)
87    $(if $(QUILT),touch $(PKG_BUILD_DIR)/.quilt_used)
88endef
89
90kernel_files=$(foreach fdir,$(GENERIC_FILES_DIR) $(FILES_DIR),$(fdir)/.)
91define Kernel/Patch/Default
92    rm -rf $(PKG_BUILD_DIR)/patches; mkdir -p $(PKG_BUILD_DIR)/patches
93    $(if $(kernel_files),$(CP) $(kernel_files) $(LINUX_DIR)/)
94    find $(LINUX_DIR)/ -name \*.rej -or -name \*.orig | $(XARGS) rm -f
95    $(call PatchDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
96    $(call PatchDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
97endef
98
99define Quilt/RefreshDir
100    mkdir -p $(2)
101    -rm -f $(2)/* 2>/dev/null >/dev/null
102    @( \
103        for patch in $$$$($(if $(3),grep "^$(3)",cat) $(1)/patches/series | awk '{print $$$$1}'); do \
104            $(CP) -v "$(1)/patches/$$$$patch" $(2); \
105        done; \
106    )
107endef
108
109define Quilt/Refresh/Host
110    $(call Quilt/RefreshDir,$(HOST_BUILD_DIR),$(PATCH_DIR))
111endef
112
113define Quilt/Refresh/Package
114    $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR))
115endef
116
117define Quilt/Refresh/Kernel
118    @[ -z "$$(grep -v '^generic/' $(PKG_BUILD_DIR)/patches/series | grep -v '^platform/')" ] || { \
119        echo "All kernel patches must start with either generic/ or platform/"; \
120        false; \
121    }
122    $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(GENERIC_PATCH_DIR),generic/)
123    $(call Quilt/RefreshDir,$(PKG_BUILD_DIR),$(PATCH_DIR),platform/)
124endef
125
126define Quilt/Template
127  $($(2)STAMP_CONFIGURED): $($(2)STAMP_CHECKED) FORCE
128  $($(2)STAMP_CHECKED): $($(2)STAMP_PREPARED)
129    if [ -s "$(1)/patches/series" ]; then \
130        (cd "$(1)"; \
131            if $(QUILT_CMD) next >/dev/null 2>&1; then \
132                $(QUILT_CMD) push -a; \
133            else \
134                $(QUILT_CMD) top >/dev/null 2>&1; \
135            fi \
136        ); \
137    fi
138    touch "$$@"
139
140  $(3)quilt-check: $($(2)STAMP_PREPARED) FORCE
141    @[ -f "$(1)/.quilt_used" ] || { \
142        echo "The source directory was not unpacked using quilt. Please rebuild with QUILT=1"; \
143        false; \
144    }
145    @[ -f "$(1)/patches/series" ] || { \
146        echo "The source directory contains no quilt patches."; \
147        false; \
148    }
149    @[ -n "$$$$(ls $(1)/patches/series)" -o "$$$$(cat $(1)/patches/series | md5sum)" = "$$(sort $(1)/patches/series | md5sum)" ] || { \
150        echo "The patches are not sorted in the right order. Please fix."; \
151        false; \
152    }
153
154  $(3)refresh: $(3)quilt-check
155    @cd "$(1)"; $(QUILT_CMD) pop -a -f >/dev/null 2>/dev/null
156    @cd "$(1)"; while $(QUILT_CMD) next 2>/dev/null >/dev/null && $(QUILT_CMD) push; do \
157        QUILT_DIFF_OPTS="-p" $(QUILT_CMD) refresh -p ab --no-index --no-timestamps; \
158    done; ! $(QUILT_CMD) next 2>/dev/null >/dev/null
159    $(Quilt/Refresh/$(4))
160    
161  $(3)update: $(3)quilt-check
162    $(Quilt/Refresh/$(4))
163endef
164
165Build/Quilt=$(call Quilt/Template,$(PKG_BUILD_DIR),,,$(if $(TARGET_BUILD),Kernel,Package))
166Host/Quilt=$(call Quilt/Template,$(HOST_BUILD_DIR),HOST_,host-,Host)
167
168endif
169

Archive Download this file



interactive