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

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

Adding note on what has been done in header.

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/all: openwrt/build
26        $(MAKE) -C $(TOPDIR) openwrt/deliver
27        touch $@
28
29openwrt/build: openwrt/prepare
30ifeq ("$(origin V)", "command line")
31        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V)
32else
33        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS)
34endif
35        touch $@
36
37openwrt/download:
38ifeq ("$(origin V)", "command line")
39        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download V=$(V)
40else
41        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download
42endif
43        touch $@
44
45openwrt/prepare: \
46  openwrt/checkout \
47  openwrt/patch \
48  openwrt/files-copy \
49  plugins/apply-openwrt \
50  openwrt/merge-config \
51  openwrt/download-link \
52  # end openwrt/prepare:
53        touch $@
54
55openwrt/merge-config: .config $(OPENWRT_BUILD_DIR)/.config openwrt/checkout openwrt/patch
56        mkdir -p $(TMP_DIR)
57        # Copy default OpenWrt settings
58        cp $(CONFIG_DIR)/openwrt.defconfig $(TMP_DIR)/.config_openwrt
59        # Merge default OpenWrt settings with DebWrt menu config settings
60        #cat .config | grep -v -e CONFIG_TARGET_BOARD -e "^#" >> $(TMP_DIR)/.config_openwrt
61        cat .config | grep -v -e CONFIG_TARGET_BOARD >> $(TMP_DIR)/.config_openwrt
62        # Merge default and menu settings with possibly altered settings in make menuconfig in OpenWrt
63        # note: settings manually made in OpenWrt menu config will be included!
64        touch $(OPENWRT_BUILD_DIR)/.config
65        cp $(OPENWRT_BUILD_DIR)/.config $(OPENWRT_BUILD_DIR)/.config.org
66        $(SCRIPT_KCONFIG) + $(OPENWRT_BUILD_DIR)/.config.org $(TMP_DIR)/.config_openwrt > $(OPENWRT_BUILD_DIR)/.config
67        # Filter out config options unknown to OpenWrt (e.g. pure kernel known options) / clean up OpenWrt config
68        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) defconfig
69        # Save .config to OpenWrt build-dir. During the OpenWrt build the .config kernel options are
70        # merged with the OpenWrt's default kernel options for the target. In this phase any DebWrt/OpenWrt
71        # specific options in the .config file are filtered out. See include/kernel-defaults.mk from OpenWrt.
72        cp .config $(OPENWRT_BUILD_DIR)/.config.debwrt
73        touch $@
74
75$(OPENWRT_BUILD_DIR)/.config: openwrt/checkout
76        [ ! -f $@ ] && touch $(OPENWRT_BUILD_DIR)/.config
77
78openwrt/download-link: openwrt/checkout
79ifneq ($(OPENWRT_DOWNLOAD_DIR),)
80        cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi
81endif
82        touch $@
83
84openwrt/patch: openwrt/checkout
85        rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
86        find \
87          "$(OPENWRT_PATCHES_DIR)/all" "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)" \
88          -name .svn -prune -o \! -type d -printf %f/%p\\n | \
89        gawk \
90          'match($$1, "^[[:digit:]]+(-$(OPENWRT_BRANCH))?(-([[:digit:]]*):([[:digit:]]*))?_", revs) \
91          { if(revs[3] <= '$${rev}' && (!length(revs[4]) || revs[4] >= '$${rev}')) print }' | \
92        sort | sed -e's/^[^/]\+\///' | \
93        while read pat ; \
94        do \
95                if ! patch -d "$(OPENWRT_BUILD_DIR)" -p 0 -N < $${pat} ; \
96                then \
97                        echo Failed applying patch: $${pat} > /dev/stderr ; \
98                        rm -f openwrt/checkout "$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp" ; \
99                        exit 1 ; \
100                fi ; \
101        done ; \
102        touch $@
103
104openwrt/unpatch: openwrt/checkout
105        rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
106        find \
107          "$(OPENWRT_PATCHES_DIR)/all" "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)" \
108          -name .svn -prune -o \! -type d -printf %f/%p\\n | \
109        gawk \
110          'match($$1, "^[[:digit:]]+(-$(OPENWRT_BRANCH))?(-([[:digit:]]*):([[:digit:]]*))?_", revs) \
111          { if(revs[3] <= '$${rev}' && (!length(revs[4]) || revs[4] >= '$${rev}')) print }' | \
112        sort -r | sed -e's/^[^/]\+\///' | \
113        while read pat ; \
114        do \
115                if ! patch -d "$(OPENWRT_BUILD_DIR)" -p 0 -R < $${pat} ; \
116                then \
117                        echo Failed removing patch: $${pat} > /dev/stderr ; \
118                        rm -f openwrt/checkout "$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp" ; \
119                        exit 1 ; \
120                fi ; \
121        done ; \
122        rm openwrt/patch
123        touch $@
124
125
126openwrt/files-copy: openwrt/patch
127        tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \
128          tar -C $(OPENWRT_BUILD_DIR) -xpf - && \
129        touch $@
130
131ifeq ($(OPENWRT_BRANCH),trunk)
132OPENWRT_SUBVERSION:=$(CONFIG_OPENWRT_SVN_REPO_URL)/trunk/
133else
134OPENWRT_SUBVERSION:=$(CONFIG_OPENWRT_SVN_REPO_URL)/branches/$(OPENWRT_BRANCH)/
135endif
136
137$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp:
138openwrt/checkout: $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
139        rm -rf $(OPENWRT_BUILD_DIR) && \
140        svn co -r $(OPENWRT_REVISION) $(OPENWRT_SUBVERSION) $(OPENWRT_BUILD_DIR) && \
141        touch $@ $<
142
143openwrt/update: openwrt/checkout
144        svn up -r $(OPENWRT_REVISION) $(OPENWRT_BUILD_DIR)
145
146openwrt/menuconfig: openwrt/prepare
147        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig
148
149# Tune kernel configuration
150openwrt/kernel_menuconfig: openwrt/prepare
151        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) kernel_menuconfig
152        rm -f openwrt/build
153
154openwrt/clean:
155        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V)
156
157openwrt/dirclean:
158        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V)
159
160openwrt/distclean:
161        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V)
162
163openwrt/debwrt-clean:
164        rm -rf $(OPENWRT_BUILD_DIR)
165        rm -f openwrt/checkout
166        rm -f openwrt/patch
167        rm -f openwrt/files-copy
168
Note: See TracBrowser for help on using the repository browser.