minor tweaks to the verbose system
[openwrt-10.03/.git] / include / verbose.mk
1
2 # Copyright (C) 2006 OpenWrt.org
3 #
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
6 #
7 # $Id:$
8
9 ifeq ($(NO_TRACE_MAKE),)
10 NO_TRACE_MAKE := $(MAKE) V=99
11 export NO_TRACE_MAKE
12 endif
13
14 ifndef KBUILD_VERBOSE
15   KBUILD_VERBOSE:=0
16 endif
17 ifeq ("$(origin V)", "command line")
18   KBUILD_VERBOSE:=$(V)
19 endif
20
21 ifeq ($(IS_TTY),1)
22   _Y:="\\033[33m" # yellow
23   _N:="\\033[m" #normal
24 endif
25
26 define MESSAGE
27         echo -e "$(_Y)$(1)$(_N)" >&3
28 endef
29
30 ifneq ($(KBUILD_VERBOSE),99)
31   ifeq ($(QUIET),1)
32     $(MAKECMDGOALS): trace
33     trace: FORCE
34         @[ -f "$(MAKECMDGOALS)" ] || { \
35                 [ -z "$${PWD##$$TOPDIR}" ] || DIR=" -C $${PWD##$$TOPDIR/}"; \
36                 $(call MESSAGE, "make[$$(($(MAKELEVEL)+1))]$$DIR $(MAKECMDGOALS)"); \
37         }
38   else
39     export QUIET:=1
40     ifeq ($(KBUILD_VERBOSE),0)
41       MAKE:=&>/dev/null $(MAKE)
42     endif
43     MAKE:=cmd() { $(MAKE) $$* || {  echo "Build failed. Please re-run make with V=99 to see what's going on"; false; } } 3>&1 4>&2; cmd
44   endif
45
46   .SILENT: $(MAKECMDGOALS)
47 endif