devel/trace-cmd: Update to 2.6.1
[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 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
109 $< Config.in
110
111 config-clean: FORCE
112 $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
113
114 defconfig: scripts/config/conf prepare-tmpinfo FORCE
115 touch .config
116 @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
117 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
118 $< --defconfig=.config Config.in
119
120 confdefault-y=allyes
121 confdefault-m=allmod
122 confdefault-n=allno
123 confdefault:=$(confdefault-$(CONFDEFAULT))
124
125 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
126 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
127 $< --$(if $(confdefault),$(confdefault),old)config Config.in
128
129 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
130 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
131 cp $(HOME)/.openwrt/defconfig .config; \
132 fi
133 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
134 $< Config.in
135
136 prepare_kernel_conf: .config FORCE
137
138 ifeq ($(wildcard staging_dir/host/bin/quilt),)
139 prepare_kernel_conf:
140 @+$(SUBMAKE) -r tools/quilt/install
141 else
142 prepare_kernel_conf: ;
143 endif
144
145 kernel_oldconfig: prepare_kernel_conf
146 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
147
148 kernel_menuconfig: prepare_kernel_conf
149 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
150
151 kernel_nconfig: prepare_kernel_conf
152 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
153
154 staging_dir/host/.prereq-build: include/prereq-build.mk
155 mkdir -p tmp
156 rm -f tmp/.host.mk
157 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
158 echo "Prerequisite check failed. Use FORCE=1 to override."; \
159 false; \
160 }
161 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
162 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
163 echo "Preparation failed."; \
164 false; \
165 }
166 endif
167 touch $@
168
169 printdb: FORCE
170 @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
171
172 ifndef SDK
173 DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
174 else
175 DOWNLOAD_DIRS = package/download
176 endif
177
178 download: .config FORCE $(if $(wildcard $(TOPDIR)/staging_dir/host/bin/flock),,tools/flock/compile)
179 @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
180
181 clean dirclean: .config
182 @+$(SUBMAKE) -r $@
183
184 prereq:: prepare-tmpinfo .config
185 @+$(NO_TRACE_MAKE) -r -s $@
186
187 check: .config FORCE
188 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
189
190 val.%: FORCE
191 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
192
193 WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
194
195 ifeq ($(SDK),1)
196
197 %::
198 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
199 @./scripts/config/conf --defconfig=.config Config.in
200 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
201
202 else
203
204 %::
205 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
206 @( \
207 cp .config tmp/.config; \
208 ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
209 if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
210 printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
211 fi \
212 )
213 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
214 printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
215 false; \
216 } )
217
218 endif
219
220 # update all feeds, re-create index files, install symlinks
221 package/symlinks:
222 ./scripts/feeds update -a
223 ./scripts/feeds install -a
224
225 # re-create index files, install symlinks
226 package/symlinks-install:
227 ./scripts/feeds update -i
228 ./scripts/feeds install -a
229
230 # remove all symlinks, don't touch ./feeds
231 package/symlinks-clean:
232 ./scripts/feeds uninstall -a
233
234 help:
235 cat README
236
237 distclean:
238 rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
239 @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
240
241 ifeq ($(findstring v,$(DEBUG)),)
242 .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
243 endif
244 .PHONY: help FORCE
245 .NOTPARALLEL:
246