简体   繁体   English

多彩的makefile信息命令

[英]Colourful makefile info command

Usually I am using echo -e "\\e[1:32mMessage\\e[0m" to print colourful messages out of the makefile. 通常,我使用echo -e "\\e[1:32mMessage\\e[0m" ]从makefile中打印彩色消息。 But now I want to print message inside of the ifndef block, so I am using $(info Message) style. 但是现在我想在ifndef块中打印消息,所以我使用$(info Message)样式。 Is it possible to make this kind of message colourful ? 是否可以使这种消息变得丰富多彩?

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. 您可以使用tput类的工具来输出所需的原义转义序列,而不是使用echo -e (无论如何这不是一个好主意)来执行相同的操作。

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. 尽管这需要派生两个 shell并运行两个外部命令,而不是在配方上下文中运行echo (或类似的)方法,所以相对而言比较昂贵。

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. 您可以(并且如果您打算在多个位置使用颜色)应该将tput的输出保存在变量中,然后重新使用它。

red:=$(shell tput setaf 1)
reset:=$(shell tput sgr0)
$(info $(red)Message$(reset))
$(info $(red)Message$(reset))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM