tags:

views:

463

answers:

3

Hello,

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

A: 

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)
Martin York
Uh I want to make the magic unside and only inside qmake. Sorry for the confusion.
Ronny
+2  A: 

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.

Pavel Shved
Uh I want to make the magic unside and only inside qmake. Sorry for the confusion.
Ronny
+1: for -Werror. That's the best suggestion IMO and this _can_ be done in your project file.
Troubadour
@hydroes: edited my answer to try to fit your needs
Pavel Shved
thanks for your help guys, but -Werror does not provide what I need. (We cannot exit on warning, because we have deprecation warnings, which remain inside until the assigned worker changes the section)
Ronny
+3  A: 

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.

Caleb Huitt - cjhuitt
awesome. exactly what I needed
Ronny