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 | |
---|
18 | OPENWRT_PATCHES_DIR=$(TOPDIR)/openwrt/patches |
---|
19 | |
---|
20 | openwrt/all: openwrt/build |
---|
21 | $(MAKE) -C $(TOPDIR) openwrt/deliver |
---|
22 | touch $@ |
---|
23 | |
---|
24 | openwrt/build: openwrt/prepare |
---|
25 | ifeq ("$(origin V)", "command line") |
---|
26 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V) |
---|
27 | else |
---|
28 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) |
---|
29 | endif |
---|
30 | touch $@ |
---|
31 | |
---|
32 | openwrt/download: |
---|
33 | ifeq ("$(origin V)", "command line") |
---|
34 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download V=$(V) |
---|
35 | else |
---|
36 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download |
---|
37 | endif |
---|
38 | touch $@ |
---|
39 | |
---|
40 | openwrt/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 | |
---|
50 | openwrt/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 | |
---|
73 | openwrt/download-link: openwrt/checkout |
---|
74 | ifneq ($(OPENWRT_DOWNLOAD_DIR),) |
---|
75 | cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi |
---|
76 | endif |
---|
77 | touch $@ |
---|
78 | |
---|
79 | openwrt/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 | |
---|
98 | openwrt/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 | |
---|
119 | openwrt/files-copy: openwrt/patch |
---|
120 | tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \ |
---|
121 | tar -C $(OPENWRT_BUILD_DIR) -xpf - && \ |
---|
122 | touch $@ |
---|
123 | |
---|
124 | ifeq ($(OPENWRT_BRANCH),trunk) |
---|
125 | OPENWRT_SUBVERSION:=svn://svn.openwrt.org/openwrt/trunk/ |
---|
126 | else |
---|
127 | OPENWRT_SUBVERSION:=svn://svn.openwrt.org/openwrt/branches/$(OPENWRT_BRANCH)/ |
---|
128 | endif |
---|
129 | |
---|
130 | $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp: |
---|
131 | openwrt/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 | |
---|
136 | openwrt/update: openwrt/checkout |
---|
137 | svn up -r $(OPENWRT_REVISION) $(OPENWRT_BUILD_DIR) |
---|
138 | |
---|
139 | openwrt/menuconfig: openwrt/prepare |
---|
140 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig |
---|
141 | |
---|
142 | # Tune kernel configuration |
---|
143 | openwrt/kernel_menuconfig: openwrt/prepare |
---|
144 | $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) kernel_menuconfig |
---|
145 | rm -f openwrt/build |
---|
146 | |
---|
147 | openwrt/clean: |
---|
148 | -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V) |
---|
149 | |
---|
150 | openwrt/dirclean: |
---|
151 | -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V) |
---|
152 | |
---|
153 | openwrt/distclean: |
---|
154 | -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V) |
---|
155 | |
---|
156 | openwrt/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 | |
---|