ignoring at (@) symbol in makefiles

后端 未结 6 1114
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 09:20

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 wha

相关标签:
6条回答
  • 2020-12-15 09:23

    To make things even more configurable, allow a make switch to enable verbosity. It default normal to silent mode. Only with the -e VERBOSE=1 mode it will be verbose of course:

    ##
    # Verbose ENABLE/DISABLE
    # invoke make -e VERBOSE=1
    ##
    V=@
    ifeq ($(VERBOSE),1)
        V=
    endif   
    
    all:
        $(V)echo test
        echo test
    

    Thank you for this topic it was of great help for my work.

    0 讨论(0)
  • 2020-12-15 09:27

    Take out all the @ and add this line to the Makefile:

    .SILENT :

    When you want to debug, comment out the .SILENT line.

    0 讨论(0)
  • 2020-12-15 09:27

    Disabling the @ in front of a make script is useful, however sometimes it is too noisy when the make script is very long. Another debugging technique is to turn on a shell feature that echoes commands just before they execute. This obviates a need to manipulate @ or .SILENT. Consider an example Makefile:

    test:
        @blah; \
        : ... lots of script commands ... ; \
        : Start debugging here ; \
        set -x; \
        : ... script segment to debug ... ; \
        set +x; \
        : Stop debugging here ; \
        : ... lots of script commands ... ;
    

    This is likely non-portable since it depends on features present in the shell that executes the script, but portability is not really that important for debugging (if it works for you).

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-15 09:33

    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!

    0 讨论(0)
  • 2020-12-15 09:41

    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).

    0 讨论(0)
提交回复
热议问题