Detect if -fdiagnostics-color is available

Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
Sebastian Ramacher 2015-10-06 22:02:51 +02:00
parent f9d1d89bd4
commit 5aa3fa952b

View file

@ -1,16 +1,21 @@
# See LICENSE file for license and copyright information # See LICENSE file for license and copyright information
#
ifeq ($(COLOR),1)
# GCC diagnostics colors
DIAGNOSTICS_COLOR_AVAILABLE ?= $(shell ($(CC) -fdiagnostics-color=always -E - </dev/null >/dev/null 2>/dev/null && echo 1) || echo 0)
ifeq ($(DIAGNOSTICS_COLOR_AVAILABLE),1)
CPPFLAGS += -fdiagnostics-color=always
endif
# colorful output
TPUT ?= /usr/bin/tput TPUT ?= /usr/bin/tput
TPUT_AVAILABLE ?= $(shell ${TPUT} -V 2>/dev/null) TPUT_AVAILABLE ?= $(shell ${TPUT} -V 2>/dev/null)
ifdef TPUT_AVAILABLE ifdef TPUT_AVAILABLE
ifeq ($(COLOR),1)
COLOR_NORMAL = `$(TPUT) sgr0` COLOR_NORMAL = `$(TPUT) sgr0`
COLOR_ACTION = `$(TPUT) bold``$(TPUT) setaf 3` COLOR_ACTION = `$(TPUT) bold``$(TPUT) setaf 3`
COLOR_COMMENT = `$(TPUT) bold``$(TPUT) setaf 2` COLOR_COMMENT = `$(TPUT) bold``$(TPUT) setaf 2`
COLOR_BRACKET = `$(TPUT) setaf 4` COLOR_BRACKET = `$(TPUT) setaf 4`
CC += -fdiagnostics-color=always
define colorecho define colorecho
@echo $(COLOR_BRACKET)" ["$(COLOR_ACTION)$1$(COLOR_BRACKET)"] "$(COLOR_COMMENT)$2$(COLOR_BRACKET) $(COLOR_NORMAL) @echo $(COLOR_BRACKET)" ["$(COLOR_ACTION)$1$(COLOR_BRACKET)"] "$(COLOR_COMMENT)$2$(COLOR_BRACKET) $(COLOR_NORMAL)
endef endef