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

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

Minor tweaks to openwrt.mk. Allow for "-all" to indicate a patch for all
branches (adds symetry with "all" directory). Turn list of patch
directories into a variable, allows for plugins to use system by adding
to value. openwrt/unpatch shouldn't fail if the branch hasn't been
checked out, nor should it fail if run multiple times, fixed.

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