build: add scriptconfig target
[openwrt/staging/stintel.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 ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
54 export PATH:=$(path)
55 export STAGING_DIR_HOST:=$(if $(STAGING_DIR),$(abspath $(STAGING_DIR)/../host),$(TOPDIR)/staging_dir/host)
56
57 unexport TAR_OPTIONS
58
59 ifeq ($(FORCE),)
60 .config scripts/config/conf scripts/config/mconf: $(STAGING_DIR_HOST)/.prereq-build
61 endif
62
63 SCAN_COOKIE?=$(shell echo $$$$)
64 export SCAN_COOKIE
65
66 SUBMAKE:=umask 022; $(SUBMAKE)
67
68 ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024;
69
70 prepare-mk: $(STAGING_DIR_HOST)/.prereq-build FORCE ;
71
72 ifdef SDK
73 IGNORE_PACKAGES = linux
74 endif
75
76 _ignore = $(foreach p,$(IGNORE_PACKAGES),--ignore $(p))
77
78 prepare-tmpinfo: FORCE
79 @+$(MAKE) -r -s $(STAGING_DIR_HOST)/.prereq-build $(PREP_MK)
80 mkdir -p tmp/info
81 $(_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=""
82 $(_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"
83 for type in package target; do \
84 f=tmp/.$${type}info; t=tmp/.config-$${type}.in; \
85 [ "$$t" -nt "$$f" ] || ./scripts/$${type}-metadata.pl $(_ignore) config "$$f" > "$$t" || { rm -f "$$t"; echo "Failed to build $$t"; false; break; }; \
86 done
87 [ tmp/.config-feeds.in -nt tmp/.packageauxvars ] || ./scripts/feeds feed_config > tmp/.config-feeds.in
88 ./scripts/package-metadata.pl mk tmp/.packageinfo > tmp/.packagedeps || { rm -f tmp/.packagedeps; false; }
89 ./scripts/package-metadata.pl pkgaux tmp/.packageinfo > tmp/.packageauxvars || { rm -f tmp/.packageauxvars; false; }
90 ./scripts/package-metadata.pl usergroup tmp/.packageinfo > tmp/.packageusergroup || { rm -f tmp/.packageusergroup; 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 ifeq ($(RECURSIVE_DEP_IS_ERROR),1)
100 KCONF_FLAGS=--fatalrecursive
101 endif
102 ifneq ($(DISTRO_PKG_CONFIG),)
103 scripts/config/%onf: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
104 endif
105 scripts/config/%onf: CFLAGS+= -O2
106 scripts/config/%onf: FORCE
107 @$(_SINGLE)$(SUBMAKE) $(if $(findstring s,$(OPENWRT_VERBOSE)),,-s) \
108 -C scripts/config $(notdir $@)
109
110 $(eval $(call rdep,scripts/config,scripts/config/mconf))
111
112 config: scripts/config/conf prepare-tmpinfo FORCE
113 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
114 $< $(KCONF_FLAGS) Config.in
115
116 config-clean: FORCE
117 $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean
118
119 defconfig: scripts/config/conf prepare-tmpinfo FORCE
120 touch .config
121 @if [ ! -s .config -a -e $(HOME)/.openwrt/defconfig ]; then cp $(HOME)/.openwrt/defconfig .config; fi
122 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
123 $< $(KCONF_FLAGS) --defconfig=.config Config.in
124
125 confdefault-y=allyes
126 confdefault-m=allmod
127 confdefault-n=allno
128 confdefault:=$(confdefault-$(CONFDEFAULT))
129
130 oldconfig: scripts/config/conf prepare-tmpinfo FORCE
131 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
132 $< $(KCONF_FLAGS) --$(if $(confdefault),$(confdefault),old)config Config.in
133
134 menuconfig: scripts/config/mconf prepare-tmpinfo FORCE
135 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
136 cp $(HOME)/.openwrt/defconfig .config; \
137 fi
138 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
139 $< Config.in
140
141 nconfig: scripts/config/nconf prepare-tmpinfo FORCE
142 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
143 cp $(HOME)/.openwrt/defconfig .config; \
144 fi
145 [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \
146 $< Config.in
147
148 xconfig: scripts/config/qconf prepare-tmpinfo FORCE
149 if [ \! -e .config -a -e $(HOME)/.openwrt/defconfig ]; then \
150 cp $(HOME)/.openwrt/defconfig .config; \
151 fi
152 $< Config.in
153
154 ifneq ($(filter scriptconfig,$(MAKECMDGOALS)),)
155 ifndef SCRIPT
156 $(error Use "make scriptconfig SCRIPT=/path/to/script")
157 endif
158 endif
159
160 scriptconfig: prepare-tmpinfo FORCE
161 $(STAGING_DIR_HOST)/bin/python3 $(SCRIPT) Config.in
162
163 prepare_kernel_conf: .config toolchain/install FORCE
164
165 ifeq ($(wildcard $(STAGING_DIR_HOST)/bin/quilt),)
166 prepare_kernel_conf:
167 @+$(SUBMAKE) -r tools/quilt/compile
168 else
169 prepare_kernel_conf: ;
170 endif
171
172 kernel_oldconfig: prepare_kernel_conf
173 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig
174
175 ifneq ($(DISTRO_PKG_CONFIG),)
176 kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
177 kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
178 kernel_xconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH)
179 endif
180 kernel_menuconfig: prepare_kernel_conf
181 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux menuconfig
182
183 kernel_nconfig: prepare_kernel_conf
184 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig
185
186 kernel_xconfig: prepare_kernel_conf
187 $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux xconfig
188
189 $(STAGING_DIR_HOST)/.prereq-build: include/prereq-build.mk
190 mkdir -p tmp
191 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prereq-build.mk prereq 2>/dev/null || { \
192 echo "Prerequisite check failed. Use FORCE=1 to override."; \
193 false; \
194 }
195 ifneq ($(realpath $(TOPDIR)/include/prepare.mk),)
196 @$(_SINGLE)$(NO_TRACE_MAKE) -j1 -r -s -f $(TOPDIR)/include/prepare.mk prepare 2>/dev/null || { \
197 echo "Preparation failed."; \
198 false; \
199 }
200 endif
201 touch $@
202
203 printdb: FORCE
204 @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1
205
206 ifndef SDK
207 DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download
208 else
209 DOWNLOAD_DIRS = package/download
210 endif
211
212 download: .config FORCE $(if $(wildcard $(STAGING_DIR_HOST)/bin/flock),,tools/flock/compile)
213 @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);)
214
215 clean dirclean: .config
216 @+$(SUBMAKE) -r $@
217
218 prereq:: prepare-tmpinfo .config
219 @+$(NO_TRACE_MAKE) -r -s $@
220
221 check: .config FORCE
222 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
223
224 val.%: FORCE
225 @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s
226
227 WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE))))
228
229 ifeq ($(SDK),1)
230
231 %::
232 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
233 @./scripts/config/conf $(KCONF_FLAGS) --defconfig=.config Config.in
234 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@
235
236 else
237
238 %::
239 @+$(PREP_MK) $(NO_TRACE_MAKE) -r -s prereq
240 @( \
241 cp .config tmp/.config; \
242 ./scripts/config/conf $(KCONF_FLAGS) --defconfig=tmp/.config -w tmp/.config Config.in > /dev/null 2>&1; \
243 if ./scripts/kconfig.pl '>' .config tmp/.config | grep -q CONFIG; then \
244 printf "$(_R)WARNING: your configuration is out of sync. Please run make menuconfig, oldconfig or defconfig!$(_N)\n" >&2; \
245 fi \
246 )
247 @+$(ULIMIT_FIX) $(SUBMAKE) -r $@ $(if $(WARN_PARALLEL_ERROR), || { \
248 printf "$(_R)Build failed - please re-run with -j1 to see the real error message$(_N)\n" >&2; \
249 false; \
250 } )
251
252 endif
253
254 # update all feeds, re-create index files, install symlinks
255 package/symlinks:
256 ./scripts/feeds update -a
257 ./scripts/feeds install -a
258
259 # re-create index files, install symlinks
260 package/symlinks-install:
261 ./scripts/feeds update -i
262 ./scripts/feeds install -a
263
264 # remove all symlinks, don't touch ./feeds
265 package/symlinks-clean:
266 ./scripts/feeds uninstall -a
267
268 help:
269 cat README.md
270
271 distclean:
272 rm -rf bin build_dir .ccache .config* dl feeds key-build* logs package/feeds staging_dir tmp
273 @$(_SINGLE)$(SUBMAKE) -C scripts/config clean
274
275 ifeq ($(findstring v,$(DEBUG)),)
276 .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
277 endif
278 .PHONY: help scriptconfig FORCE
279 .NOTPARALLEL:
280