source: trunk/openwrt/openwrt.mk @ 884

Last change on this file since 884 was 884, checked in by amain, 3 years ago

Add LEDE support. LEDE is (for now) the new default.

File size: 8.3 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
23ifneq ($(findstring openwrt,$(MAKECMDGOALS)),)
24$(info Architecture: $(TARGET_ARCH))
25$(info Target      : $(TARGET))
26$(info Sub rarget  : $(SUB_TARGET))
27$(info Profile     : $(PROFILE))
28$(info )
29endif
30 
31OPENWRT_PATCHES_DIR=$(TOPDIR)/openwrt/patches/$(PROJECT)
32OPENWRT_PATCH_DIRS:= "$(OPENWRT_PATCHES_DIR)/all" \
33        "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)"
34
35# keep for future reference:
36#
37#get_patches = \
38#       if [ ! -d "$(OPENWRT_BUILD_DIR)" ]; then exit 1; fi ; \
39#       rev=$(call get_svn_revision,$(OPENWRT_BUILD_DIR)) ; \
40#       find \
41#         $(OPENWRT_PATCH_DIRS) \
42#         -name .svn -prune -o \! -type d -printf %f/%p\\n 2>/dev/null | \
43#       gawk -F / '\
44#         BEGIN { OFS=FS } \
45#         match($$1, "^([[:digit:]]+)((-$(OPENWRT_BRANCH))|(-all))?(-([[:digit:]]*):([[:digit:]]*))?(_[^/]*)", revs) \
46#           { if(revs[6] <= '$${rev}' && (!length(revs[7]) || revs[7] >= '$${rev}')) \
47#             { $$1=revs[1] revs[8]; print } \
48#           }' | \
49#       sort $(1) | sed -e's/^[^/]\+\///'
50#
51#do_patches = \
52#       if [ ! -d "$(OPENWRT_BUILD_DIR)" ]; then exit 1; fi ; \
53#       $(call get_patches,$(1)) | while read patch ; \
54#       do \
55#               patchi=$$(echo $${patch} | sed -e's!$(TOPDIR)/!!') ; \
56#               if ! patch -b -d "$(OPENWRT_BUILD_DIR)" -p1 $(2) < "$${patch}" ; \
57#               then \
58#                       echo ">> fail: $${patchi}" 1>&2 ; \
59#                       $(if $(FORCE_PATCH),retval=1,exit 1) ; \
60#               else \
61#                       echo ">> success: $${patchi}" ; \
62#               fi ; \
63#       done
64
65openwrt/all: openwrt/build
66        $(MAKE) -C $(TOPDIR) openwrt/deliver
67        touch $@
68
69_PJOBS := $(shell grep -a \\-j /proc/$$PPID/cmdline | tr -d '\0' | sed 's/.*-j\([0-9]*\).*/\1/' )
70ifneq ($(_PJOBS),)
71PJOBS := -j$(_PJOBS)
72else
73PJOBS := -j1
74endif
75
76openwrt/build: openwrt/prepare
77        @echo "OpenWrt make parallelization: $(subst -j,,$(PJOBS))"
78ifeq ("$(origin V)", "command line")
79        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V)
80else
81        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS)
82endif
83        touch $@
84
85openwrt/download:
86ifeq ("$(origin V)", "command line")
87        @echo "OpenWrt make parallelization: $(subst -j,,$(PJOBS))"
88        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) download V=$(V)
89else
90        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) download
91endif
92        touch $@
93
94openwrt/prepare: \
95  openwrt/checkout \
96  openwrt/patch \
97  openwrt/files-copy \
98  openwrt/merge-config \
99  openwrt/download-link
100        touch $@
101
102openwrt/merge-config: .config $(OPENWRT_BUILD_DIR)/.config openwrt/checkout openwrt/patch
103        mkdir -p $(TMP_DIR)
104        # Copy default OpenWrt settings
105        cp $(CONFIG_DIR)/openwrt.defconfig $(TMP_DIR)/.config_openwrt
106        # Merge default OpenWrt settings with DebWrt menu config settings
107        grep -v -e CONFIG_TARGET_BOARD .config >> $(TMP_DIR)/.config_openwrt
108        # Merge default and menu settings with possibly altered settings in make menuconfig in OpenWrt
109        # note: settings manually made in OpenWrt menu config will be included!
110        touch $(OPENWRT_BUILD_DIR)/.config
111        cp $(OPENWRT_BUILD_DIR)/.config $(OPENWRT_BUILD_DIR)/.config.org
112        $(SCRIPT_KCONFIG) + $(OPENWRT_BUILD_DIR)/.config.org $(TMP_DIR)/.config_openwrt > $(OPENWRT_BUILD_DIR)/.config
113        cat $(OPENWRT_BUILD_DIR)/.config | grep -v "^#" | grep -v "^$$" | sort > $(TMP_DIR)/.config.openwrt.merged
114        # Filter out config options unknown to OpenWrt (e.g. pure kernel known options) / clean up OpenWrt config
115        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) defconfig
116        cat $(OPENWRT_BUILD_DIR)/.config | grep -v "^#" | grep -v "^$$" | sort > $(TMP_DIR)/.config.openwrt.filtered
117        diff -u $(TMP_DIR)/.config.openwrt.merged $(TMP_DIR)/.config.openwrt.filtered | grep "^-CONFIG_PACKAGE_" && ( echo "WARNING: DebWrt selected packages removed by OpenWrt defconfig." )
118        # Save .config to OpenWrt build-dir. During the OpenWrt build the .config kernel options are
119        # merged with the OpenWrt's default kernel options for the target. In this phase any DebWrt/OpenWrt
120        # specific options in the .config file are filtered out. See include/kernel-defaults.mk from OpenWrt.
121        cp .config $(OPENWRT_BUILD_DIR)/.config.debwrt
122        touch $@
123
124$(OPENWRT_BUILD_DIR)/.config: openwrt/checkout
125        [ ! -f $@ ] && touch $(OPENWRT_BUILD_DIR)/.config
126
127openwrt/download-link: openwrt/checkout
128ifneq ($(OPENWRT_DOWNLOAD_DIR),)
129        cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi
130endif
131        touch $@
132
133openwrt/patches/install: openwrt/checkout
134        mkdir $(OPENWRT_BUILD_DIR)/patches
135        cp -ra $(OPENWRT_PATCHES_DIR)/all/* $(OPENWRT_BUILD_DIR)/patches
136        cd $(OPENWRT_BUILD_DIR)/patches; ls -1 | sort | grep -v "^series" >series
137        touch $@
138
139openwrt/patches/uninstall: openwrt/unpatch
140        rm -rf $(OPENWRT_BUILD_DIR)/patches
141        rm -f openwrt/patches/install
142
143openwrt/patch: openwrt/checkout openwrt/patches/install
144        cd $(OPENWRT_BUILD_DIR); quilt push -a
145        touch $@
146
147openwrt/unpatch: $(OPENWRT_BUILD_DIR)/patches
148        cd $(OPENWRT_BUILD_DIR); quilt pop -a
149        rm -f openwrt/patch
150
151openwrt/files-copy: openwrt/patch
152        tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \
153          tar -C $(OPENWRT_BUILD_DIR) -xpf - && \
154        touch $@
155
156ifeq ($(OPENWRT_BRANCH),trunk)
157GIT_URL:=$(GIT_REPO_URL)/$(GIT_PROJECT)
158else
159GIT_URL:=$(GIT_REPO_URL)/$(OPENWRT_BRANCH)/$(GIT_PROJECT)
160endif
161
162$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp:
163openwrt/checkout: $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
164        @if [ ! -f $(TOPDIR)/.config ]; then echo "Please type menuconfig first"; exit 1; fi
165        mkdir -p $(OPENWRT_BUILD_DIR)
166        git clone $(GIT_URL) $(OPENWRT_BUILD_DIR)
167ifneq ($(OPENWRT_REVISION),HEAD)
168        cd $(OPENWRT_BUILD_DIR); git checkout $(OPENWRT_REVISION)
169endif
170        touch $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
171        touch $@
172
173# checkout or update openwrt
174openwrt/update: openwrt/checkout
175        -$(MAKE) openwrt/patches/uninstall
176        cd $(OPENWRT_BUILD_DIR); git pull origin master
177        $(MAKE) openwrt/patch
178
179openwrt/menuconfig: openwrt/prepare
180        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig
181
182# Tune kernel configuration
183openwrt/kernel_menuconfig: openwrt/prepare
184        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) kernel_menuconfig
185        rm -f openwrt/build
186
187# deletes contents of the directories /bin and /build_dir. make clean does not remove the toolchain, it also avoids cleaning architectures/targets other than the one you have selected in your .config
188openwrt/clean: openwrt/deliver/clean
189        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V)
190        rm -f openwrt/all
191        rm -f openwrt/build
192        rm -f openwrt/deliver
193        rm -f openwrt/merge-config
194
195# deletes contents of the directories /bin and /build_dir and additionally /staging_dir and /toolchain (=the cross-compile tools) and /logs. 'Dirclean' is your basic "Full clean" operation.
196openwrt/dirclean: openwrt/deliver/clean
197        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V)
198        rm -f openwrt/all
199        rm -f openwrt/build
200        rm -f openwrt/deliver
201        rm -f openwrt/merge-config
202
203# nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources.
204openwrt/distclean: openwrt/deliver/clean
205        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V)
206        rm -f openwrt/all
207        rm -f openwrt/build
208        rm -f openwrt/deliver
209        rm -f openwrt/merge-config
210
211openwrt/full-clean: openwrt/deliver/clean
212        rm -rf $(OPENWRT_BUILD_DIR)
213        rm -f openwrt/all
214        rm -f openwrt/build
215        rm -f openwrt/deliver
216        rm -f openwrt/checkout
217        rm -f openwrt/patch
218        rm -f openwrt/files-copy
219        rm -f openwrt/download-link
220        rm -f openwrt/prepare
221        rm -f openwrt/merge-config
222
223.PHONY: openwrt/patches/uninstall \
224        openwrt/clean
225
Note: See TracBrowser for help on using the repository browser.