image.mk: force rebuild of kernel dependent parts - fixes auto-rebuild on DTS changes
[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 RELEASE:=Chaos Calmer
10 PREP_MK= OPENWRT_BUILD= QUIET=0
11
12 export IS_TTY=$(shell tty -s && echo 1 || echo 0)
13
14 include $(TOPDIR)/include/verbose.mk
15
16 ifeq ($(SDK),1)
17 include $(TOPDIR)/include/version.mk
18 else
19 REVISION:=$(shell $(TOPDIR)/scripts/getver.sh)
20 endif
21
22 HOSTCC ?= $(CC)
23 OPENWRTVERSION:=$(RELEASE)$(if $(REVISION), ($(REVISION)))
24 export RELEASE
25 export REVISION
26 export OPENWRTVERSION
27 export LD_LIBRARY_PATH:=$(subst ::,:,$(if $(LD_LIBRARY_PATH),$(LD_LIBRARY_PATH):)$(STAGING_DIR_HOST)/lib)
28 export DYLD_LIBRARY_PATH:=$(subst ::,:,$(if $(DYLD_LIBRARY_PATH),$(DYLD_LIBRARY_PATH):)$(STAGING_DIR_HOST)/lib)
29 export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
30 export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
31
32 # prevent perforce from messing with the patch utility
33 unexport P4PORT P4USER P4CONFIG P4CLIENT
34
35 # prevent user defaults for quilt from interfering
36 unexport QUILT_PATCHES QUILT_PATCH_OPTS
37
38 unexport C_INCLUDE_PATH CROSS_COMPILE ARCH
39
40 # prevent distro default LPATH from interfering
41 unexport LPATH
42
43 # make sure that a predefined CFLAGS variable does not disturb packages
44 export CFLAGS=
45
46 unexport TAR_OPTIONS
47
48 ifneq ($(shell $(HOSTCC) 2>&1 | grep clang),)
49 export HOSTCC_REAL?=$(HOSTCC)
50 export HOSTCC_WRAPPER:=$(TOPDIR)/scripts/clang-gcc-wrapper
51 else
52 export HOSTCC_WRAPPER:=$(HOSTCC)
53 endif
54
55 ifeq ($(FORCE),)
56 .config scripts/config/conf scripts/config/mconf: staging_dir/host/.prereq-build
57 endif
58
59 SCAN_COOKIE?=$(shell echo $$$$)
60 export SCAN_COOKIE
61
62 SUBMAKE:=umask 022; $(SUBMAKE)
63
64 ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
65
66 prepare-mk: FORCE ;
67
68 prepare-tmpinfo: FORCE
69 @+$(MAKE) -r -s staging_dir/host/.prereq-build $(PREP_MK)
70 mkdir -p tmp/info
71 $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="packageinfo" SCAN_DIR="package" SCAN_NAME="package" SCAN_DEPS="$(TOPDIR)/include/package*.mk $(TOPDIR)/overlay/*/*.mk" SCAN_DEPTH=5 SCAN_EXTRA=""
72 $(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f include/scan.mk SCAN_TARGET="targetinfo" SCAN_DIR="target/linux" SCAN_NAME="target" SCAN_DEPS="profiles/*.mk $(TOPDIR)/include/kernel*.mk $(TOPDIR)/include/target.mk" SCAN_DEPTH=2 SCAN_EXTRA="" SCAN_MAKEOPTS="TARGET_BUILD=1"
73 for type in package target; do \
74 f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
75 [ "$$t" -nt "$$f" ] || ./scripts/metadata.pl $${type}_config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
76 done
77 [ tmp/.config-feeds.in -nt tmp/.packagefeeds ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
78 ./scripts/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
79 ./scripts/metadata.pl package_feeds tmp/.packageinfo > tmp/.packagefeeds || { rm -f tmp/.packagefeeds; false; }
80 touch $(TOPDIR)/tmp/.build
81
82 .config: ./scripts/config/conf $(if $(CONFIG_HAVE_DOT_CONFIG),,prepare-tmpinfo)
83 @+if [ \! -e .config ] || ! grep CONFIG_HAVE_DOT_CONFIG .config >/dev/null; then \
84 [ -e $(HOME)/.openwrt/defconfig ] && cp $(HOME)/.openwrt/defconfig .config; \
85 $(_SINGLE)$(NO_TRACE_MAKE) menuconfig $(PREP_MK); \
86 fi
87
88 scripts/config/mconf:
89 @$(_SINGLE)$(SUBMAKE) -s -C scripts/config all CC="$(HOSTCC_WRAPPER)"
90
91 $(eval $(call rdep,scripts/config,scripts/config/mconf))
92
93 scripts/config/conf:
94 @$(_SINGLE)$(SUBMAKE) -s -C scripts/config conf CC="$(HOSTCC_WRAPPER)"
95
96 config: scripts/config/conf prepare-tmpinfo FORCE
97 $< Config.in
98
99 config-clean: FORCE
100 $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
101
102 defconfig: scripts/config/conf prepare-tmpinfo FORCE
103 touch .config
104 @if [ -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
105 $< --defconfig=.config Config.in
106
107 confdefault-y=allyes
108 confdefault-m=allmod
109 confdefault-n=allno
110 confdefault:=$(confdefault-$(CONFDEFAULT))
111
112 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
113 $< --$(if $(confdefault),$(confdefault),old)config Config.in
114
115 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
116 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
117 cp $(HOME)/.openwrt/defconfig .config; \
118 fi
119 $< Config.in
120
121 prepare_kernel_conf: .config FORCE
122
123 ifeq ($(wildcard staging_dir/host/bin/quilt),)
124 prepare_kernel_conf:
125 @+$(SUBMAKE) -r tools/quilt/install
126 else
127 prepare_kernel_conf: ;
128 endif
129
130 kernel_oldconfig: prepare_kernel_conf
131 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
132
133 kernel_menuconfig: prepare_kernel_conf
134 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
135
136 kernel_nconfig: prepare_kernel_conf
137 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
138
139 staging_dir/host/.prereq-build: include/prereq-build.mk
140 mkdir -p tmp
141 rm -f tmp/.host.mk
142 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
143 echo "Prerequisite check failed. Use FORCE=1 to override."; \
144 false; \
145 }
146 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
147 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
148 echo "Preparation failed."; \
149 false; \
150 }
151 endif
152 touch $@
153
154 printdb: FORCE
155 @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
156
157 download: .config FORCE
158 @+$(SUBMAKE) tools/download
159 @+$(SUBMAKE) toolchain/download
160 @+$(SUBMAKE) package/download
161 @+$(SUBMAKE) target/download
162
163 clean dirclean: .config
164 @+$(SUBMAKE) -r $@
165
166 prereq:: prepare-tmpinfo .config
167 @+$(NO_TRACE_MAKE) -r -s $@
168
169 WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
170
171 ifeq ($(SDK),1)
172
173 %::
174 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
175 @./scripts/config/conf --defconfig=.config Config.in
176 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
177
178 else
179
180 %::
181 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
182 @( \
183 cp .config tmp/.config; \
184 ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
185 if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
186 printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
187 fi \
188 )
189 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
190 printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
191 false; \
192 } )
193
194 endif
195
196 help:
197 cat README
198
199 docs docs/compile: FORCE
200 @$(_SINGLE)$(SUBMAKE) -C docs compile
201
202 docs/clean: FORCE
203 @$(_SINGLE)$(SUBMAKE) -C docs clean
204
205 distclean:
206 rm -rf tmp build_dir staging_dir dl .config* feeds package/feeds package/openwrt-packages bin
207 @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
208
209 ifeq ($(findstring v,$(DEBUG)),)
210 .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
211 endif
212 .PHONY: help FORCE
213 .NOTPARALLEL:
214