There are different approaches. And you can make them configurable.
- If you add
@
sign in front of the line within rule, the command itself won't be printed, but its output will.
- If you add
-Werror
to your CFLAGS
variable (you do have one, don't you? It's a common practice!), you definitely won't miss any warning--the build will stop after the first one.
- You can redirect standard output of your command to
/dev/null
, leaving only error stream (this is not for your particular case, because gcc usually doesn't yield output but may be helpful for other commands).
Unfortunately, for qmake
only the second approach applies. Add to your project file:
QMAKE_CFLAGS+=-Werror
QMAKE_CXXFLAGS+=-Werror
And the makefiles generated will use these flags when they invoke compiler, so the build will stop at every warning.
(this section will be moved to another question as soon an one appears).
For usual make you can use it all--you can make it all configurable! Here's the example:
trace?=short
ifeq ($(trace),short)
suppress_echo=@
redirect_to_null=1>/dev/null
else ifeq ($(trace),full)
suppress_echo=
redirect_to_null=
else ifeq ($(trace),werror)
CFLAGS+=-Werror
else
$(error Incorrect trace type "$(trace)"!)
endif
# Thanks to Martin York for the source of this copy-pasted code
out.ext: $(OBJ)
@echo $(CC) $(CFLAGS) -o out.ext $(redirect_to_null)
$(suppress_echo)$(CC) $(CFLAGS) -o out.ext $(OBJ) $(redirect_to_null)
So, if you invoke make
like this:
$ make trace=full
it will print everything. If you invoke
$ make
the short
value will be used by default (note the ?=
operator instead of usual =
!) and the rules will expand to such version
out.ext: out.o
@echo cc -o out.ext 1>/dev/null
@cc -o out.ext out.o 1>/dev/null
what will give much as you need.
Such approach, with configuration, is used in production code. For example, I saw it in Ubuntu's IcedTea makefiles.