“全部”是什么意思?在 makefile 中代表什么?
我阅读了一些有关 Makefile 的教程,但对我来说仍然不清楚目标“all”代表什么以及它的作用。
有什么想法吗?
I read some tutorials concerning Makefiles but for me it is still unclear for what the target "all" stands for and what it does.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正如 Makefile 所理解的那样,构建由许多目标组成。例如,要构建项目,您可能需要
如果您使用 makefile 实现了此工作流程,则可以单独创建每个目标。例如,如果您编写,
它只会在必要时构建该文件。
all
的名称不固定。这只是一个约定俗成的名字;all
目标表示如果您调用它,make 将构建完成构建所需的所有内容。这通常是一个虚拟目标,它不会创建任何文件,而仅依赖于其他文件。对于上面的示例,构建所需的全部内容就是构建可执行文件,其他文件作为依赖项引入。所以在 makefile 中它看起来像这样:all
target 通常是 makefile 中的第一个,因为如果你只是在命令行中编写make
,而不指定目标,它会建立第一个目标。您希望它是全部
。all
通常也是.PHONY
目标。了解更多信息此处。A build, as Makefile understands it, consists of a lot of targets. For example, to build a project you might need
If you implemented this workflow with makefile, you could make each of the targets separately. For example, if you wrote
it would only build that file, if necessary.
The name of
all
is not fixed. It's just a conventional name;all
target denotes that if you invoke it, make will build all what's needed to make a complete build. This is usually a dummy target, which doesn't create any files, but merely depends on the other files. For the example above, building all necessary is building executables, the other files being pulled in as dependencies. So in the makefile it looks like this:all
target is usually the first in the makefile, since if you just writemake
in command line, without specifying the target, it will build the first target. And you expect it to beall
.all
is usually also a.PHONY
target. Learn more here.GNU Make 手册在其 标准目标列表。
如果 Makefile 的作者遵循该约定,那么目标
all
应该:make
应该与make all
一样。要实现 1
all
通常定义为.PHONY
目标,该目标取决于构成整个程序的可执行文件:要实现 2
all
> 应该是 make 文件中定义的第一个目标,或者指定为默认目标:The manual for GNU Make gives a clear definition for
all
in its list of standard targets.If the author of the Makefile is following that convention then the target
all
should:make
should do the same asmake all
.To achieve 1
all
is typically defined as a.PHONY
target that depends on the executable(s) that form the entire program:To achieve 2
all
should either be the first target defined in the make file or be assigned as the default goal:不确定它代表什么特别的东西。这只是您提供“all”规则的约定,通常它用于列出构建整个项目所需的所有子目标,因此名称为“all”。它唯一的特别之处在于,人们常常将其作为 makefile 中的第一个目标,这意味着仅键入“make”将执行与“make all”相同的操作。
Not sure it stands for anything special. It's just a convention that you supply an 'all' rule, and generally it's used to list all the sub-targets needed to build the entire project, hence the name 'all'. The only thing special about it is that often times people will put it in as the first target in the makefile, which means that just typing 'make' alone will do the same thing as 'make all'.
目标“all”是虚拟目标的一个示例 - 磁盘上没有任何内容称为“all”。这意味着当您执行“make all”时,make 始终认为它需要构建它,因此执行该目标的所有命令。这些命令通常是构建 makefile 知道的所有最终产品的命令,但它可以做任何事情。
虚拟目标的其他示例是“clean”和“install”,它们的工作方式相同。
如果您还没有阅读过,您应该阅读 GNU Make 手册,这也是一个很棒的教程。
The target "all" is an example of a dummy target - there is nothing on disk called "all". This means that when you do a "make all", make always thinks that it needs to build it, and so executes all the commands for that target. Those commands will typically be ones that build all the end-products that the makefile knows about, but it could do anything.
Other examples of dummy targets are "clean" and "install", and they work in the same way.
If you haven't read it yet, you should read the GNU Make Manual, which is also an excellent tutorial.