什么是“目标"? [英] What is a 'make target'?

查看:60
本文介绍了什么是“目标"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在构建源代码之前需要先创建make target?

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

更具体地说,什么是推荐答案

Makefile如下所示:

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) $< -o $@

...

这意味着,当您键入make all(简称只是键入make)时,它将确保二进制目标或文件是最新的.为此,需要确保mybinary比所有文件都新.如果不是,那么它将使用下一行指定的shell命令来构建mybinary.但是在执行此操作之前,首先要确保files.o等是最新的.这意味着它们必须比files.c和files.h更新.如果不是,那么它将使用下一行指定的shell命令来生成files.o.一旦所有* .o文件都是最新的,它就可以生成mybinary.一旦构建了二进制文件,就可以满足所有目标.

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

也可以使用通配符指定目标,例如,%.c表示要在外壳中调用*.c的内容.

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

某些目标是语音"目标,这意味着它们与任何实际文件都不对应. 全部"目标就是这种目标. 干净"目标(make clean)也是如此.等等.您实际上并不需要或不想构建一个名为"all"或"clean"的文件.有多种方法可以指定目标是虚假的.

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.

出现在Makefile中的第一个目标是只要您键入make就会被调用的目标.一种约定是将该目标命名为全部".因此make将与make all相同.

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.

这篇关于什么是“目标"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆