source: trunk/openwrt/openwrt.mk @ 517

Last change on this file since 517 was 517, checked in by amain, 6 years ago

Merge contrib branch 340:516. Main features added:

  • updated plugin architecture
  • improved patch system
  • bitten continous integration support
  • sever build fixed over time to remain in sync with OpenWrt
File size: 6.6 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
24OPENWRT_PATCH_DIRS:= "$(OPENWRT_PATCHES_DIR)/all" \
25        "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)"
26
27get_patches = \
28        if [ ! -d "$(OPENWRT_BUILD_DIR)" ]; then exit 1; fi ; \
29        rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
30        find \
31          $(OPENWRT_PATCH_DIRS) \
32          -name .svn -prune -o \! -type d -printf %f/%p\\n | \
33        gawk -F / '\
34          BEGIN { OFS=FS } \
35          match($$1, "^([[:digit:]]+)((-$(OPENWRT_BRANCH))|(-all))?(-([[:digit:]]*):([[:digit:]]*))?(_[^/]*)", revs) \
36            { if(revs[6] <= '$${rev}' && (!length(revs[7]) || revs[7] >= '$${rev}')) \
37              { $$1=revs[1] revs[8]; print } \
38            }' | \
39        sort $(1) | sed -e's/^[^/]\+\///'
40
41do_patches = \
42        if [ ! -d "$(OPENWRT_BUILD_DIR)" ]; then exit 1; fi ; \
43        $(call get_patches,$(1)) | while read patch ; \
44        do \
45                patchi=$$(echo $${patch} | sed -e's!$(TOPDIR)/!!') ; \
46                if ! patch -b -d "$(OPENWRT_BUILD_DIR)" -p1 $(2) < "$${patch}" ; \
47                then \
48                        echo ">> fail: $${patchi}" > /dev/stderr ; \
49                        $(if $(FORCE_PATCH),retval=1,exit 1) ; \
50                else \
51                        echo ">> success: $${patchi}" ; \
52                fi ; \
53        done
54
55openwrt/all: openwrt/build
56        $(MAKE) -C $(TOPDIR) openwrt/deliver
57        touch $@
58
59openwrt/build: openwrt/prepare
60ifeq ("$(origin V)", "command line")
61        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V)
62else
63        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS)
64endif
65        touch $@
66
67openwrt/download:
68ifeq ("$(origin V)", "command line")
69        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download V=$(V)
70else
71        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) download
72endif
73        touch $@
74
75openwrt/prepare: \
76  openwrt/checkout \
77  openwrt/patch \
78  openwrt/files-copy \
79  openwrt/merge-config \
80  openwrt/download-link
81        touch $@
82
83openwrt/merge-config: .config $(OPENWRT_BUILD_DIR)/.config openwrt/checkout openwrt/patch
84        mkdir -p $(TMP_DIR)
85        # Copy default OpenWrt settings
86        cp $(CONFIG_DIR)/openwrt.defconfig $(TMP_DIR)/.config_openwrt
87        # Merge default OpenWrt settings with DebWrt menu config settings
88        grep -v -e CONFIG_TARGET_BOARD .config >> $(TMP_DIR)/.config_openwrt
89        # Merge default and menu settings with possibly altered settings in make menuconfig in OpenWrt
90        # note: settings manually made in OpenWrt menu config will be included!
91        touch $(OPENWRT_BUILD_DIR)/.config
92        cp $(OPENWRT_BUILD_DIR)/.config $(OPENWRT_BUILD_DIR)/.config.org
93        $(SCRIPT_KCONFIG) + $(OPENWRT_BUILD_DIR)/.config.org $(TMP_DIR)/.config_openwrt > $(OPENWRT_BUILD_DIR)/.config
94        # Filter out config options unknown to OpenWrt (e.g. pure kernel known options) / clean up OpenWrt config
95        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) defconfig
96        # Save .config to OpenWrt build-dir. During the OpenWrt build the .config kernel options are
97        # merged with the OpenWrt's default kernel options for the target. In this phase any DebWrt/OpenWrt
98        # specific options in the .config file are filtered out. See include/kernel-defaults.mk from OpenWrt.
99        cp .config $(OPENWRT_BUILD_DIR)/.config.debwrt
100        touch $@
101
102$(OPENWRT_BUILD_DIR)/.config: openwrt/checkout
103        [ ! -f $@ ] && touch $(OPENWRT_BUILD_DIR)/.config
104
105openwrt/download-link: openwrt/checkout
106ifneq ($(OPENWRT_DOWNLOAD_DIR),)
107        cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi
108endif
109        touch $@
110
111openwrt/patch/show: openwrt/checkout
112        @$(call get_patches) | while read patch ;\
113        do \
114           echo $${patch}; \
115        done
116
117openwrt/patch/force:
118        rm -f $(TOPDIR)/openwrt/patch ; \
119        $(MAKE) -C $(TOPDIR) openwrt/patch FORCE_PATCH=1 ; \
120
121openwrt/patch: openwrt/checkout
122        @$(call do_patches,,-N)
123        rm -f openwrt/unpatch
124        touch $@
125
126openwrt/unpatch/show: openwrt/checkout
127        @$(call get_patches,-r) | while read patch ;\
128        do \
129           echo $${patch}; \
130        done
131openwrt/unpatch/force:
132        rm -f $(TOPDIR)/openwrt/unpatch ; \
133        $(MAKE) -C $(TOPDIR) openwrt/unpatch FORCE_PATCH=1 ; \
134
135openwrt/unpatch:
136        @if [ ! -f $(TOPDIR)/openwrt/patch ]; then \
137           echo "E: can't unpatch if patches have not previously been applied"; \
138           exit 1; \
139        fi
140        @$(call do_patches,-r,-R)
141        rm -f openwrt/patch
142        touch $@
143
144openwrt/files-copy: openwrt/patch
145        tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \
146          tar -C $(OPENWRT_BUILD_DIR) -xpf - && \
147        touch $@
148
149ifeq ($(OPENWRT_BRANCH),trunk)
150OPENWRT_SUBVERSION:=$(call qstrip,$(CONFIG_OPENWRT_SVN_REPO_URL))/trunk/
151else ifeq ($(OPENWRT_TAG),)
152OPENWRT_SUBVERSION:=$(call qstrip,$(CONFIG_OPENWRT_SVN_REPO_URL))/branches/$(OPENWRT_BRANCH)/
153else
154OPENWRT_SUBVERSION:=$(call qstrip,$(CONFIG_OPENWRT_SVN_REPO_URL))/tags/$(OPENWRT_TAG)
155endif
156
157$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp:
158openwrt/checkout: $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
159        if [ ! -f $(TOPDIR)/.config ]; then echo "Please type menuconfig first"; exit 1; fi
160        mkdir -p $(OPENWRT_BUILD_DIR)
161        svn co -r $(OPENWRT_REVISION) $(OPENWRT_SUBVERSION) $(OPENWRT_BUILD_DIR)
162        touch $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
163        touch $@
164
165openwrt/update: openwrt/checkout
166        svn up -r $(OPENWRT_REVISION) $(OPENWRT_BUILD_DIR)
167
168openwrt/menuconfig: openwrt/prepare
169        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig
170
171# Tune kernel configuration
172openwrt/kernel_menuconfig: openwrt/prepare
173        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) kernel_menuconfig
174        rm -f openwrt/build
175
176openwrt/wrtclean:
177        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V)
178
179openwrt/dirclean:
180        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V)
181
182openwrt/distclean:
183        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V)
184
185openwrt/clean:
186        rm -rf $(OPENWRT_BUILD_DIR)
187        rm -f openwrt/checkout
188        rm -f openwrt/patch
189        rm -f openwrt/files-copy
190
191.PHONY: openwrt/patch/force \
192        openwrt/unpatch/force \
193        openwrt/clean \
194
Note: See TracBrowser for help on using the repository browser.