处理从单个输入生成的多个文件 [英] Processing multiple files generated from single input
问题描述
我有一个数据文件,该文件由脚本处理以产生多个输出文件.这些输出文件中的每一个都将被进一步处理.创建哪些文件取决于输入文件的内容,因此我无法明确列出它们.我不太清楚如何引用Makefile中生成的各种文件.
I have a data file that is processed by a script to produce multiple output files. Each of these output files is then processed further. Which files are created depends on the contents of the input file, so I can't list them explicitly. I can't quite figure out how to refer to the various files that are generated in a makefile.
目前,我有这样的事情:
Currently, I have something like this:
final.out: *.out2
merge_files final.out $(sort $^)
%.out2: %.out1
convert_files $?
%.out1: data.in
extract_data data.in
此操作失败,并显示No rule to make target '*.out2', needed by 'final.out'
.我认为这是因为.out2文件尚不存在,因此通配符表达式未按我希望的方式替换.我尝试使用通配符函数,但是失败,因为先决条件列表最终为空.
This fails with No rule to make target '*.out2', needed by 'final.out'
. I assume this is because the .out2 files don't exist yet and therefore the wildcard expression isn't replaced the way I would like it to. I have tried to use the wildcard function but that fails because the list of prerequisites ends up being empty.
任何指针将不胜感激.
推荐答案
编辑:修复了第二遍中的先决条件列表.
EDIT: fixed the list of prerequisites in second pass.
您显然无法在运行extract_data
命令之前计算中间文件的列表.在这种情况下,一种解决方案是运行make两次.第一次生成*.out1
文件,第二次完成作业.您可以使用一个空的虚拟文件来标记是否
extract_data
命令应再次运行还是不运行:
You apparently cannot compute the list of intermediate files before running the extract_data
command. In this case a solution consists in running make twice. One first time to generate the *.out1
files and a second time to finish the job. You can use an empty dummy file to mark whether the
extract_data
command shall be run again or not:
ifeq ($(FIRST_PASS_DONE),)
final.out: .dummy
$(MAKE) FIRST_PASS_DONE=yes
.dummy: data.in
extract_data $<
else
OUT1 := $(wildcard *.out1)
OUT2 := $(patsubst %.out1,%.out2,$(OUT1))
final.out: $(OUT2)
merge_files $@ $(sort $^)
%.out2: %.out1
convert_files $?
endif
这篇关于处理从单个输入生成的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!