Controlling verbosity of make

后端 未结 5 623
粉色の甜心
粉色の甜心 2021-02-04 11:10

I\'m using a makefile to compile a program made of many .c files, and any time make is invoked it only compiles those files modified after the last run

5条回答
  •  北海茫月
    2021-02-04 11:19

    I would create a function which takes a command to execute and decides whether to echo it.

    # 'cmd' takes two arguments:
    #   1. The actual command to execute.
    #   2. Optional message to print instead of echoing the command
    #      if executing without 'V' flag.
    ifdef V
    cmd = $1
    else
    cmd = @$(if $(value 2),echo -e "$2";)$1
    endif
    
    %.o: %.c $(h1) $(h3) %.h
        $(call cmd, \
            $(CC) $(CFLAGS) -c $< -o $(libDir)$@$(MATHOPTS), \
            Compiling $<)
    

    Then the result of plain make invocation will be something like:

    Compiling foo.c
    

    Whereas make V=1 will give:

    gcc -Wall -c foo.c -o foo.o ...
    

提交回复
热议问题