views:

71

answers:

3

I am writing a short shell script which calls 'make all'. It's not critical, but is there a way I can suppress the message saying 'nothing to be done for all' if that is the case? I am hoping to find a flag for make which suppresses this (not sure there is one), but an additional line or 2 of code would work too.

FYI I'm using bash.

Edit: to be more clear, I only want to suppess messages that therer is nothing to be done. Otherwise, I want to display the output.

+1  A: 

The flag -s silences make: make -s all

EDIT: I originally answered that the flag -q silenced make. It works for me, although the manpage specifies -s, --silent, --quiet as the valid flags.

Ryan Tenney
@Ryan W Tenney, for me this is `-s`, `--silent` or `--quiet`
Anders
I should have been more clear. I only want to suppress the case where the files are up to date. Otherwise I want to show the output.
I saw someone else answered and suggested `make all | grep -v "Nothing to be done for"` but it seems they deleted that answer.
Ryan Tenney
Yea I liked that answer too..
+2  A: 

The grep solution:

{ make all 2>&1 1>&3 | grep -v 'No rule to make target `all' >&2; } 3>&1 

The construct 2>&1 1>&3 sends make's stdout to fd 3 and make's stderr to stdout. grep then reads from the previous command's stdout, removes the offending line and sends its stdout to stderr. Finally, fd 3 is returned to stdout.

glenn jackman
Is all that really necessary? What different from just doing the grep -v?
First of all, on my make anyway, that message goes to stderr, so at least you have to redirect stderr for grep to have any effect. Next, you wanted the rest of make's output untouched, so I didn't want to mix stderr with stdout. Lastly, it's a learning exercise for me too.
glenn jackman
+1  A: 

You can make "all" a PHONY target (if it isn't already) which has the real target as a prerequisite, and does something inconspicuous:

.PHONY: all

all: realTarget
    @echo > /dev/null
Beta
Rather than echo, you can probably just do @: for a no-op
William Pursell
@William Pursell: by golly, you're right. I never knew `:` was a shell no-op... or that I'd ever have a use for such a thing.
Beta
I like this sneaky approach. The warning goes away because `all` now has something to do, but what it does is nothing. Another option to `echo` is to make the action be `@true` which should print nothing and silently succeed.
RBerteig