gpt4 book ai didi

makefile - 如何根据模式先决条件设置 Makefile 目标?

转载 作者:行者123 更新时间:2023-12-02 21:49:14 26 4
gpt4 key购买 nike

我在 makefile 中有一系列模式依赖项,最后它们应该放在一个文件中,例如: *.x -> *.y -> onefile.z

所以我制作了这样的文件:

$ touch a.x b.x

和规则:

%.y: %.x some-other-script
touch $@

onefile.z: %.y second-other-script
touch $@

这条规则不起作用:

$ make onefile.z
make: *** No rule to make target '%.y', needed by 'onefile.z'. Stop.

使用通配符:

%.y: %.x some-other-script
touch $@

z: $(wildcard *.y) second-other-script
touch $@

这也不起作用:它发现没有 *.y 文件,并继续使 onefile.z 跳过第一条规则。

$ make onefile.z
touch onefile.z

$ ls
a.x b.x onefile.z Makefile

我可能可以将两个规则合并为一个,但在实际应用中,步骤更多,有些是通过 HTTP 发出请求,需要很长时间,而且实际上不应该无缘无故地重复。

有没有办法建立这样的依赖关系?

最佳答案

onefile.z: %.y secondary-other-script 是常规规则,而不是模式规则或静态模式规则,因此 % 按字面解释。即使它是一个模式规则,make 应该如何推断词干应该匹配什么?

$(wildcard *.y) 告诉 make 查找所有与 *.y 匹配的文件,但当然还没有,所以它返回一个空字符串.

如果我正确理解了您的问题,以下内容应该有效:

xfiles := $(wildcard *.x)
yfiles := $(xfiles:.x=.y)

%.y: %.x some-other-script
touch $@

onefile.z: $(yfiles) second-other-script
touch $@

请参阅 Gnu Make 文档

关于makefile - 如何根据模式先决条件设置 Makefile 目标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39829344/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com