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