如何设置Makefile目标取决于模式先决条件?

编程入门 行业动态 更新时间:2024-10-27 04:36:00
本文介绍了如何设置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 $@

请参阅

  • 通配符函数 $(wildcard ...)
  • 替代函数 $(foo:from=to)

更多推荐

如何设置Makefile目标取决于模式先决条件?

本文发布于:2023-11-04 10:27:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557680.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:先决条件   如何设置   目标   模式   Makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!