535ac0e065698347774fdbc717d7480a88408ae0
[oweals/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:=Designated Driver
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 export RELEASE
24 export REVISION
25 export GIT_CONFIG_PARAMETERS='core.autocrlf=false'
26 export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS))
27 export SOURCE_DATE_EPOCH:=$(shell $(TOPDIR)/scripts/get_source_date_epoch.sh)
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: 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/metadata.pl $(_ignore) $${type}_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/metadata.pl package_mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
90         ./scripts/metadata.pl package_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 [ -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         $< 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 download: .config FORCE
169         @+$(SUBMAKE) tools/download
170         @+$(SUBMAKE) toolchain/download
171         @+$(SUBMAKE) package/download
172         @+$(SUBMAKE) target/download
173
174 clean dirclean: .config
175         @+$(SUBMAKE) -r $@
176
177 prereq:: prepare-tmpinfo .config
178         @+$(NO_TRACE_MAKE) -r -s $@
179
180 WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
181
182 ifeq ($(SDK),1)
183
184 %::
185         @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
186         @./scripts/config/conf --defconfig=.config Config.in
187         @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
188
189 else
190
191 %::
192         @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
193         @( \
194                 cp .config tmp/.config; \
195                 ./scripts/config/conf --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
196                 if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
197                         printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
198                 fi \
199         )
200         @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
201                 printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
202                 false; \
203         } )
204
205 endif
206
207 # update all feeds, re-create index files, install symlinks
208 package/symlinks:
209         ./scripts/feeds update -a
210         ./scripts/feeds install -a
211
212 # re-create index files, install symlinks
213 package/symlinks-install:
214         ./scripts/feeds update -i
215         ./scripts/feeds install -a
216
217 # remove all symlinks, don't touch ./feeds
218 package/symlinks-clean:
219         ./scripts/feeds uninstall -a
220
221 help:
222         cat README
223
224 docs docs/compile: FORCE
225         @$(_SINGLE)$(SUBMAKE) -C docs compile
226
227 docs/clean: FORCE
228         @$(_SINGLE)$(SUBMAKE) -C docs clean
229
230 distclean:
231         rm -rf bin build_dir .config* dl feeds key-build* logs package/feeds package/openwrt-packages staging_dir tmp
232         @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
233
234 ifeq ($(findstring v,$(DEBUG)),)
235   .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
236 endif
237 .PHONY: help FORCE
238 .NOTPARALLEL:
239