什么是“make 目标”?

发布于 2024-08-21 05:34:11 字数 244 浏览 2 评论 0 原文

为什么我需要先创建一个 make 目标,然后才能构建我的源代码?

更具体地说,什么是 准确地制定目标

Why do I need to make a make target before being able to build my source code?

More specifically, what is make target exactly?

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

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

发布评论

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

评论(5

抚笙 2024-08-28 05:34:11

Makefile 看起来像这样:

all: mybinary

mybinary: files.o it.o depends.o on.o
[tab]$(CC) $(CFLAGS) files.o it.o depends.o on.o -o mybinary

files.o: files.c files.h
[tab]$(CC) -c $(CPPFLAGS) $(CFLAGS) 
lt; -o $@

...

这意味着,当您输入 make all (简写方式就是输入 make)时,它将确保 mybinary 目标或文件符合日期。为此,需要确保 mybinary 比所有 files.o it.o dependent.o 和 on.o 更新。如果没有,则它使用下一行指定的 shell 命令来构建 mybinary。但在此之前,它首先确保 files.o 等文件是最新的。这意味着它们必须比 files.c 和 files.h 更新。如果没有,那么它使用下一行指定的 shell 命令来构建 files.o。一旦所有 *.o 文件都是最新的,它就可以构建 mybinary。一旦构建了我的二进制文件,所有目标就得到满足。

目标通常只是文件。块的格式为:

target: list of dependency files
[tab]shell commands to build target if it's older than any of its dependencies
[tab]more shell commands
[tab]still more

还可以使用通配符指定目标,例如 %.c 表示您在 shell 中调用 *.c 的内容。

有些目标是“虚假”目标,这意味着它们不对应于任何真实文件。 “全部”目标就是这样的。 “clean”目标(make clean)也是如此。等等。您实际上并不需要或想要构建一个名为“all”或“c​​lean”的文件。有多种方法可以指定目标是虚假的。

如果您只需键入 make,Makefile 中出现的第一个目标就是将被调用的目标。一种约定是将这个目标命名为“all”。因此,make 将与 make all 相同。

Makefiles look like this:

all: mybinary

mybinary: files.o it.o depends.o on.o
[tab]$(CC) $(CFLAGS) files.o it.o depends.o on.o -o mybinary

files.o: files.c files.h
[tab]$(CC) -c $(CPPFLAGS) $(CFLAGS) 
lt; -o $@

...

This means, when you type make all (the shorthand is just to type make), it will make sure that the mybinary target or file is up to date. To do that, it needs to make sure that mybinary is newer than all of files.o it.o depends.o and on.o. If not, then it uses the shell commands specified on the next line to build mybinary. But before doing that, it first makes sure that files.o and so on are up to date. This means they have to be newer than files.c and files.h. If not, then it uses the shell commands specified on the next line to build files.o. Once all the *.o files are up to date, it can build mybinary. Once mybinary is built, the all target is satisfied.

Targets are usually just files. The format of a block is:

target: list of dependency files
[tab]shell commands to build target if it's older than any of its dependencies
[tab]more shell commands
[tab]still more

Targets can also be specified using wildcards, for instance %.c means what in the shell you'd call *.c.

Some targets are "phony" targets meaning they don't correspond to any real file. The "all" target is of this sort. So too is the "clean" target (make clean). And so on. You don't really need or want to build a file called "all" or "clean". There are various ways to specify that a target is phony.

The first target to appear in the Makefile is the one that will be invoked if you simply type make. One convention is to name this target "all". So then make will be the same as make all.

梦回梦里 2024-08-28 05:34:11

“make target”基本上是您想要重建的文件。

Make 无法预测您想要构建什么,因此您必须隐式或显式地告诉它应该构建什么。通常,文件中的第一个目标是诸如“all”之类的名称,如果您在没有任何显式目标的情况下运行“make”,它将构建 makefile 中列出的第一个目标。然而,有些 makefile 没有指定任何目标;那么您必须在命令行上指定一个。或者,如果您不想构建默认目标,则必须指定您想要构建的目标。

用 GNU make 的术语来说,目标也可以是“假的”。也就是说,它是一个不存在的名称,并且规则不会创建它,但它(虚假目标)依赖于许多具有与其关联的规则的其他文件。事实上,“all”目标通常是一个虚假目标 - 大多数目录中没有名为“all”的文件。

A 'make target' is basically a file that you want rebuilt.

Make can't divine what you want built, so you have to tell it, implicitly or explicitly, what it should build. Often, the first target in the file is a name such as 'all' and if you run 'make' without any explicit target, it will build the first target listed in the makefile. However, some makefiles do not specify any target; then you must specify one on the command line. Or, if you don't want the default target built, then you must specify the target that you do want built.

A target can also be 'phony', in the terms of GNU make. That is, it is a name that does not exist, and the rules do not create it, but it (the phony target) depends on a number of other files that do have rules associated with them. Indeed, the 'all' target is usually a phony target - there isn't a file called 'all' in most directories.

清音悠歌 2024-08-28 05:34:11

makefile 通常包含用于制作程序、安装程序、随后清理以及其他操作的代码。

所以target这个词可以是各种关键字,例如allinstallclean等。

这是一种方式说做某事make all 意味着做所有事情

A makefile will usually include code to make your program, install your program, clean up afterward, and other things.

so the word target could be various keywords, such as all, install, clean, etc.

It's a way of saying make something. make all implies do everything

私藏温柔 2024-08-28 05:34:11

make 是一种常见的开发工具,它检查源代码文件和由它们生成的目标代码之间的文件日期,并编译源代码较新的文件。它通过使用一个称为 makefile 的文件来完成此操作,该文件列出了需要比较的文件。

标准语法是 make /f makefile myprog.exe

这表示使用 makefile 中的文件列表构建 myprog.exe。 makefile 默认为 makefile.mak,因此如果您使用该名称,则不必在命令行上指定它。

这里的myprog.exe称为目标。一个技巧是您可以在 makefile 中放入一个不存在的文件的构建指令列表。如果您随后说构建该目标,它将运行这些命令。通常,您会看到类似 make clean 的内容,它已删除临时文件。

make is a common development tool, which checks file dates between source code files and the object code produced from them, and compiles the one where the source is newer. It does this by use a file, called a makefile, which list the files that need to be compared.

The standard syntax is make /f makefile myprog.exe

That says to build myprog.exe using the file list in makefile. The makefile defaults to makefile.mak so if you use that name, you don't have to specify it on the command line.

myprog.exe here is called the target. One trick is that you could put in the makefile a list of build instructions for a non-existant file. If you then say to build that target, it will run those command. Often, you'll see something like make clean, which has temporary file deleted.

梦毁影碎の 2024-08-28 05:34:11

在现实生活中,当你想要实现某件事时,你通常称其为目标或目标。为了实现该目标,通常您需要满足一些先决条件。

在计算机领域,目标具有类似的含义。它不一定限于构建软件。但在构建软件时经常会看到这种情况。

一个软件通常由很多组件组成。这些组件通常具有相互依赖性。假设完全构建一个软件是您的最终目标。为了实现这一点,您需要根据组件的依赖关系来构建组件。您可以想象将组件组织成层次结构,就像树一样。而每个节点都是一个以根为最终目标的中间目标,通常命名为all。您可以为任何目标节点(中间节点或根节点)调用 make。然后需要完成其所有子目标才能使目标节点完成。

对于每个目标,您需要指定完成该目标所需采取的操作。这些操作称为命令或规则。

一些引用自此处

目标将任务按特定顺序组合在一起并允许构建
过程被分解成更小的单元。

In real life, when you want to achieve something, you usually call that something a goal, or target. To reach that target, usually you need to achieve some pre-requisites.

In computer domain, target has a similar meaning. It is not necessarily limited to build software. But it is often seen when building software.

A piece of software is usually composed of a lot of components. And these components usually have inter-dependencies. Let's say to completely build a software is your ultimate target. And to achieve that, you need to build components with respect to their dependencies. You can image organizing the components into a hierarchy, like a tree. And each node is a intermediate target with the root as the ultimate target, usually it is named all. You can invoke make for any of the target nodes, intermediate or root. And then all its sub-targets need to be completed to make the target node complete.

For each target, you need to specify the actions to take to complete that target. These actions are called commands or rules.

Some quote from here:

Targets group tasks together in a particular order and allow the build
process to be factored into smaller units.

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