Question

how can I format the make output (!!by only changing the qmake project file!!). My compilation lines continue growing, and the one-line-warnings/errors almost disappear between them.

I am thinking of something like

$(CC) in.ext -o out.ext

thanks in regard

Was it helpful?

Solution

In qmake, you can add a silent configuration option:

CONFIG += silent

(note: I think that's the command. It's something similar to this.)

Which should suppress most of the output, and only print lines like "compiling a.o", along with your warnings and errors. I believe this is similar to make's .SILENT. directive (I think that's the one...)

You may want to be careful with this, however, because it suppresses a lot of information that error parsers like to use. For example, if you are compiling with a SUBDIRS configuration, it won't print out when it changes to the different directories.

OTHER TIPS

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.

You can suppress the printout with '@' and echo what you want to see:

Simple Example:

out.ext:  $(OBJ)
    @echo $(CC) -o out.ext
    @$(CC) -o out.ext $(OBJ) $(OTHER_FLAGS_ETC)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top