gpt4 book ai didi

makefile - Makefile 中的双冒号规则是什么?

转载 作者:行者123 更新时间:2023-12-03 08:57:56 24 4
gpt4 key购买 nike

栏目 4.13 of the GNU Make manual描述了所谓的双冒号规则:

Double-colon rules are 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.

When a target appears in multiple rules, all the rules must be the same type: all ordinary, or all double-colon. If they are double-colon, each of them is independent of the others. Each double-colon rule's commands are executed if the target is older than any prerequisites of that rule. If there are no prerequisites for that rule, its commands are always executed (even if the target already exists). This can result in executing none, any, or all of the double-colon rules.

Double-colon rules with the same target are in fact completely separate from one another. Each double-colon rule is processed individually, just as rules with different targets are processed.

The double-colon rules for a target are executed in the order they appear in the makefile. However, the cases where double-colon rules really make sense are those where the order of executing the commands would not matter.

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.

Each double-colon rule should specify commands; if it does not, an implicit rule will be used if one applies. See section Using Implicit Rules.


我有点单独理解本节每个句子的含义,但我仍然不清楚双冒号规则的用途。至于罕见,我还没有看到任何一个Makefile不是以开头的开源项目
all::
因此: Makefile 中双冒号规则的预期目的是什么?

最佳答案

每个::规则都是独立处理的,因此可以更简单。例如,单一规则:

libxxx.a : sub1.o sub2.o
ar rv libxxx.a sub1.o
ar rv libxxx.a sub2.o

可以用两个更简单的规则替换:
libxxx.a :: sub1.o
ar rv libxxx.a sub1.o

libxxx.a :: sub2.o
ar rv libxxx.a sub2.o

与一些复杂的规则相比,像 AutoMake 这样的实用程序更容易吐出许多简单的规则。

发布了一个包含更多示例的好答案,然后取下,然后在这里找到:

https://web.archive.org/web/20180122002430/http://owen.sj.ca.us/~rk/howto/slides/make/slides/makecolon.html

感谢 R.K. Owen 写了它,Edward Minnix 再次找到它!

关于makefile - Makefile 中的双冒号规则是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7891097/

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