verbose.mk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. #
  3. # Copyright (C) 2006-2020 OpenWrt.org
  4. ifndef OPENWRT_VERBOSE
  5. OPENWRT_VERBOSE:=
  6. endif
  7. ifeq ("$(origin V)", "command line")
  8. OPENWRT_VERBOSE:=$(V)
  9. endif
  10. ifeq ($(OPENWRT_VERBOSE),1)
  11. OPENWRT_VERBOSE:=w
  12. endif
  13. ifeq ($(OPENWRT_VERBOSE),99)
  14. OPENWRT_VERBOSE:=s
  15. endif
  16. ifeq ($(NO_TRACE_MAKE),)
  17. NO_TRACE_MAKE := $(MAKE) V=s$(OPENWRT_VERBOSE)
  18. export NO_TRACE_MAKE
  19. endif
  20. ifeq ($(IS_TTY),1)
  21. ifneq ($(strip $(NO_COLOR)),1)
  22. _Y:=\\033[33m
  23. _R:=\\033[31m
  24. _N:=\\033[m
  25. endif
  26. endif
  27. define ERROR_MESSAGE
  28. { \
  29. printf "$(_R)%s$(_N)\n" "$(1)" >&9 || \
  30. printf "$(_R)%s$(_N)\n" "$(1)"; \
  31. } >&2 2>/dev/null
  32. endef
  33. ifeq ($(findstring s,$(OPENWRT_VERBOSE)),)
  34. define MESSAGE
  35. { \
  36. printf "$(_Y)%s$(_N)\n" "$(1)" >&8 || \
  37. printf "$(_Y)%s$(_N)\n" "$(1)"; \
  38. } 2>/dev/null
  39. endef
  40. ifeq ($(QUIET),1)
  41. ifneq ($(CURDIR),$(TOPDIR))
  42. _DIR:=$(patsubst $(TOPDIR)/%,%,${CURDIR})
  43. else
  44. _DIR:=
  45. endif
  46. _MESSAGE:=$(if $(MAKECMDGOALS),$(shell \
  47. $(call MESSAGE, make[$(MAKELEVEL)]$(if $(_DIR), -C $(_DIR)) $(MAKECMDGOALS)); \
  48. ))
  49. ifneq ($(strip $(_MESSAGE)),)
  50. $(info $(_MESSAGE))
  51. endif
  52. SUBMAKE=$(MAKE)
  53. else
  54. SILENT:=>/dev/null $(if $(findstring w,$(OPENWRT_VERBOSE)),,2>&1)
  55. export QUIET:=1
  56. 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
  57. endif
  58. .SILENT: $(MAKECMDGOALS)
  59. else
  60. SUBMAKE=$(MAKE) -w
  61. define MESSAGE
  62. printf "%s\n" "$(1)"
  63. endef
  64. endif