source: trunk/openwrt/openwrt.mk @ 770

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

Simplyfiy OpenWrt patch management using quilt. Allowing debwrt rebuilds without rebuilding OpenWrt toolchain. In other words: make clean; make openwrt/update; make -j4 V=s

File size: 8.4 KB
RevLine 
[1]1# DebWrt - Debian on Embedded devices
2#
3# Copyright (C) 2010 Johan van Zoomeren <amain@debwrt.net>
4#
[517]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#
[1]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
[696]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 
[2]31OPENWRT_PATCHES_DIR=$(TOPDIR)/openwrt/patches
[517]32OPENWRT_PATCH_DIRS:= "$(OPENWRT_PATCHES_DIR)/all" \
33        "$(OPENWRT_PATCHES_DIR)/$(OPENWRT_BRANCH)"
[1]34
[756]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
[517]64
[5]65openwrt/all: openwrt/build
66        $(MAKE) -C $(TOPDIR) openwrt/deliver
[171]67        touch $@
[5]68
[742]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
[2]76openwrt/build: openwrt/prepare
[742]77        @echo "OpenWrt make parallelization: $(subst -j,,$(PJOBS))"
[3]78ifeq ("$(origin V)", "command line")
[742]79        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS) V=$(V)
[3]80else
[742]81        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) $(CONFIG_OPENWRT_MAKE_OPTIONS)
[3]82endif
[171]83        touch $@
[3]84
[176]85openwrt/download:
86ifeq ("$(origin V)", "command line")
[742]87        @echo "OpenWrt make parallelization: $(subst -j,,$(PJOBS))"
88        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) download V=$(V)
[176]89else
[742]90        $(SCRIPT_CLEAN_EXEC) $(MAKE) $(PJOBS) -C $(OPENWRT_BUILD_DIR) download
[176]91endif
92        touch $@
93
[185]94openwrt/prepare: \
95  openwrt/checkout \
[283]96  openwrt/patch \
[327]97  openwrt/files-copy \
[185]98  openwrt/merge-config \
[517]99  openwrt/download-link
[58]100        touch $@
101
[270]102openwrt/merge-config: .config $(OPENWRT_BUILD_DIR)/.config openwrt/checkout openwrt/patch
[171]103        mkdir -p $(TMP_DIR)
[270]104        # Copy default OpenWrt settings
[3]105        cp $(CONFIG_DIR)/openwrt.defconfig $(TMP_DIR)/.config_openwrt
[328]106        # Merge default OpenWrt settings with DebWrt menu config settings
[517]107        grep -v -e CONFIG_TARGET_BOARD .config >> $(TMP_DIR)/.config_openwrt
[270]108        # Merge default and menu settings with possibly altered settings in make menuconfig in OpenWrt
[328]109        # note: settings manually made in OpenWrt menu config will be included!
[3]110        touch $(OPENWRT_BUILD_DIR)/.config
111        cp $(OPENWRT_BUILD_DIR)/.config $(OPENWRT_BUILD_DIR)/.config.org
[270]112        $(SCRIPT_KCONFIG) + $(OPENWRT_BUILD_DIR)/.config.org $(TMP_DIR)/.config_openwrt > $(OPENWRT_BUILD_DIR)/.config
[724]113        cat $(OPENWRT_BUILD_DIR)/.config | grep -v "^#" | grep -v "^$$" | sort > $(TMP_DIR)/.config.openwrt.merged
[328]114        # Filter out config options unknown to OpenWrt (e.g. pure kernel known options) / clean up OpenWrt config
[3]115        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) defconfig
[724]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." )
[328]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.
[3]121        cp .config $(OPENWRT_BUILD_DIR)/.config.debwrt
[171]122        touch $@
[3]123
[193]124$(OPENWRT_BUILD_DIR)/.config: openwrt/checkout
[172]125        [ ! -f $@ ] && touch $(OPENWRT_BUILD_DIR)/.config
126
[3]127openwrt/download-link: openwrt/checkout
[165]128ifneq ($(OPENWRT_DOWNLOAD_DIR),)
[2]129        cd $(OPENWRT_BUILD_DIR) && if [ -d $(OPENWRT_DOWNLOAD_DIR) -a ! -e dl ]; then ln -snf $(OPENWRT_DOWNLOAD_DIR) dl; fi
[165]130endif
[171]131        touch $@
[2]132
[756]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 $@
[517]138
[756]139openwrt/patches/uninstall: openwrt/unpatch
140        rm -rf $(OPENWRT_BUILD_DIR)/patches
141        rm -f openwrt/patches/install
[517]142
[756]143openwrt/patch: openwrt/checkout openwrt/patches/install
144        cd $(OPENWRT_BUILD_DIR); quilt push -a
[2]145        touch $@
146
[756]147openwrt/unpatch: $(OPENWRT_BUILD_DIR)/patches
148        cd $(OPENWRT_BUILD_DIR); quilt pop -a
[517]149        rm -f openwrt/patch
[336]150
[327]151openwrt/files-copy: openwrt/patch
[517]152        tar -C $(FILES_DIR_OPENWRT) --exclude-vcs -cpf - . | \
153          tar -C $(OPENWRT_BUILD_DIR) -xpf - && \
[327]154        touch $@
155
[517]156ifeq ($(OPENWRT_BRANCH),trunk)
[732]157OPENWRT_GIT:=$(call qstrip,$(CONFIG_OPENWRT_GIT_REPO_URL))/openwrt.git
[517]158else
[732]159OPENWRT_GIT:=$(call qstrip,$(CONFIG_OPENWRT_GIT_REPO_URL))/$(OPENWRT_BRANCH)/openwrt.git
[517]160endif
161
[194]162$(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp:
163openwrt/checkout: $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
[517]164        if [ ! -f $(TOPDIR)/.config ]; then echo "Please type menuconfig first"; exit 1; fi
[2]165        mkdir -p $(OPENWRT_BUILD_DIR)
[730]166        git clone $(OPENWRT_GIT) $(OPENWRT_BUILD_DIR)
167ifneq ($(OPENWRT_REVISION),HEAD)
168        cd $(OPENWRT_BUILD_DIR); git checkout $(OPENWRT_REVISION)
169endif
[195]170        touch $(OPENWRT_BUILD_DIR)/.debwrt.checkout.stamp
[2]171        touch $@
172
[756]173# checkout or update openwrt
174openwrt/update: openwrt/checkout
175        -$(MAKE) openwrt/patches/uninstall
[730]176        cd $(OPENWRT_BUILD_DIR); git pull origin master
177        $(MAKE) openwrt/patch
[75]178
[2]179openwrt/menuconfig: openwrt/prepare
180        $(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) menuconfig
181
[192]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
[724]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
[727]188openwrt/clean: openwrt/deliver/clean
[333]189        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) clean V=$(V)
[727]190        rm -f openwrt/all
191        rm -f openwrt/build
192        rm -f openwrt/deliver
193        rm -f openwrt/merge-config
[286]194
[724]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.
[727]196openwrt/dirclean: openwrt/deliver/clean
[333]197        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) dirclean V=$(V)
[727]198        rm -f openwrt/all
199        rm -f openwrt/build
200        rm -f openwrt/deliver
201        rm -f openwrt/merge-config
[286]202
[724]203# nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources.
[727]204openwrt/distclean: openwrt/deliver/clean
[333]205        -$(SCRIPT_CLEAN_EXEC) $(MAKE) -C $(OPENWRT_BUILD_DIR) distclean V=$(V)
[727]206        rm -f openwrt/all
207        rm -f openwrt/build
208        rm -f openwrt/deliver
209        rm -f openwrt/merge-config
[286]210
[727]211openwrt/full-clean: openwrt/deliver/clean
[2]212        rm -rf $(OPENWRT_BUILD_DIR)
[727]213        rm -f openwrt/all
214        rm -f openwrt/build
215        rm -f openwrt/deliver
[2]216        rm -f openwrt/checkout
217        rm -f openwrt/patch
[517]218        rm -f openwrt/files-copy
[727]219        rm -f openwrt/download-link
220        rm -f openwrt/prepare
221        rm -f openwrt/merge-config
[517]222
[756]223.PHONY: openwrt/patches/uninstall \
224        openwrt/clean
[517]225
Note: See TracBrowser for help on using the repository browser.