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