Suppress “nothing to be done for 'all' ”

2020-08-09 08:09发布

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.

4条回答
做自己的国王
2楼-- · 2020-08-09 08:21

I would like to improve on the previous solution, just to make it a little bit more efficient...:)

.PHONY: all
all: realTarget
        @:

@true would also work but is a little slower than @: (I've done some performance tests). In any case both are quite faster than "echo > /dev/null"...

查看更多
Animai°情兽
3楼-- · 2020-08-09 08:30

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
查看更多
▲ chillily
4楼-- · 2020-08-09 08:32

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.

查看更多
闹够了就滚
5楼-- · 2020-08-09 08:39

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.

查看更多
登录 后发表回答