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

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

More features for patching. This version doesn't have problems with
subdirectories or checking directories with different depths. This also
adds the ability to include the branch name specification in the files.

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