My (makefile-based) build system outputs quite an amount of diagnostics, and I wish to color them, as explained in this question (preferably using tput setaf
and tput sgr0
).
However, editing all the strings from all my hierarchical Makefiles in my system would be an overwhelming and non-practical task (if I change my mind in the future, it would be another overwhelming task to undo it again).
Ideally, I'd like to have custom constructs like my_warning_echo
, my_error_echo
, etc..., exactly with the same syntax as echo
.
For example, the syntax would be my_warning_echo "some text message"
and the implementation would be such that outputs @echo "$$(tput setaf 3)some text message$$(tput sgr0)
(the double $$ are because this will be used from inside a Makefile).
The main problem is with the closing tput sgr0
(otherwise I could just use a macro that holds @echo "$$(tput setaf 3)
).
I could also write a shell function taking one argument (the text message), but the syntax will require adding parentheses at the beginning and at the end of the message.
Is there any approach which would let me keep the same syntax as the standard echo
?
Solutions that depend on GNU make would be fine (I prefer to be as standard as possible, but my build system already uses GNU make extensions, so...)