source: branches/contrib/openwrt/openwrt.mk @ 349

Last change on this file since 349 was 349, checked in by ehem, 8 years ago

Rework the openwrt/patch target. Instead of patching with a hand-rolled
list of patches, scan the appropriate directories for patch files. Patch
filenames now MUST match the pattern [0-9]+(-[0-9]*:[0-9]*)_<name>. The
lead digits specify order of application, lower numbers are applied
first. If present, the two subsequent numbers indicate a range of
Subversion revisions that a given patch applies to. If a number is
absent, the range is interpreted to include all older revisions or all
newer revisions as appropriate.

Adjust openwrt/unpatch target to match (patches are now removed in
reverse order). Adjust the generate script to match.

File size: 5.9 KB
Line 
1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010 Johan van Zoomeren <amain@debwrt.net>
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18OPENWRT_PATCHES_DIR=$(TOPDIR)/openwrt/patches
19
20openwrt/all: openwrt/build
21        $(MAKE) -C $(TOPDIR) openwrt/deliver
22        touch $@
23
24openwrt/build: openwrt/prepare
25ifeq ("$(origin V)", "command line")
26        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V)
27else
28        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS)
29endif
30        touch $@
31
32openwrt/download:
33ifeq ("$(origin V)", "command line")
34        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download V=$(V)
35else
36        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download
37endif
38        touch $@
39
40openwrt/prepare: \
41  openwrt/checkout \
42  openwrt/patch \
43  openwrt/files-copy \
44  plugins/apply-openwrt \
45  openwrt/merge-config \
46  openwrt/download-link \
47  # end openwrt/prepare:
48        touch $@
49
50openwrt/merge-config: .config $(OPENWRT_BUILD_DIR)/.config openwrt/checkout openwrt/patch
51        mkdir -p $(TMP_DIR)
52        # Copy default OpenWrt settings
53        cp $(CONFIG_DIR)/openwrt.defconfig $(TMP_DIR)/.config_openwrt
54        # Merge default OpenWrt settings with DebWrt menu config settings
55        #cat .config | grep -v -e CONFIG_TARGET_BOARD -e "^#" >> $(TMP_DIR)/.config_openwrt
56        cat .config | grep -v -e CONFIG_TARGET_BOARD >> $(TMP_DIR)/.config_openwrt
57        # Merge default and menu settings with possibly altered settings in make menuconfig in OpenWrt
58        # note: settings manually made in OpenWrt menu config will be included!
59        touch $(OPENWRT_BUILD_DIR)/.config
60        cp $(OPENWRT_BUILD_DIR)/.config $(OPENWRT_BUILD_DIR)/.config.org
61        $(SCRIPT_KCONFIG) + $(OPENWRT_BUILD_DIR)/.config.org $(TMP_DIR)/.config_openwrt > $(OPENWRT_BUILD_DIR)/.config
62        # Filter out config options unknown to OpenWrt (e.g. pure kernel known options) / clean up OpenWrt config
63        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) defconfig
64        # Save .config to OpenWrt build-dir. During the OpenWrt build the .config kernel options are
65        # merged with the OpenWrt's default kernel options for the target. In this phase any DebWrt/OpenWrt
66        # specific options in the .config file are filtered out. See include/kernel-defaults.mk from OpenWrt.
67        cp .config $(OPENWRT_BUILD_DIR)/.config.debwrt
68        touch $@
69
70$(OPENWRT_BUILD_DIR)/.config: openwrt/checkout
71        [ ! -f $@ ] && touch $(OPENWRT_BUILD_DIR)/.config
72
73openwrt/download-link: openwrt/checkout
74ifneq ($(OPENWRT_DOWNLOAD_DIR),)
75        cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi
76endif
77        touch $@
78
79openwrt/patch: openwrt/checkout
80        rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
81        field=`echo "$(OPENWRT_PATCHES_DIR)" | awk -F / '{print NF+2}'` ; \
82        find "$(OPENWRT_PATCHES_DIR)/all" "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)" -name .svn -prune -o -print | \
83        awk -F / \
84          'match($$'$${field}', "^[[:digit:]]+(-([[:digit:]]*):([[:digit:]]*))?_", revs) \
85          { if(revs[2] <= "'$${rev}'" && (!length(revs[3]) || revs[3] >= "'$${rev}'")) print }' | \
86        sort -t / -k $${field} | \
87        while read pat ; \
88        do \
89                if ! patch -d "$(OPENWRT_BUILD_DIR)" -p 0 -N < $${pat} ; \
90                then \
91                        echo Failed applying patch: $${pat} > /dev/stderr ; \
92                        rm -f openwrt/checkout "$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp" ; \
93                        exit 1 ; \
94                fi ; \
95        done ; \
96        touch $@
97
98openwrt/unpatch: openwrt/checkout
99        rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
100        field=`echo "$(OPENWRT_PATCHES_DIR)" | awk -F / '{print NF+2}'` ; \
101        find "$(OPENWRT_PATCHES_DIR)/all" "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)" -name .svn -prune -o -print | \
102        awk -F / \
103          'match($$'$${field}', "^[[:digit:]]+(-([[:digit:]]*):([[:digit:]]*))?_", revs) \
104          { if(revs[2] <= "'$${rev}'" && (!length(revs[3]) || revs[3] >= "'$${rev}'")) print }' | \
105        sort -t / -k $${field} -r | \
106        while read pat ; \
107        do \
108                if ! patch -d "$(OPENWRT_BUILD_DIR)" -p 0 -R < $${pat} ; \
109                then \
110                        echo Failed removing patch: $${pat} > /dev/stderr ; \
111                        rm -f openwrt/checkout "$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp" ; \
112                        exit 1 ; \
113                fi ; \
114        done ; \
115        rm openwrt/patch
116        touch $@
117
118
119openwrt/files-copy: openwrt/patch
120        tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \
121          tar -C $(OPENWRT_BUILD_DIR) -xpf - && \
122        touch $@
123
124ifeq ($(OPENWRT_BRANCH),trunk)
125OPENWRT_SUBVERSION:=svn://svn.openwrt.org/openwrt/trunk/
126else
127OPENWRT_SUBVERSION:=svn://svn.openwrt.org/openwrt/branches/$(OPENWRT_BRANCH)/
128endif
129
130$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp:
131openwrt/checkout: $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
132        rm -rf $(OPENWRT_BUILD_DIR) && \
133        svn co -r $(OPENWRT_REVISION) $(OPENWRT_SUBVERSION) $(OPENWRT_BUILD_DIR) && \
134        touch $@ $<
135
136openwrt/update: openwrt/checkout
137        svn up -r $(OPENWRT_REVISION) $(OPENWRT_BUILD_DIR)
138
139openwrt/menuconfig: openwrt/prepare
140        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig
141
142# Tune kernel configuration
143openwrt/kernel_menuconfig: openwrt/prepare
144        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) kernel_menuconfig
145        rm -f openwrt/build
146
147openwrt/clean:
148        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V)
149
150openwrt/dirclean:
151        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V)
152
153openwrt/distclean:
154        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V)
155
156openwrt/debwrt-clean:
157        rm -rf $(OPENWRT_BUILD_DIR)
158        rm -f openwrt/checkout
159        rm -f openwrt/patch
160        rm -f openwrt/files-copy
161
Note: See TracBrowser for help on using the repository browser.