merge the scripts dealing with package/target metadata to remove some redundant code
[openwrt/staging/mkresin.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=${CURDIR}
24 ifeq ($(KBUILD_VERBOSE),99)
25 MAKE:=3>/dev/null $(MAKE)
26 endif
27 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
28
29 include $(TOPDIR)/include/verbose.mk
30
31 OPENWRTVERSION:=$(RELEASE)
32 ifneq ($(VERSION),)
33 OPENWRTVERSION:=$(VERSION) ($(OPENWRTVERSION))
34 else
35 REV:=$(shell LANG=C svn info | awk '/^Revision:/ { print$$2 }' )
36 ifneq ($(REV),)
37 OPENWRTVERSION:=$(OPENWRTVERSION)/r$(REV)
38 endif
39 endif
40 export OPENWRTVERSION
41
42 ifneq ($(shell ./scripts/timestamp.pl -p tmp/.pkginfo package scripts include),tmp/.pkginfo)
43 tmp/.pkginfo: FORCE
44 endif
45
46 ifneq ($(shell ./scripts/timestamp.pl -p tmp/.targetinfo target/linux scripts include),tmp/.targetinfo)
47 tmp/.targetinfo: FORCE
48 endif
49
50 ifeq ($(FORCE),)
51 .config scripts/config/conf scripts/config/mconf: tmp/.prereq-build
52 world: tmp/.prereq-packages tmp/.prereq-target
53 endif
54
55 ifeq ($(IS_TTY),1)
56 define progress
57 printf "\033[M\r$(1)" >&2;
58 endef
59 endif
60
61 define dumpinfo
62 @mkdir -p tmp
63 @echo -n Collecting $(2) info...
64 @-for dir in $(1)/*/; do \
65 [ -f "$${dir}/Makefile" ] || continue; \
66 $(call progress,Collecting $(2) info: $${dir%%/}) \
67 echo Source-Makefile: $${dir}Makefile; \
68 $(NO_TRACE_MAKE) --no-print-dir DUMP=1 -C $$dir 3>/dev/null || echo "ERROR: please fix $${dir}Makefile" >&2; \
69 echo; \
70 done > $@
71 @($(call progress,Collecting $(2) info: done))
72 @echo
73 endef
74
75 tmp/.pkginfo:
76 $(call dumpinfo,package,package)
77
78 tmp/.targetinfo:
79 $(call dumpinfo,target/linux,target)
80
81 tmpinfo-clean: FORCE
82 @-rm -rf tmp/.pkginfo tmp/.targetinfo
83
84 tmp/.config.in: tmp/.pkginfo
85 @./scripts/metadata.pl package_config < $< > $@ || rm -f $@
86
87 tmp/.config-target.in: tmp/.targetinfo
88 @./scripts/metadata.pl target_config < $< > $@ || rm -f $@
89
90 .config: ./scripts/config/conf tmp/.config.in tmp/.config-target.in
91 @[ -f .config ] || $(NO_TRACE_MAKE) menuconfig
92 @$< -D .config Config.in &> /dev/null
93
94 scripts/config/mconf:
95 @$(MAKE) -C scripts/config all
96
97 scripts/config/conf:
98 @$(MAKE) -C scripts/config conf
99
100 config: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
101 $< Config.in
102
103 config-clean: FORCE
104 $(NO_TRACE_MAKE) -C scripts/config clean
105
106 defconfig: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
107 touch .config
108 $< -D .config Config.in
109
110 oldconfig: scripts/config/conf tmp/.config.in tmp/.config-target.in FORCE
111 $< -o Config.in
112
113 menuconfig: scripts/config/mconf tmp/.config.in tmp/.config-target.in FORCE
114 $< Config.in
115
116 package/%: tmp/.pkginfo tmp/.targetinfo FORCE
117 $(MAKE) -C package $(patsubst package/%,%,$@)
118
119 target/%: tmp/.pkginfo tmp/.targetinfo FORCE
120 $(MAKE) -C target $(patsubst target/%,%,$@)
121
122 tools/%: FORCE
123 $(MAKE) -C tools $(patsubst tools/%,%,$@)
124
125 toolchain/%: tmp/.targetinfo FORCE
126 $(MAKE) -C toolchain $(patsubst toolchain/%,%,$@)
127
128 tmp/.prereq-build: include/prereq-build.mk
129 @mkdir -p tmp
130 @rm -f tmp/.host.mk
131 @$(NO_TRACE_MAKE) -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
132 echo "Prerequisite check failed. Use FORCE=1 to override."; \
133 false; \
134 }
135 @touch $@
136
137 tmp/.prereq-packages: include/prereq.mk tmp/.pkginfo .config
138 @mkdir -p tmp
139 @rm -f tmp/.host.mk
140 @$(NO_TRACE_MAKE) -s -C package prereq 2>/dev/null || { \
141 echo "Prerequisite check failed. Use FORCE=1 to override."; \
142 false; \
143 }
144 @touch $@
145
146 tmp/.prereq-target: include/prereq.mk tmp/.targetinfo .config
147 @mkdir -p tmp
148 @rm -f tmp/.host.mk
149 @$(NO_TRACE_MAKE) -s -C target prereq 2>/dev/null || { \
150 echo "Prerequisite check failed. Use FORCE=1 to override."; \
151 false; \
152 }
153 @touch $@
154
155 prereq: tmp/.prereq-build tmp/.prereq-packages tmp/.prereq-target FORCE
156
157 download: .config FORCE
158 $(MAKE) tools/download
159 $(MAKE) toolchain/download
160 $(MAKE) package/download
161 $(MAKE) target/download
162
163 world: .config FORCE
164 $(MAKE) tools/install
165 $(MAKE) toolchain/install
166 $(MAKE) target/compile
167 $(MAKE) package/compile
168 $(MAKE) package/install
169 $(MAKE) target/install
170 $(MAKE) package/index
171
172 clean: FORCE
173 rm -rf build_* bin tmp
174
175 dirclean: clean
176 rm -rf staging_dir_* toolchain_build_* tool_build
177
178 distclean: dirclean config-clean
179 rm -rf dl
180
181 help:
182 cat README
183
184 doc:
185 $(MAKE) -C docs/ openwrt.pdf
186
187 docclean:
188 $(MAKE) -C docs/ clean
189
190 symlinks:
191 scripts/feeds.sh $(CONFIG_SOURCE_FEEDS)
192
193 .SILENT: clean dirclean distclean config-clean download world
194 FORCE: ;
195 .PHONY: FORCE help
196 %: ;