【问题标题】:Rules with two % marks in GNU makeGNU make 中带有两个 % 标记的规则
【发布时间】:2017-08-22 18:57:01
【问题描述】:

我正在尝试使用 GNU make 来自动化我的分析管道。我有一个脚本,它使用模式 data/sub001/sub001_input.txt 读取文件并写入 data/sub001/sub001_output.txt。我如何为每个主题编写与此模式匹配的规则?到目前为止,这是我的尝试:

# List of all the subjects
SUBJECTS ?= sub001 sub002 sub003

/data/%/%_output.txt : process.py data/%/%_input.txt
    python process.py $*

# for each $SUBJECT in $SUBJECTS
all : /data/$(SUBJECT)/$(SUBJECT)_output.txt
    @echo 'Data analysis complete!'

我希望all 目标调用:

python process.py sub001
python process.py sub002
python process.py sub003

如果相应的sub###_input.txt 文件发生更改,我希望重新处理单个主题,如果process.py 文件更改,我希望重新处理所有主题。

【问题讨论】:

    标签: makefile gnu-make


    【解决方案1】:

    您不能在模式规则中使用多个模式字符。

    你可以使用一个代表整个中间部分的图案,然后像这样去掉你想要的部分:

    /data/%_output.txt : process.py data/%_input.txt
            python process.py $(*F)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 1970-01-01
      • 1970-01-01
      • 2013-06-13
      • 1970-01-01
      • 2017-09-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多