【问题标题】:No rule to make (phony) target没有制定(虚假)目标的规则
【发布时间】:2021-03-11 21:14:47
【问题描述】:

我正在尝试为虚假目标 foo-test 创建一个模式规则,它应该构建一个实际文件 foo-test1

%-test: %-test1

%-test1:
    touch $@

当我拨打make --just-print foo-test 时,我会收到No rule to make target: foo-test

但我希望 make 看到 foo-test 依赖于 foo-test1 并应用第二条规则来制作 foo-test1。如何实现这种行为? (我尝试将%-test%-test1 声明为.PHONY;它没有帮助)。

【问题讨论】:

    标签: makefile


    【解决方案1】:

    这个:

    %-test: %-test1
    

    不定义模式规则。它删除一个模式规则。见https://www.gnu.org/software/make/manual/html_node/Canceling-Rules.html

    如果你想制定一个模式规则,你必须给它一个配方。像这样就足够了:

    %-test: %-test1 ;
    

    【讨论】:

    • 啊 :) 但现在当我运行它时,它会运行 touch foo-test1 然后 rm foo-test1;如何阻止它删除?
    • 这是一个中间文件。请参阅gnu.org/software/make/manual/html_node/Chained-Rules.html 中的讨论
    • 啊哈 - .SECONDARY: 没有目标告诉 make 永远不要扔掉任何东西 :)
    猜你喜欢
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2011-09-08
    • 1970-01-01
    • 2017-10-13
    相关资源
    最近更新 更多