makefile - 是否可以过滤静态模式规则中的先决条件?

标签 makefile gnu-make

我试图将 $(all_possible_inputs) 限制为 $(relevant_inputs)。 $(all_possible_inputs) 是来自其他包含的 makefile 的多个文件的串联。以下功能正确(perl 脚本知道如何忽略额外的输入),但如果单个输入更改,所有内容都会重建:

$(step2_outputs): $(data)/%.step2: $(routines)/step2.%.pl $(all_possible_inputs)
        perl $^ > $@

更新:过滤器必须匹配多个 *.step1 文件。如果step1产生了:

A.foo.step1
A.bar.step1
B.foo.step1
B.bar.step1
B.baz.step1

那么step2的规则应该展开为:

A.step2: routines/step2.A.pl A.foo.step1 A.bar.step1
B.step2: routines/step2.B.pl B.foo.step1 B.bar.step1 B.baz.step1

从逻辑上讲,这就是我想要的工作:

$(step2_outputs): $(data)/%.step2: $(routines)/step2.%.pl $(filter $(data)/%.*.step1,$(all_possible_inputs))
        perl $^ > $@

% 应该与静态模式规则主干匹配。 * 应该是一个通配符(我知道这是行不通的)。我认为问题在于过滤器重新调整了“%”的用途,因此过滤器表达式失败。我认为它可能可以通过二次扩展来解决,但我试过了,过滤器仍然返回空字符串:

更新:我根据 Beta 的好建议将示例切换为使用 $$*:

.SECONDEXPANSION:
$(step2_outputs): $(data)/%.step2: $(routines)/step2.%.pl $$(filter $(data)/$$*.%.step1,$(all_possible_inputs))
        perl $^ > $@

这是在 linux 环境中的 gnu make 3.81 上运行的。

最佳答案

你的第三种方法对我有用,但你可以试试这个:代替 %(在第一阶段扩展)使用 $$*

.SECONDEXPANSION:
$(step2_outputs): $(data)/%.step2: $(routines)/step2.%.pl $$(filter $(data)/$$*.step1,$(all_possible_inputs))
    perl $^ > $@

关于makefile - 是否可以过滤静态模式规则中的先决条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11238052/

相关文章:

linux-kernel - := or += when compiling Linux kernel modules?

makefile - 了解 kbuild 构建过程的工作原理

python - 在 Makefile 的内置 shell 函数中使用 make 变量

c++ - makefile中的多种编译模式

bash - 如何突出显示 make 输出中的警告和错误行?

makefile - GNU 制造商 : % doesn't match dotted filenames?

c++ - 无法在 make 文件中包含库

makefile - 有什么办法可以使命令回显

c - Makefile 问题 - 无法理解问题出在哪里

c++ - 在 C++ 项目中设置加密的单个文件