如何指定在没有固定起点的依赖图中从何处开始

发布于 2025-01-08 16:26:41 字数 1079 浏览 1 评论 0原文

我使用的工具链更像是一个网络。有很多替代起点,所有这些都会产生一个最终输出。

我通常使用 make 或 scons - 实际上,我更喜欢 scons,但我的团队非常喜欢 make。我对其他构建工具持开放态度。

例如,final_result 取决于倒数第二个

final_result: penultimate

倒数第二个可以通过以下几种不同方式中的任何一种来实现:

如果从文件 1 开始,则

penultimate: file1 ; rule1

如果从文件 2 开始,则

penultimate: file2 ; rule2

问:如何指定从文件 2 开始,而不是从文件 1 开始?

我想我可以使用命令行开关和 ifdeffing。但我更希望让 make 或 scons 弄清楚“嘿,周围有一个 file2,所以我应该使用rule2,而不是fil1/rule1”。部分原因是网络比这复杂得多……

更糟糕的是,有时一条路径的中间可能是另一条路径的开始。让我们看看:

A .s 生成一个 .diag

foo.diag: foo.s

但有时没有 .s,而我只有一个别人给我的已经构建的 .diag。

.diag 生成一个 .heximg 和一个 .hwresult

foo.hwresult: hwsim foo.heximg

foo.heximg: foo.diag

但有时我会直接得到一个 .img

等等。

我只想写出整体依赖关系图,然后说“好吧,现在这就是我得到的 - 现在你怎么样能得出最终结果吗?”

就我现在所拥有的,当我得到一个 foo.img 时,我被告知(在本例中是通过 make )“foo.s not dfound”。因为 make 想要一直返回到依赖关系图中来判断 foo.img 是否已过期,而我想说“假设 foo.img 是最新的,并继续处理依赖于 foo.img 的内容,而不是返回 foo.img 所依赖的东西。”

I'm using a tool chain that is more like a web. There are lotys of alternate start points, all resulting in a single final output.

I typically use make or scons - actually, I prefer scons, but my team highly prefers make. I'm open to other build tools.

E.g. final_result depends on penultimate

final_result: penultimate

penultimate may be made in any of several different ways:

If starting from file1, then

penultimate: file1 ; rule1

If starting from file2, then

penultimate: file2 ; rule2

Q: how do I specify to start with file2, not file1?

I suppose that I could use a command line switch and ifdeffing. But I would prefer to have make or scons figure out "Hey, there's a file2 around, so I should use rule2, not fil1/rule1". In part because the web is much more complex than this...

Worse, sometimes an intermediate on one path may be a start on another. Let's see:

A .s produces a .diag

foo.diag: foo.s

But sometimes there is no .s, and I just have a .diag that somebody else gave me already built.

A .diag produces a .heximg, and a .hwresult

foo.hwresult: hwsim foo.heximg

foo.heximg: foo.diag

But sometimes I am given a .img directly

Etc.

I just want to write the overall dependency graph, and say "OK, now here's what I have been given - now how do you get to the final result?"

With what I have now, when I am given, say, a foo.img, I get told (by make in this case) "foo.s not dfound". Because make wants to go all the way back in the dependency graph to tell if foo.img is out of date, whereas I want to say "assume foo.img is up to date, and work forwrads for stuff that depends on foo.img, instead of going back for stuff that foo.img depends on."

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东北女汉子 2025-01-15 16:26:41

您必须使用模式规则(隐式规则)来完成这一切。如果您指定显式规则,则 make 会认为存在硬依赖关系,并且如果不满足依赖关系的某些部分,make 将失败。

如果您使用隐式规则,那么 make 将认为这是构建目标的可能方法。如果这种方法不起作用(因为某些先决条件不存在并且 make 不知道如何构建它),那么 make 将尝试另一种方法。如果没有办法工作,并且目标已经存在,make 将只使用该目标而无需更新它。

另外你说“a .diag 生成 .heximg 和 .hwresult”,然后给出了一个我不认识的奇怪的 makefile 语法示例,但仅供参考,使用模式规则,您可以指定单个命令生成多个输出(您不能使用显式规则执行此操作):

%.heximg %.hwresult: %.diag

这是坏消息:在 GNU make 中定义隐式规则的唯一方法是文件名中是否存在公共“词干”。也就是说,您可以通过编写模式规则“%.heximg: %.diag”来编写一条将 foo.diag 转换为 foo.heximg 的隐式规则,因为它们有一个共同的词干“foo”,但是没有办法创建一个从“foo1”到“倒数第二”的编译的模式规则,因为它们不共享共同的词干。

You have to do it all with pattern rules (implicit rules). If you specify an explicit rule then make considers that a hard dependency and if some portion of the dependency is not met, make will fail.

If you use an implicit rule then make will consider that a POSSIBLE way to build the target. If that way doesn't work (because some prerequisite does not exist and make doesn't know how to build it) make will try another way. If no way works, and the target already exists, make will just use that target without having to update it.

Also you say "a .diag produces a .heximg and a .hwresult" then gave a strange example makefile syntax that I didn't recognize, but FYI with pattern rules you can specify that a single command generates multiple outputs (you can't do this with explicit rules):

%.heximg %.hwresult: %.diag

Here's the bad news: the only way to define an implicit rule in GNU make is if there is a common "stem" in the filename. That is, you can write an implicit rule that converts foo.diag to foo.heximg by writing a pattern rule "%.heximg: %.diag", because they have a common stem "foo", but there's no way to create a pattern rule for a compilation from "foo1" to "penultimate", because they don't share a common stem.

安静被遗忘 2025-01-15 16:26:41

我不确定,但可能您正在寻找 双冒号规则

双冒号规则是在目标名称后面使用 :: 而不是 : 编写的显式规则。当同一目标出现在多个规则中时,它们的处理方式与普通规则不同。

双冒号规则有些晦涩难懂,而且通常不是很有用;它们为用于更新目标的方法根据导致更新的必备文件而不同的情况提供了一种机制,但这种情况很少见。

I'm not sure, but probably you're looking for Double-Colon Rules:

Double-colon rules are explicit rules written with :: instead of : after the target names. They are handled differently from ordinary rules when the same target appears in more than one rule.

Double-colon rules are somewhat obscure and not often very useful; they provide a mechanism for cases in which the method used to update a target differs depending on which prerequisite files caused the update, and such cases are rare.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文