Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colourful makefile info command

Usually I am using echo -e "\e[1:32mMessage\e[0m" to print colourful messages out of the makefile. But now I want to print message inside of the ifndef block, so I am using $(info Message) style. Is it possible to make this kind of message colourful ?

like image 359
mucka Avatar asked Oct 20 '25 13:10

mucka


1 Answers

Yes. You can use a tool like tput to output the literal escape sequences needed instead of using echo -e (which isn't a good idea anyway) to do the same thing.

For example:

$(info $(shell tput setaf 1)Message$(shell tput sgr0))

Though that requires two shells to be spawned and two external commands to be run as opposed to the echo (or similar) methods in a recipe context so that's comparatively more expensive.

You could (and should if you plan on using the colors in more than one place) save the output from tput in a variable and then just re-use that.

red:=$(shell tput setaf 1)
reset:=$(shell tput sgr0)
$(info $(red)Message$(reset))
$(info $(red)Message$(reset))
like image 191
Etan Reisner Avatar answered Oct 22 '25 02:10

Etan Reisner