tags:

views:

68

answers:

3

In makefiles, a line prefixed with an at symbols disables the print of the output. I have a makefile where every line is prefixed with an at, but for debug I need to see what's going on. Is there a way to tell make to ignore the at and output the line ? the debug is excessive, and the -n option prints them, but does not do anything (it's for dry run)

+2  A: 

In GNU Make, this isn't possible out of the box. Having a Makefile which is non-configurably completely silent is simply bad practice. Removing the @ signs and running with -s is the easiest way to get a silent build (except for possible echo commands).

larsmans
It's possible (and easy) to make a Makefile with configurable verbosity. The linux kernel does this, as do `automake`-generated `Makefile`s with `AM_SILENT_RULES`.
Jack Kelly
Nice trick and a deservedly accepted answer, but my remarks stand.
larsmans
@larsmans: True. If you make some trivial edit, I'll remove my downvote.
Jack Kelly
+3  A: 

You can have make tell someone else to print the commands as they are executed, which is much the same thing:

make SHELL='/bin/sh -x' ...your make arguments...

However this won't work quite so well if your makefile contains shell script fragments as recipes, rather than sequences of separate simple commands, as you'll see the individual shell commands as they are encountered instead of the whole fragments as they are invoked.

Alternatively, you could actually take advantage of the free-software nature of GNU Make and hack up your own version that ignores the @ signs. Grepping the GNU Make source code for COMMANDS_SILENT will soon show you that it suffices to add 1 || to the ?: condition in the arguments to the message() call in start_job_command() in job.c. Job done!

John Marshall
+1 for a willingness to dive into the source. Free software is great like that.
Jack Kelly
+5  A: 

Make a variable that has a default value of @:

AT := @

And then use that in your Makefile:

foo:
    $(AT)fooc -o $@

Then run make as make AT=. You can get fancier than that, if you like:

V := 0
AT_0 := @
AT_1 :=
AT = $(AT_$(V))

This will make commands silent, unless V is set to 1 (e.g., make V=1). This uses the non-POSIX, but common feature of recursive variable expansion.

Jack Kelly
You may be able to use `:=` instead of `=` for the `AT =` line as well. I can't remember.
Jack Kelly
+1 for cool trick
Matt Joiner