“全部”是什么意思?在 makefile 中代表什么?

发布于 2024-08-27 06:08:53 字数 73 浏览 6 评论 0原文

我阅读了一些有关 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 技术交流群。

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

发布评论

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

评论(4

╰ゝ天使的微笑 2024-09-03 06:08:53

正如 Makefile 所理解的那样,构建由许多目标组成。例如,要构建项目,您可能需要

  1. 从 file1.c 中构建 file1.o
  2. 从 file2.c 中构建
  3. file2.o 从 file3.c 中构建
  4. file3.o 从 file1.o 和 file3.o 中
  5. 构建可执行文件 1构建可执行文件 2 out of file2.o

如果您使用 makefile 实现了此工作流程,则可以单独创建每个目标。例如,如果您编写,

make file1.o

它只会在必要时构建该文件。

all 的名称不固定。这只是一个约定俗成的名字; all 目标表示如果您调用它,make 将构建完成构建所需的所有内容。这通常是一个虚拟目标,它不会创建任何文件,而仅依赖于其他文件。对于上面的示例,构建所需的全部内容就是构建可执行文件,其他文件作为依赖项引入。所以在 makefile 中它看起来像这样:

all: executable1 executable2

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

  1. Build file1.o out of file1.c
  2. Build file2.o out of file2.c
  3. Build file3.o out of file3.c
  4. Build executable1 out of file1.o and file3.o
  5. Build executable2 out of file2.o

If you implemented this workflow with makefile, you could make each of the targets separately. For example, if you wrote

make file1.o

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: executable1 executable2

all target is usually the first in the makefile, since if you just write make in command line, without specifying the target, it will build the first target. And you expect it to be all.

all is usually also a .PHONY target. Learn more here.

无人接听 2024-09-03 06:08:53

GNU Make 手册在其 标准目标列表

如果 Makefile 的作者遵循该约定,那么目标 all 应该:

  1. 编译整个程序,但不构建文档。
  2. 成为默认目标。就像运行 make 应该与 make all 一样。

要实现 1 all 通常定义为 .PHONY 目标,该目标取决于构成整个程序的可执行文件:

.PHONY : all
all : executable

要实现 2 all > 应该是 make 文件中定义的第一个目标,或者指定为默认目标:

.DEFAULT_GOAL := all

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:

  1. Compile the entire program, but not build documentation.
  2. Be the the default target. As in running just make should do the same as make all.

To achieve 1 all is typically defined as a .PHONY target that depends on the executable(s) that form the entire program:

.PHONY : all
all : executable

To achieve 2 all should either be the first target defined in the make file or be assigned as the default goal:

.DEFAULT_GOAL := all
比忠 2024-09-03 06:08:53

不确定它代表什么特别的东西。这只是您提供“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'.

西瑶 2024-09-03 06:08:53

目标“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.

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