【问题标题】:How to detect if the makefile `--silent/--quiet` command line option was set?如何检测是否设置了 makefile `--silent/--quiet` 命令行选项?
【发布时间】:2019-10-13 19:48:15
【问题描述】:

如何检测是否设置了makefile --silent / --quiet 命令行选项?

相关问题:

  1. how to detect if --quiet option is specified with rake

【问题讨论】:

    标签: makefile


    【解决方案1】:

    我认为你需要:

    $(findstring s,$(word 1, $(MAKEFLAGS)))
    

    因为 MAKEFLAGS 也有很长的选项,例如:

    MAKEFLAGS=s -j80 --jobserver-auth=4,6
    

    所以,IOW:

     # Set SILENT to 's' if --quiet/-s set, otherwise ''.
     SILENT := $(findstring s,$(word 1, $(MAKEFLAGS)))
    

    【讨论】:

      【解决方案2】:

      如果您调用 make --quiet--silent,则变量 {MAKEFLAGS} 仅设置为 @987654328 @。如果您添加其他选项,如 --ignore-errors--keep-going,变量 {MAKEFLAGS} 将设置为 iks 。然后,你可以用这个来捕捉它:

      ECHOCMD:=/bin/echo -e
      SHELL := /bin/bash
      
      all:
          printf 'Calling with "%s" %s\n' "${MAKECMDGOALS}" "${MAKEFLAGS}";
      
          if [[ "ws" == "w$(findstring s,${MAKEFLAGS})" ]]; then \
              printf '--silent option was set\n'; \
          fi
      

      参考资料:

      1. Recursive make: correct way to insert `$(MAKEFLAGS)`
      2. How to set MAKEFLAGS from Makefile, in order to remove default implicit-rules
      3. Remove target from MAKECMDGOALS?
      4. https://www.gnu.org/software/autoconf/manual/autoconf-2.61/html_node/The-Make-Macro-MAKEFLAGS.html

      【讨论】:

        猜你喜欢
        • 2021-09-21
        • 1970-01-01
        • 2015-04-27
        • 2012-07-14
        • 2016-10-27
        • 1970-01-01
        • 1970-01-01
        • 2020-07-10
        • 2011-06-27
        相关资源
        最近更新 更多