我正在使用 Make 来管理数据工作流(而不是构建软件项目)。我有这样的模式规则:
%.B: %.A
foo $^ > $@
%.C: %.B
bar $^ > $@
.SECONDARY:
现在,如果我注意到某些 .B
文件存在问题(例如 foo
中的错误),我会删除特定的 。 B
文件并再次执行 make
,但是当然相应的 .C
文件仍然存在并且比它们的 .A
文件更新, 所以什么也没有发生。
有没有一种很好的方法可以在缺少依赖项时强制重建 .C
文件?基本上我想我正在寻找一种方法来将 .B
文件提升到完整目标而不是次要或中间目标。
最佳答案
我从来没有遇到过这个问题,尽管我经常这样做。
也许那是因为我从不使用模式规则。
只需获取目标列表并使用static 模式规则。
也许像使用 $(wildcard)
获取源列表一样简单。
# List of sources
As := 1.A 2.A 3.A
${As}: ; touch $@
# List of targets
Bs := ${As:.A=.B}
Cs := ${Bs:.B=.C}
# Static pattern rules
${Bs}: %.B: %.A ; touch $@
${Cs}: %.C: %.B ; touch $@
.PHONY: all
all: ${Cs}
导致
$ make all --warn
touch 1.A
touch 1.B
touch 1.C
touch 2.A
touch 2.B
touch 2.C
touch 3.A
touch 3.B
touch 3.C
$ make all --warn
make: Nothing to be done for 'all'.
$ rm 2.B
$ make all --warn
touch 2.B
touch 2.C
工作是个好人。
关于makefile - GNU 使 : rebuild when intermediate files are missing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41811879/