b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 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 | RTOOLS ?= |
| 19 | BITNUM := $(shell getconf LONG_BIT) |
| 20 | NONEXIST := $(shell $(TOPDIR)/scripts/gettools.sh) |
| 21 | TOOLS_REFRESH:=0 |
| 22 | ifeq ($(NONEXIST),1) |
| 23 | TOOLS_REFRESH:=1 |
| 24 | endif |
| 25 | ifneq ($(strip $(RTOOLS)),) |
| 26 | TOOLS_REFRESH:=1 |
| 27 | endif |
| 28 | export TOOLS_REFRESH |
| 29 | export NONEXIST |
| 30 | export BITNUM |
| 31 | |
| 32 | export REVISION |
| 33 | export SOURCE_DATE_EPOCH |
| 34 | export GIT_CONFIG_PARAMETERS='core.autocrlf=false' |
| 35 | export GIT_ASKPASS:=/bin/true |
| 36 | export MAKE_JOBSERVER=$(filter --jobserver%,$(MAKEFLAGS)) |
| 37 | export GNU_HOST_NAME:=$(shell $(TOPDIR)/scripts/config.guess) |
| 38 | export HOST_OS:=$(shell uname) |
| 39 | export HOST_ARCH:=$(shell uname -m) |
| 40 | |
| 41 | ifeq ($(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 |
| 45 | endif |
| 46 | |
| 47 | # prevent perforce from messing with the patch utility |
| 48 | unexport P4PORT P4USER P4CONFIG P4CLIENT |
| 49 | |
| 50 | # prevent user defaults for quilt from interfering |
| 51 | unexport QUILT_PATCHES QUILT_PATCH_OPTS |
| 52 | |
| 53 | unexport C_INCLUDE_PATH CROSS_COMPILE ARCH |
| 54 | |
| 55 | # prevent distro default LPATH from interfering |
| 56 | unexport LPATH |
| 57 | |
| 58 | # make sure that a predefined CFLAGS variable does not disturb packages |
| 59 | export CFLAGS= |
| 60 | export LDFLAGS= |
| 61 | |
| 62 | empty:= |
| 63 | space:= $(empty) $(empty) |
| 64 | path:=$(subst :,$(space),$(PATH)) |
| 65 | path:=$(filter-out .%,$(path)) |
| 66 | path:=$(subst $(space),:,$(path)) |
| 67 | export ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH)) |
| 68 | export PATH:=$(path) |
| 69 | export STAGING_DIR_HOST:=$(if $(STAGING_DIR),$(abspath $(STAGING_DIR)/../host),$(TOPDIR)/staging_dir/host) |
| 70 | |
| 71 | unexport TAR_OPTIONS |
| 72 | |
| 73 | ifeq ($(FORCE),) |
| 74 | .config scripts/config/conf scripts/config/mconf: $(STAGING_DIR_HOST)/.prereq-build |
| 75 | endif |
| 76 | |
| 77 | SCAN_COOKIE?=$(shell echo $$$$) |
| 78 | export SCAN_COOKIE |
| 79 | |
| 80 | SUBMAKE:=umask 022; $(SUBMAKE) |
| 81 | |
| 82 | ULIMIT_FIX=_limit=`ulimit -n`; [ "$$_limit" = "unlimited" -o "$$_limit" -ge 1024 ] || ulimit -n 1024; |
| 83 | |
| 84 | prepare-mk: $(STAGING_DIR_HOST)/.prereq-build FORCE ; |
| 85 | |
| 86 | ifdef SDK |
| 87 | IGNORE_PACKAGES = linux |
| 88 | endif |
| 89 | |
| 90 | _ignore = $(foreach p,$(IGNORE_PACKAGES),--ignore $(p)) |
| 91 | |
| 92 | prepare-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 |
| 113 | ifneq (,$(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 | ) |
| 135 | endif |
| 136 | |
| 137 | ifeq ($(RECURSIVE_DEP_IS_ERROR),1) |
| 138 | KCONF_FLAGS=--fatalrecursive |
| 139 | endif |
| 140 | ifneq ($(DISTRO_PKG_CONFIG),) |
| 141 | scripts/config/%onf: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH) |
| 142 | endif |
| 143 | scripts/config/%onf: CFLAGS+= -O2 |
| 144 | scripts/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 | |
| 150 | config: scripts/config/conf prepare-tmpinfo FORCE |
| 151 | [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \ |
| 152 | $< $(KCONF_FLAGS) Config.in |
| 153 | |
| 154 | config-clean: FORCE |
| 155 | $(_SINGLE)$(NO_TRACE_MAKE) -C scripts/config clean |
| 156 | |
| 157 | defconfig: 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 | |
| 163 | defconfig_%: 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 | |
| 169 | confdefault-y=allyes |
| 170 | confdefault-m=allmod |
| 171 | confdefault-n=allno |
| 172 | confdefault:=$(confdefault-$(CONFDEFAULT)) |
| 173 | |
| 174 | oldconfig: scripts/config/conf prepare-tmpinfo FORCE |
| 175 | [ -L .config ] && export KCONFIG_OVERWRITECONFIG=1; \ |
| 176 | $< $(KCONF_FLAGS) --$(if $(confdefault),$(confdefault),old)config Config.in |
| 177 | |
| 178 | menuconfig: 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 | |
| 185 | nconfig: 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 | |
| 192 | xconfig: 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 | |
| 198 | prepare_kernel_conf: .config toolchain/install FORCE |
| 199 | |
| 200 | ifeq ($(wildcard $(STAGING_DIR_HOST)/bin/quilt),) |
| 201 | prepare_kernel_conf: |
| 202 | @+$(SUBMAKE) -r tools/quilt/compile |
| 203 | else |
| 204 | prepare_kernel_conf: ; |
| 205 | endif |
| 206 | |
| 207 | kernel_oldconfig: prepare_kernel_conf |
| 208 | $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux oldconfig |
| 209 | |
| 210 | ifneq ($(DISTRO_PKG_CONFIG),) |
| 211 | kernel_menuconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH) |
| 212 | kernel_nconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH) |
| 213 | kernel_xconfig: export PATH:=$(dir $(DISTRO_PKG_CONFIG)):$(PATH) |
| 214 | endif |
| 215 | kernel_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 | |
| 219 | kernel_nconfig: prepare_kernel_conf |
| 220 | $(_SINGLE)$(NO_TRACE_MAKE) -C target/linux nconfig |
| 221 | |
| 222 | kernel_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 | |
| 239 | printdb: FORCE |
| 240 | @$(_SINGLE)$(NO_TRACE_MAKE) -p $@ V=99 DUMP_TARGET_DB=1 2>&1 |
| 241 | |
| 242 | ifndef SDK |
| 243 | DOWNLOAD_DIRS = tools/download toolchain/download package/download target/download |
| 244 | else |
| 245 | DOWNLOAD_DIRS = package/download |
| 246 | endif |
| 247 | |
| 248 | download: .config FORCE $(if $(wildcard $(STAGING_DIR_HOST)/bin/flock),,tools/flock/compile) |
| 249 | @+$(foreach dir,$(DOWNLOAD_DIRS),$(SUBMAKE) $(dir);) |
| 250 | |
| 251 | clean 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 | |
| 256 | prereq:: prepare-tmpinfo .config |
| 257 | @+$(NO_TRACE_MAKE) -r -s $@ |
| 258 | |
| 259 | check: .config FORCE |
| 260 | @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s |
| 261 | |
| 262 | val.% var.%: FORCE |
| 263 | @+$(NO_TRACE_MAKE) -r -s $@ QUIET= V=s |
| 264 | |
| 265 | WARN_PARALLEL_ERROR = $(if $(BUILD_LOG),,$(and $(filter -j,$(MAKEFLAGS)),$(findstring s,$(OPENWRT_VERBOSE)))) |
| 266 | |
| 267 | ifeq ($(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 | |
| 274 | else |
| 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 | |
| 290 | endif |
| 291 | |
| 292 | # update all feeds, re-create index files, install symlinks |
| 293 | package/symlinks: |
| 294 | ./scripts/feeds update -a |
| 295 | ./scripts/feeds install -a |
| 296 | |
| 297 | # re-create index files, install symlinks |
| 298 | package/symlinks-install: |
| 299 | ./scripts/feeds update -i |
| 300 | ./scripts/feeds install -a |
| 301 | |
| 302 | # remove all symlinks, don't touch ./feeds |
| 303 | package/symlinks-clean: |
| 304 | ./scripts/feeds uninstall -a |
| 305 | |
| 306 | help: |
| 307 | cat README.md |
| 308 | |
| 309 | preclean: |
| 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 | |
| 317 | distclean: preclean |
| 318 | rm -rf owtoolchain host bin |
| 319 | |
| 320 | ifeq ($(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 |
| 322 | endif |
| 323 | .PHONY: help FORCE |
| 324 | .NOTPARALLEL: |
| 325 | |