如何“制作”?如果没有指定目标,应用程序知道要构建的默认目标吗?
大多数 Linux 应用程序都是通过以下方式编译的:
make
make install clean
据我了解,make
命令将构建目标的名称作为参数。例如,install
通常是将一些文件复制到标准位置的目标,而 clean
是删除临时文件的目标。
但是,如果没有指定参数(例如我的示例中的第一个命令),make
将构建什么目标?
Most Linux apps are compiled with:
make
make install clean
As I understand it, the make
command takes names of build targets as arguments. So for example install
is usually a target that copies some files to standard locations, and clean
is a target that removes temporary files.
But what target will make
build if no arguments are specified (e.g. the first command in my example)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
默认情况下,它首先处理不以
.
开头的第一个目标,又名 默认目标;为此,它可能必须处理其他目标 - 具体来说,是第一个目标所依赖的目标。GNU Make 手册涵盖了所有这些内容,并且是一本令人惊讶的简单且信息丰富的读物。
By default, it begins by processing the first target that does not begin with a
.
aka the default goal; to do that, it may have to process other targets - specifically, ones the first target depends on.The GNU Make Manual covers all this stuff, and is a surprisingly easy and informative read.
为了节省其他人几秒钟的时间,并让他们不必阅读手册,这里是简短的答案。将其添加到 make 文件的顶部:
如果执行“make”且未指定目标,mytarget 现在将成为运行的目标。
如果您有较旧版本的 make (<= 3.80),则此操作将不起作用。如果是这种情况,那么您可以执行匿名提到的操作,只需将其添加到 make 文件的顶部
:
https://www.gnu.org/software/make /manual/html_node/How-Make-Works.html
To save others a few seconds, and to save them from having to read the manual, here's the short answer. Add this to the top of your make file:
mytarget will now be the target that is run if "make" is executed and no target is specified.
If you have an older version of make (<= 3.80), this won't work. If this is the case, then you can do what anon mentions, simply add this to the top of your make file:
References:
https://www.gnu.org/software/make/manual/html_node/How-Make-Works.html
GNU Make 还允许您使用名为
.DEFAULT_GOAL
的特殊变量来指定默认的 make 目标。您甚至可以在 Makefile 中间取消设置此变量,使文件中的下一个目标成为默认目标。参考:Gnu Make 手册 - 特殊变量
GNU Make also allows you to specify the default make target using a special variable called
.DEFAULT_GOAL
. You can even unset this variable in the middle of the Makefile, causing the next target in the file to become the default target.Ref: The Gnu Make manual - Special Variables
bmake 相当于 GNU Make 的
.DEFAULT_GOAL
是.MAIN
:请参阅 bmake(1) 手册页。
bmake's equivalent of GNU Make's
.DEFAULT_GOAL
is.MAIN
:See the bmake(1) manual page.
跑步
run