使用批量编译更新可变数量目标的 makefile 规则

makefile rule to update a variable number of targets with a batch compile

我们有一个专有的编译器,可以获取多个输入文件并同时处理它们:

compiler a.in
# produces a.out

compiler a.in b.in c.in
# produces a.out b.out c.out

这样做的原因是可以节省大量的初始化时间。对于数千个文件,批处理版本比单独编译文件快几个数量级。我们还在文件上 运行 一个 post 处理器。

现在,我在 (GNU) makefile 中有这个,它没有利用批处理功能并一个接一个地更新文件。我想更新它以使用批编译:

.INTERMEDIATE: $(TMP)
$(TMP):  $(TMPDIR)/%.tmp: $(SRCDIR)/%.in |$(TMPDIR) 
        compiler $< -o $@

$(RESULT): $(RESDIR)/%.out: $(TMPDIR)/%.tmp $(SRCDIR)/%.in
        post-process $< -o $@

我将如何重写第一条规则以重新编译已使用单个命令修改的所有文件,也许使用 $??第二条规则需要保留在那里并保持不变。

如果你需要 GNU make 4.3+,那么你的生活就很简单了,你可以利用 grouped targets,像这样(注意 &:):

a.out b.out c.out &: a.in b.in c.in
        compiler $^

如果您不需要最新版本的 GNU make,您只能使用 "sentinel files",如下所示:

a.out b.out c.out : .sentinal ;

.sentinal: a.in b.in c.in
        compiler $^
        @touch $@

(确保在第一条规则中包含尾随分号...)