makefile - GNU 使 : rebuild when intermediate files are missing

标签 makefile gnu-make

我正在使用 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/

相关文章:

python - easy_install 值错误 : bad marshal data (unknown type code)

macos - 在 OS X 上使用 Bash 命令生成文件 ifeq

c - gmake (Gnu) to make (Cygwin) - 验证我的实现 [只有 3 个语句]

makefile - 如何对 GNU Make 文件进行性能分析

makefile - cmake:如何添加仅执行shell脚本的add_custom_command?

c++ - FLTK-不显示Mac iOS图像

c++ - Makefile: 将 .o 放在不同目录中的规则

只能在 makefile 中使用一个目标文件

linux - 与 GNU Make 链接时参数列表太长

linux - 在执行之前制作 CMake 打印命令