build: process variable exports from toplevel.mk only once
[openwrt/openwrt.git] / include / toplevel.mk
1 # Makefile for OpenWrt
2 #
3 # Copyright (C) 2007-2012 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 PREP_MK= OPENWRT_BUILD= QUIET=0
10
11 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
12
13 include $(TOPDIR)/include/verbose.mk
14 ifeq ($(OPENWRT_VARS),)
15 include $(TOPDIR)/include/toplevel-vars.mk
16 endif
17
18 ifeq ($(FORCE),)
19 .config scripts/config/conf scripts/config/mconf: staging_dir/host/.prereq-build
20 endif
21
22 SUBMAKE:=umask 022; $(SUBMAKE)
23
24 ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
25
26 prepare-mk: staging_dir/host/.prereq-build FORCE ;
27
28 ifdef SDK
29 IGNORE_PACKAGES = linux
30 endif
31
32 _ignore = $(foreach p,$(IGNORE_PACKAGES),--ignore $(p))
33
34 prepare-tmpinfo: FORCE
35 @+$(MAKE) -r -s staging_dir/host/.prereq-build $(PREP_MK)
36 mkdir -p tmp/info
37 $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPTH=5 SCAN_EXTRA=""
38 $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPTH=2 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
39 for type in package target; do \
40 f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
41 [ "$$t" -nt "$$f" ] || ./scripts/$${type}-metadata.pl $(_ignore) config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
42 done
43 [ tmp/.config-feeds.in -nt tmp/.packageauxvars ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
44 ./scripts/package-metadata.pl mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
45 ./scripts/package-metadata.pl pkgaux tmp/.packageinfo > tmp/.packageauxvars || { rm -f tmp/.packageauxvars; false; }
46 ./scripts/package-metadata.pl usergroup tmp/.packageinfo > tmp/.packageusergroup || { rm -f tmp/.packageusergroup; false; }
47 touch $(TOPDIR)/tmp/.build
48
49 .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
50 @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
51 [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
52 $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
53 fi
54
55 ifeq ($(RECURSIVE_DEP_IS_ERROR),1)
56 KCONF_FLAGS=--fatalrecursive
57 endif
58 ifneq ($(DISTRO_PKG_CONFIG),)
59 scripts/config/%onf: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
60 endif
61 scripts/config/%onf: CFLAGS+= -O2
62 scripts/config/%onf:
63 @$(_SINGLE)$(SUBMAKE) $(if $(findstring s,$(OPENWRT_VERBOSE)),,-s) \
64 -C scripts/config $(notdir $@) CC="$(HOSTCC_WRAPPER)"
65
66 $(eval $(call rdep,scripts/config,scripts/config/mconf))
67
68 config: scripts/config/conf prepare-tmpinfo FORCE
69 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
70 $< $(KCONF_FLAGS) Config.in
71
72 config-clean: FORCE
73 $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
74
75 defconfig: scripts/config/conf prepare-tmpinfo FORCE
76 touch .config
77 @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
78 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
79 $< $(KCONF_FLAGS) --defconfig=.config Config.in
80
81 confdefault-y=allyes
82 confdefault-m=allmod
83 confdefault-n=allno
84 confdefault:=$(confdefault-$(CONFDEFAULT))
85
86 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
87 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
88 $< $(KCONF_FLAGS) --$(if $(confdefault),$(confdefault),old)config Config.in
89
90 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
91 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
92 cp $(HOME)/.openwrt/defconfig .config; \
93 fi
94 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
95 $< Config.in
96
97 nconfig: scripts/config/nconf prepare-tmpinfo FORCE
98 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
99 cp $(HOME)/.openwrt/defconfig .config; \
100 fi
101 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
102 $< Config.in
103
104 xconfig: scripts/config/qconf prepare-tmpinfo FORCE
105 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
106 cp $(HOME)/.openwrt/defconfig .config; \
107 fi
108 $< Config.in
109
110 prepare_kernel_conf: .config toolchain/install FORCE
111
112 ifeq ($(wildcard staging_dir/host/bin/quilt),)
113 prepare_kernel_conf:
114 @+$(SUBMAKE) -r tools/quilt/compile
115 else
116 prepare_kernel_conf: ;
117 endif
118
119 kernel_oldconfig: prepare_kernel_conf
120 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
121
122 ifneq ($(DISTRO_PKG_CONFIG),)
123 kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
124 kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
125 kernel_xconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
126 endif
127 kernel_menuconfig: prepare_kernel_conf
128 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
129
130 kernel_nconfig: prepare_kernel_conf
131 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
132
133 kernel_xconfig: prepare_kernel_conf
134 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux xconfig
135
136 staging_dir/host/.prereq-build: include/prereq-build.mk
137 mkdir -p tmp
138 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
139 echo "Prerequisite check failed. Use FORCE=1 to override."; \
140 false; \
141 }
142 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
143 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
144 echo "Preparation failed."; \
145 false; \
146 }
147 endif
148 touch $@
149
150 printdb: FORCE
151 @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
152
153 ifndef SDK
154 DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
155 else
156 DOWNLOAD_DIRS = package/download
157 endif
158
159 download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
160 @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
161
162 clean dirclean: .config
163 @+$(SUBMAKE) -r $@
164
165 prereq:: prepare-tmpinfo .config
166 @+$(NO_TRACE_MAKE) -r -s $@
167
168 check: .config FORCE
169 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
170
171 val.%: FORCE
172 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
173
174 WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
175
176 ifeq ($(SDK),1)
177
178 %::
179 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
180 @./scripts/config/conf $(KCONF_FLAGS) --defconfig=.config Config.in
181 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
182
183 else
184
185 %::
186 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
187 @( \
188 cp .config tmp/.config; \
189 ./scripts/config/conf $(KCONF_FLAGS) --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
190 if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
191 printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
192 fi \
193 )
194 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
195 printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
196 false; \
197 } )
198
199 endif
200
201 # update all feeds, re-create index files, install symlinks
202 package/symlinks:
203 ./scripts/feeds update -a
204 ./scripts/feeds install -a
205
206 # re-create index files, install symlinks
207 package/symlinks-install:
208 ./scripts/feeds update -i
209 ./scripts/feeds install -a
210
211 # remove all symlinks, don't touch ./feeds
212 package/symlinks-clean:
213 ./scripts/feeds uninstall -a
214
215 help:
216 cat README.md
217
218 distclean: cacheclean
219 rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
220 @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
221
222 ifeq ($(findstring v,$(DEBUG)),)
223 .SILENT: symlinkclean clean dirclean distclean config-clean download help tmpinfo-clean .config scripts/config/mconf scripts/config/conf menuconfig staging_dir/host/.prereq-build tmp/.prereq-package prepare-tmpinfo
224 endif
225 .PHONY: help FORCE
226 .NOTPARALLEL:
227