如何设置Makefile目标取决于模式先决条件? [英] How to set a Makefile target depend on pattern prerequisites?

查看:127
本文介绍了如何设置Makefile目标取决于模式先决条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a chain of pattern dependencies in a makefile, and in the end they should come together in one file, e.g.: *.x -> *.y -> onefile.z

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

So I made the files like this:

$ 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跳过第一条规则.

This does not work either: it sees there are no *.y files and proceeds making onefile.z skipping the first rule.

$ make onefile.z
touch onefile.z

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

我可能可以将两个规则合并为一个,但是在实际的应用程序中,步骤更多,有些正在通过HTTP发出请求,并且花费了很多时间,实际上不应无故重复.

I probably could merge two rules into one, but in the real application, there are more steps, and some are making requests over HTTP and take much time, and in fact should not be repeated without a reason.

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

Is there a way to make such a dependency?

推荐答案

onefile.z: %.y second-other-script是常规规则,不是模式规则或静态模式规则,因此%会按字面意义进行解释.即使这是一个模式规则,也应该如何推断出茎应该匹配的东西?

onefile.z: %.y second-other-script is a regular rule, not a pattern rule or a static pattern rule, so the % is interpreted literally. Even if it were a pattern rule, how is make supposed to infer what the stem is supposed to match?

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

$(wildcard *.y) tells make to find all the files that match *.y, but of course there are none yet so it returns an empty string.

如果我正确理解了您的问题,那么以下内容应该起作用:

The following should work, if I've understood your question correctly:

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

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

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

请参阅

这篇关于如何设置Makefile目标取决于模式先决条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆