clean up openwrt version handling, use a separate script that is executed at the...
[openwrt.git] / include / toplevel.mk
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007 OpenWrt.org
4 #
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
7 #
8
9 RELEASE:=Kamikaze
10 SHELL:=/usr/bin/env bash
11 PREP_MK= OPENWRT_BUILD= QUIET=0
12
13 include $(TOPDIR)/include/verbose.mk
14
15 REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
16 OPENWRTVERSION:=$(RELEASE)$(if $(REVISION), ($(REVISION)))
17 export RELEASE
18 export REVISION
19 export OPENWRTVERSION
20 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
21
22 ifeq ($(FORCE),)
23   .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
24 endif
25
26 SCAN_COOKIE?=$(shell echo $$$$)
27 export SCAN_COOKIE
28
29 prepare-mk: FORCE ;
30
31 prepare-tmpinfo: FORCE
32         mkdir -p tmp/info
33         +$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPS="$(TOPDIR)/include/package*.mk" SCAN_DEPTH=5 SCAN_EXTRA=""
34         +$(NO_TRACE_MAKE) -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPS="profiles/*.mk $(TOPDIR)/include/kernel*.mk" SCAN_DEPTH=2 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
35         for type in package target; do \
36                 f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
37                 [ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
38         done
39         ./scripts/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
40         touch $(TOPDIR)/tmp/.build
41
42 .config: ./scripts/config/conf prepare-tmpinfo
43         @+if [ \! -f .config ]; then \
44                 [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
45                 $(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
46         fi
47
48 scripts/config/mconf:
49         @+$(MAKE) -C scripts/config all
50
51 $(eval $(call rdep,scripts/config,scripts/config/mconf))
52
53 scripts/config/conf:
54         @+$(MAKE) -C scripts/config conf
55
56 config: scripts/config/conf prepare-tmpinfo FORCE
57         $< Config.in
58
59 config-clean: FORCE
60         $(NO_TRACE_MAKE) -C scripts/config clean
61
62 defconfig: scripts/config/conf prepare-tmpinfo FORCE
63         touch .config
64         $< -D .config Config.in
65
66 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
67         $< -$(if $(CONFDEFAULT),$(CONFDEFAULT),o) Config.in
68
69 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
70         if [ \! -f .config -a -e $(HOME)/.openwrt/defconfig ]; then \
71                 cp $(HOME)/.openwrt/defconfig .config; \
72         fi
73         $< Config.in
74
75 kernel_oldconfig: .config FORCE
76         $(NO_TRACE_MAKE) -C target/linux oldconfig
77
78 kernel_menuconfig: .config FORCE
79         $(NO_TRACE_MAKE) -C target/linux menuconfig
80
81 tmp/.prereq-build: include/prereq-build.mk
82         mkdir -p tmp
83         rm -f tmp/.host.mk
84         @+$(NO_TRACE_MAKE) -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
85                 echo "Prerequisite check failed. Use FORCE=1 to override."; \
86                 false; \
87         }
88         touch $@
89
90 download: .config FORCE
91         $(MAKE) -j1 tools/download
92         $(MAKE) -j1 toolchain/download
93         $(MAKE) -j1 package/download
94         $(MAKE) -j1 target/download
95
96 clean dirclean: .config
97         @$(MAKE) $@ 
98
99 prereq:: .config
100         @+$(SUBMAKE) -s tmp/.prereq-build $(PREP_MK)
101         @$(NO_TRACE_MAKE) -s $@
102
103 %::
104         @+$(PREP_MK) $(NO_TRACE_MAKE) -s prereq
105         @+$(MAKE) -r $@
106
107 help:
108         cat README
109
110 docs docs/compile: FORCE
111         $(MAKE) -C docs compile
112
113 docs/clean: FORCE
114         $(MAKE) -C docs clean
115
116 symlinkclean:
117         -find package -type l | xargs rm -f
118         rm -rf tmp
119
120 distclean:
121         rm -rf tmp build_dir staging_dir dl .config* feeds
122
123 ifeq ($(findstring v,$(DEBUG)),)
124   .SILENT: symlinkclean clean dirclean distclean config-clean download help tmpinfo-clean .config scripts/config/mconf scripts/config/conf menuconfig tmp/.prereq-build tmp/.prereq-package prepare-tmpinfo
125 endif
126 .PHONY: help FORCE
127 .NOTPARALLEL:
128