13 Aug 2016 Fine-grained verbosity control in Makefiles 13 Aug 2016

Do you want a quiet build, but with the ability to use CMake’s VERBOSE=1 argument? Put these two lines at the start of your Makefile:

AT_ = @
AT = $(AT_$(VERBOSE))

then substitute all your @ echo suppressors with $(AT). This is an old-timey trick that gives you instant Makefile karma, firmly establishes your UNIX creds, and is all made possible thanks to the beauty of computed variable names. If the VERBOSE argument is not given, then $(VERBOSE) resolves to nil, so that $(AT) in turn resolves to $(AT_), i.e. @.

Recently I’ve taken to extending this idea in my own monstrosities to allow fine-grained, multi-level verbosity control. This allows me to control the amount of crud which gets dumped to the screen over various levels, but requires a little more boilerplate: