【问题标题】:How to include a makefile gracefully even if nonexistent即使不存在,如何优雅地包含生成文件
【发布时间】:2015-08-30 09:50:55
【问题描述】:

在 (GNU) make 中,当附加的 makefile 不存在时,如何在(主)makefile 的开头包含额外的 makefile(可能会预先设置一些变量)而不会出现中断错误消息?

我在makefile的顶部尝试过

include *.make

为了覆盖默认值

main ?= main.md
DEPS ?= template.tpl

但是,我确实收到了错误:

Makefile:4: *.make: No such file or directory

可能是因为在 makefile 的开头只允许定义,而不是命令。

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    使用sinclude or equivalent -include (silent include) directive

    $ cat GNUmakefile
    sinclude *.make
    
    all:
            echo foo
    
    $ ls *.make
    ls: *.make: No such file or directory
    $ make -f GNUmakefile
    echo foo
    foo
    

    【讨论】:

    • 完美运行。谢谢。
    【解决方案2】:

    只需使用wildcard 函数,如果没有文件匹配,该函数将扩展为空字符串:

    include $(wildcard *.make)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多