Makefile:所有vs默认目标 [英] Makefile: all vs default targets

查看:97
本文介绍了Makefile:所有vs默认目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谈论GNU品牌,PHONY目标all:default:之间有什么区别.

Talking with respect to GNU make, what is the difference between PHONY targets all: and default:.

CC=g++
default: hello

hello: hello.cpp
     $(CC) -o hello hello.cpp

CC=g++
all: hello

hello: hello.cpp
     $(CC) -o hello hello.cpp

他们两个都做同样的工作.

Both of them do the same job.

推荐答案

如果愿意,可以将其命名为shirley.您提到的标签都没有任何特殊的语义.如果未将目标指定为命令行参数,则make的默认行为是运行Makefile中的第一个目标.如果您想覆盖此行为,请使用 .DEFAULT: 特殊目标.

You can call them shirley if you like; neither of the labels you mention has any special semantics. The default behavior of make is to run the first target in the Makefile if you don't specify a target as a command-line argument. If you like to override this behavior, there is the .DEFAULT: special target.

有一个约定,有一个名为all的目标可以构建所有内容,但这只是人类约定,不是特殊情况或就Make而言的要求.

There is a convention to have a target named all which builds everything, but this is just human convention, not a special case or a requirement as far as Make is concerned.

类似地,有一个(弱)约定来调用默认目标default,但是类似地,这只是一个人类标签(与all约定有些重叠并且可能会冲突).

Similarly, there is a (weak) convention to call the default target default, but similarly, this is just a human label (and somewhat overlaps and possibly conflicts with the all convention).

因此,以下Makefile会执行完全相同的操作:

So the following Makefile does exactly the same thing:

.PHONY: shirley all default
default: hello
all: hello
shirley: hello

hello: hello.cpp
# (Make already knows how to build an executable out of a .cpp file)

您可以忽略上面的任何或所有虚假目标,唯一的区别是,当人类(有效地)指的是make hello时,他们将无法说出make shirley.

You can omit any or all of the phony targets above, and the only difference will be that humans won't be able to say make shirley when they (effectively) mean make hello.

底线:构建Makefile,以便make能够执行合理的最终用户期望的操作,而无需读取过多的README文件或检查Makefile.通常是make all(即使不是默认设置,您也应该使用这个名称来满足人类的约定,即使它不是默认名称),但这显然取决于您的项目和用户的期望.

Bottom line: Construct your Makefile so that make does what a reasonable end-user expects without reading too much README files or inspecting the Makefile. Often that will be make all (and you should probably have a target with this name, just to satisfy human conventions, even if it's not the default) but this obviously depends on your project and your users' expectations.

不要叫我雪莉.

Don't call me Shirley.

这篇关于Makefile:所有vs默认目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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