source: trunk/openwrt/openwrt.mk @ 751

Last change on this file since 751 was 751, checked in by amain, 4 years ago

Merge fix patch /dev/stderr issue from branches/15.05

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