another optimization
[openwrt/openwrt.git] / Makefile
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2006 OpenWrt.org
4 # Copyright (C) 2006 by Felix Fietkau <openwrt@nbd.name>
5 #
6 # This is free software, licensed under the GNU General Public License v2.
7 # See /LICENSE for more information.
8 #
9
10 RELEASE:=Kamikaze
11 #VERSION:=2.0 # uncomment for final release
12
13 #--------------------------------------------------------------
14 # Just run 'make menuconfig', configure stuff, then run 'make'.
15 # You shouldn't need to mess with anything beyond this point...
16 #--------------------------------------------------------------
17
18 all: world
19
20 SHELL:=/usr/bin/env bash
21 export LC_ALL=C
22 export LANG=C
23 export TOPDIR=${shell pwd}
24 ifeq ($(KBUILD_VERBOSE),99)
25 MAKE:=3>/dev/null $(MAKE)
26 endif
27 ifneq ($(shell tty -s <&3 || echo x),x)
28 IS_TTY=1
29 export IS_TTY
30 endif
31
32 include $(TOPDIR)/include/verbose.mk
33
34 OPENWRTVERSION:=$(RELEASE)
35 ifneq ($(VERSION),)
36 OPENWRTVERSION:=$(VERSION) ($(OPENWRTVERSION))
37 else
38 REV:=$(shell LANG=C svn info | awk '/^Revision:/ { print$$2 }' )
39 ifneq ($(REV),)
40 OPENWRTVERSION:=$(OPENWRTVERSION)/r$(REV)
41 endif
42 endif
43 export OPENWRTVERSION
44
45 ifneq ($(shell ./scripts/timestamp.pl -p tmp/.pkginfo package scripts Makefile),tmp/.pkginfo)
46 tmp/.pkginfo: FORCE
47 endif
48
49 ifneq ($(shell ./scripts/timestamp.pl -p tmp/.targetinfo target/linux scripts Makefile),tmp/.targetinfo)
50 tmp/.targetinfo: FORCE
51 endif
52
53 ifeq ($(FORCE),)
54 .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
55 world: tmp/.prereq-packages
56 endif
57
58 tmp/.pkginfo:
59 @mkdir -p tmp
60 @echo Collecting package info...
61 @-for dir in package/*/; do \
62 [ -f "$${dir}/Makefile" ] || continue; \
63 echo Source-Makefile: $${dir}Makefile; \
64 $(NO_TRACE_MAKE) --no-print-dir DUMP=1 -C $$dir 3>/dev/null || echo "ERROR: please fix $${dir}Makefile" >&2; \
65 echo; \
66 done > $@
67
68 tmp/.targetinfo:
69 @mkdir -p tmp
70 @echo Collecting target info...
71 @-for dir in target/linux/*/; do \
72 [ -f "$${dir}/Makefile" ] || continue; \
73 ( cd "$$dir"; $(NO_TRACE_MAKE) --no-print-dir DUMP=1 3>/dev/null || echo "ERROR: please fix $${dir}Makefile" >&2 ); \
74 echo; \
75 done > $@
76
77 tmpinfo-clean: FORCE
78 @-rm -rf tmp/.pkginfo tmp/.targetinfo
79
80 tmp/.config.in: tmp/.pkginfo
81 @./scripts/gen_package_config.pl < $< > $@ || rm -f $@
82
83 tmp/.config-target.in: tmp/.targetinfo
84 @./scripts/gen_target_config.pl < $< > $@ || rm -f $@
85
86 .config: ./scripts/config/conf tmp/.config.in tmp/.config-target.in
87 @[ -f .config ] || $(NO_TRACE_MAKE) menuconfig
88 @$< -D .config Config.in &> /dev/null
89
90 scripts/config/mconf:
91 @$(MAKE) -C scripts/config all
92
93 scripts/config/conf:
94 @$(MAKE) -C scripts/config conf
95
96 config: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
97 $< Config.in
98
99 config-clean: FORCE
100 $(NO_TRACE_MAKE) -C scripts/config clean
101
102 defconfig: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
103 touch .config
104 $< -D .config Config.in
105
106 oldconfig: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
107 $< -o Config.in
108
109 menuconfig: scripts/config/mconf tmp/.config.in tmp/.config-target.in FORCE
110 $< Config.in
111
112 package/%: tmp/.pkginfo tmp/.targetinfo FORCE
113 $(MAKE) -C package $(patsubst package/%,%,$@)
114
115 target/%: tmp/.pkginfo tmp/.targetinfo FORCE
116 $(MAKE) -C target $(patsubst target/%,%,$@)
117
118 tools/%: FORCE
119 $(MAKE) -C tools $(patsubst tools/%,%,$@)
120
121 toolchain/%: tmp/.targetinfo FORCE
122 $(MAKE) -C toolchain $(patsubst toolchain/%,%,$@)
123
124 tmp/.prereq-build: include/prereq-build.mk
125 @mkdir -p tmp
126 @$(NO_TRACE_MAKE) -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
127 echo "Prerequisite check failed. Use FORCE=1 to override."; \
128 false; \
129 }
130 @touch $@
131
132 tmp/.prereq-packages: include/prereq.mk tmp/.pkginfo .config
133 @mkdir -p tmp
134 @$(NO_TRACE_MAKE) -s -C package prereq 2>/dev/null || { \
135 echo "Prerequisite check failed. Use FORCE=1 to override."; \
136 false; \
137 }
138 @touch $@
139
140 prereq: tmp/.prereq-build tmp/.prereq-packages FORCE
141
142 download: .config FORCE
143 $(MAKE) tools/download
144 $(MAKE) toolchain/download
145 $(MAKE) package/download
146 $(MAKE) target/download
147
148 world: .config FORCE
149 $(MAKE) tools/install
150 $(MAKE) toolchain/install
151 $(MAKE) target/compile
152 $(MAKE) package/compile
153 $(MAKE) package/install
154 $(MAKE) target/install
155 $(MAKE) package/index
156
157 clean: FORCE
158 rm -rf build_* bin tmp
159
160 dirclean: clean
161 rm -rf staging_dir_* toolchain_build_* tool_build
162
163 distclean: dirclean config-clean
164 rm -rf dl
165
166 .SILENT: clean dirclean distclean config-clean download world
167 FORCE: ;
168 .PHONY: FORCE
169 %: ;