bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -V, --verbose, as opposite of -s, --silent, --quiet


From: David Boyce
Subject: Re: -V, --verbose, as opposite of -s, --silent, --quiet
Date: Sat, 23 Oct 2021 13:28:00 -0700

BTW we use a slightly different and, I think, slightly improved version of what's shown there (see below). Improvements are:

1. Either the verbose or the concise output is shown, vs both in verbose mode as the original does.
2. It uses $(info ...) instead of echo which saves a fork/exec per recipe (note: this is safe only when used in the first recipe line).
3. It provides a default "MAKING $@" message as demonstrated in the example.
4. A special case is used to ensure the clean target is always verbose.

David

$ cat Makefile
.PHONY: all
all: hola

ifeq ($(V),)
  vb = $(info $(or $1,MAKING $(@F)))
  .SILENT:
endif

hola: hola.o
        $(call vb)
        $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)

%.o: %.c
        $(call vb,CC $(<F) -> $(@F))
        $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<

.PHONY: clean
clean: clean_recipe = $(RM) *.o hola
clean:
        @$(info $(clean_recipe))
        @$(clean_recipe)


$ make clean; make
rm -f *.o hola
CC hola.c -> hola.o
MAKING hola

$ make clean; make V=1
rm -f *.o hola
cc -c -o hola.o   hola.c
cc -o hola  hola.o

On Sat, Oct 23, 2021 at 6:06 AM Paul Smith <psmith@gnu.org> wrote:
On Sat, 2021-10-23 at 03:01 +0200, Alejandro Colomar (man-pages) wrote:
> I'd like a project to use '--silent' by default, to have readable
> output, and hide most of the full commands, which would be too
> noisy.
>
> So, ideally, I'd like to have 'MAKEFLAGS += --silent' in the
> Makefile.

Actually what you really want is the .SILENT special target.

https://www.gnu.org/software/make/manual/html_node/Special-Targets.html#index-_002eSILENT

That leads to this best-practice way to handle verbose output:

http://make.mad-scientist.net/managing-recipe-echoing/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]