blob: f6aa0d701213907f8493afa408d723a246a7686c [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001# SPDX-License-Identifier: GPL-2.0-only
2#
3# Copyright (C) 2006-2020 OpenWrt.org
4
5ifndef OPENWRT_VERBOSE
6 OPENWRT_VERBOSE:=
7endif
8ifeq ("$(origin V)", "command line")
9 OPENWRT_VERBOSE:=$(V)
10endif
11
12ifeq ($(OPENWRT_VERBOSE),1)
13 OPENWRT_VERBOSE:=w
14endif
15ifeq ($(OPENWRT_VERBOSE),99)
16 OPENWRT_VERBOSE:=s
17endif
18
19ifeq ($(NO_TRACE_MAKE),)
20NO_TRACE_MAKE := $(MAKE) V=s$(OPENWRT_VERBOSE)
21export NO_TRACE_MAKE
22endif
23
24ifeq ($(IS_TTY),1)
25 ifneq ($(strip $(NO_COLOR)),1)
26 _Y:=\\033[33m
27 _R:=\\033[31m
28 _N:=\\033[m
29 endif
30endif
31
32define ERROR_MESSAGE
33 { \
34 printf "$(_R)%s$(_N)\n" "$(1)" >&9 || \
35 printf "$(_R)%s$(_N)\n" "$(1)"; \
36 } >&2 2>/dev/null
37endef
38
39ifeq ($(findstring s,$(OPENWRT_VERBOSE)),)
40 define MESSAGE
41 { \
42 printf "$(_Y)%s$(_N)\n" "$(1)" >&8 || \
43 printf "$(_Y)%s$(_N)\n" "$(1)"; \
44 } 2>/dev/null
45 endef
46
47 ifeq ($(QUIET),1)
48 ifneq ($(CURDIR),$(TOPDIR))
49 _DIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
50 else
51 _DIR:=
52 endif
53 _MESSAGE:=$(if $(MAKECMDGOALS),$(shell \
54 $(call MESSAGE, make[$(MAKELEVEL)]$(if $(_DIR), -C $(_DIR)) $(MAKECMDGOALS)); \
55 ))
56 ifneq ($(strip $(_MESSAGE)),)
57 $(info $(_MESSAGE))
58 endif
59 SUBMAKE=$(MAKE)
60 else
61 SILENT:=>/dev/null $(if $(findstring w,$(OPENWRT_VERBOSE)),,2>&1)
62 export QUIET:=1
63 SUBMAKE=cmd() { $(SILENT) $(MAKE) -s "$$@" < /dev/null || { echo "make $$*: build failed. Please re-run make with -j1 V=s or V=sc for a higher verbosity level to see what's going on"; false; } } 8>&1 9>&2; cmd
64 endif
65
66 .SILENT: $(MAKECMDGOALS)
67else
68 SUBMAKE=$(MAKE) -w
69 define MESSAGE
70 printf "%s\n" "$(1)"
71 endef
72endif