diff --git a/Makefile.include b/Makefile.include index 692fe86a53..5ddce7f8dd 100644 --- a/Makefile.include +++ b/Makefile.include @@ -171,6 +171,7 @@ include $(RIOTMAKE)/utils/checks.mk include $(RIOTMAKE)/docker.inc.mk # include color echo macros +include $(RIOTMAKE)/utils/ansi.mk include $(RIOTMAKE)/color.inc.mk # include concurrency helpers diff --git a/makefiles/color.inc.mk b/makefiles/color.inc.mk index d302e5832d..ea494442db 100644 --- a/makefiles/color.inc.mk +++ b/makefiles/color.inc.mk @@ -14,12 +14,11 @@ ifneq ($(CC_NOCOLOR),1) IS_TERMINAL = $(if $(MAKE_TERMOUT),$(MAKE_TERMERR),) # Check if terminal support colored output ifneq ($(IS_TERMINAL),) - _ANSI_ESC := $(shell printf "\033") - COLOR_GREEN := $(_ANSI_ESC)[1;32m - COLOR_RED := $(_ANSI_ESC)[1;31m - COLOR_YELLOW := $(_ANSI_ESC)[1;33m - COLOR_PURPLE := $(_ANSI_ESC)[1;35m - COLOR_RESET := $(_ANSI_ESC)[0m + COLOR_GREEN := $(ANSI_GREEN) + COLOR_RED := $(ANSI_RED) + COLOR_YELLOW := $(ANSI_YELLOW) + COLOR_PURPLE := $(ANSI_PURPLE) + COLOR_RESET := $(ANSI_RESET) ifeq ($(OS),Darwin) COLOR_ECHO := echo -e SHELL=bash diff --git a/makefiles/utils/ansi.mk b/makefiles/utils/ansi.mk new file mode 100644 index 0000000000..53fabdb054 --- /dev/null +++ b/makefiles/utils/ansi.mk @@ -0,0 +1,11 @@ +# ANSI Terminal codes and other escape sequences. +# The objective of this definitions is to be able to write special characters +# without resorting to shell commands like echo. + +include $(RIOTMAKE)/utils/ansi_special.mk + +ANSI_GREEN := $(ANSI_ESC)[1;32m +ANSI_RED := $(ANSI_ESC)[1;31m +ANSI_YELLOW := $(ANSI_ESC)[1;33m +ANSI_PURPLE := $(ANSI_ESC)[1;35m +ANSI_RESET := $(ANSI_ESC)[0m diff --git a/makefiles/utils/ansi_special.mk b/makefiles/utils/ansi_special.mk new file mode 100644 index 0000000000..a67d5367bb --- /dev/null +++ b/makefiles/utils/ansi_special.mk @@ -0,0 +1,16 @@ +# Make does not recognize escaped characters (e.g. \t, \033, etc). +# The following variables contain the characters themselves. +# This file is inherently fragile (i.e. your editor could destroy the tab +# without you realizing, to be careful when editing this. + +# To generate this: $ printf "ANSI_ESC := \033# comment" +ANSI_ESC := # you may or may not be able to see that character in your editor + +# The third parameter to the subst is a tab - be careful not to replace it with +# spaces! +TAB := $(subst ,, ) + +define NEWLINE + + +endef