【问题标题】:Makefile - require all pattern matchesMakefile - 要求所有模式匹配
【发布时间】:2017-01-31 17:12:34
【问题描述】:

我正在尝试编写一个规则,该规则将在程序每个阶段的输出上调用我的检查脚本,如果该输出尚不存在,则使用我的%.output : %.input 规则生成该输出。

我试过check : $(wildcard stage[1234].output),但这会导致规则只需要那些匹配的输出文件已经存在

我可以定义一个像TARGETS = stage1.output stage2.output ... 这样的变量,但是有没有办法生成一个模式的所有可能匹配项然后需要它们?

【问题讨论】:

    标签: makefile wildcard


    【解决方案1】:

    要应用 %.output : %.input 规则,您需要两者

    1. 需要与模式%.output 匹配的中间体的目标
    2. 相应的%.input 文件 - 预先存在或构建它的规则

    如果您的stage*.input 文件已经存在,您可以使用:

    INPUTS=$(wildcard stage[1234].input)
    TARGETS=$(INPUTS:%.input=%.output)
    check: $(TARGETS)
    

    如果您的 stage*.input 文件不存在,但预计将根据类似的模式规则构建,请重新应用相同的原则。

    如果您的stage*.input 是通过更复杂的方式生成的,但假设它们的名称可以通过应用替换模式生成,则只需应用该模式即可。在您的示例中,它将类似于:

    L:= 1 2 3 4
    TARGETS=$(L:%=stage%.output)
    

    【讨论】:

      【解决方案2】:

      如果你想在 Make 中模拟 seq Unix 实用程序,这里是:

      seq = $(if $(word $1,$2),$2,$(call seq,$1,$2 $(words $2 1)))
      $(info seq(10)=$(call seq,10))
      
      stage_sount:=7
      stages:=$(patsubst %,stage%.output,$(call seq,$(stage_sount)))
      $(info stages=$(stages))
      all:
      

      输出:

      $ make
      seq(10)= 1 2 3 4 5 6 7 8 9 10
      stages=stage1.output stage2.output stage3.output stage4.output stage5.output stage6.output stage7.output
      make: Nothing to be done for 'all'.
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-14
        • 1970-01-01
        • 1970-01-01
        • 2017-05-14
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多