【问题标题】:Make not using Match Anything rule for prerequisite不使用任何匹配规则作为先决条件
【发布时间】:2017-12-20 16:39:58
【问题描述】:

所以,我有一个带有 2 个模式规则的 Makefile,其中一个是终端 Match-Anything;目标是about.html(例如):

vpath %.md $(SOURCE_DIR)
HEADER := assets/navbar.part

%.html : %.md $(HEADER)
        pandoc [...] $< -o $@

%::
        cp $(SOURCE_DIR)/$@ $@

如果我执行make assets/navbar.part,然后执行make about.html(例如),一切正常(navbar.part 使用匹配任何内容,而 about.html 使用第一条规则)。但是,如果我在没有navbar.part 的情况下尝试make about.htmlmake 会:

  1. 找到先决条件 about.md
  2. ??放弃履行 $(HEADER)
  3. 尝试使用 matchany 规则生成 about.html

我期待 make 会:

  1. 找到先决条件 about.md
  2. 使用 match-anything 规则创建先决条件 $(HEADER)
  3. 满足所有先决条件后,最后执行第一条规则

从阅读调试跟踪来看,Make 似乎从未真正尝试满足 $(HEADER) 先决条件:

Considering target file 'about.html'.
 File 'about.html' does not exist.
 Looking for an implicit rule for 'about.html'.
 Trying pattern rule with stem 'about'.
 Trying implicit prerequisite 'about.md'.
 Found prerequisite 'about.md' as VPATH '../website/about.md'
 Trying rule prerequisite 'assets/navbar.part'.
 Trying pattern rule with stem 'about.html'.
 Found an implicit rule for 'about.html'.
  Considering target file 'about.md'.
   Finished prerequisites of target file 'about.md'.
  No need to remake target 'about.md'; using VPATH name '../website/about.md'.
 Finished prerequisites of target file 'about.html'.
Must remake target 'about.html'.
cp -f ../website/about.html about.html

有什么想法吗?

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    翻完手册,发现section 10.8写着:

    对于列表中的每个模式规则:

    • 找到词干 s,它是 t 或 n 中与目标模式中的“%”匹配的非空部分。
    • 通过将 s 替换为“%”来计算先决条件名称;如果目标模式不包含斜线,则将 d 附加到每个先决条件名称的前面。
    • 测试所有先决条件是否存在或应该存在。 (如果文件名在 makefile 中作为目标或明确的先决条件被提及,那么我们说它应该存在。)

    因为$(HEADER)不符合ought to exist的定义:

    • 尝试规则时不存在文件
    • 不存在具有该显式目标的规则

    失败了;但是,如果我们尝试 make 特别是 $(HEADER),它会成功,然后尝试 make about.html 它会成功,因为此时 $(HEADER) 是一个现有文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      • 1970-01-01
      • 2017-05-20
      • 2011-07-18
      相关资源
      最近更新 更多