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