3.2 What Name to Give Your Makefle

By default, when make looks for the makefle, it tries the following names, in order: GNUmakefile, makefile and Makefile.

Normally you should call your makefle either makefile or Makefile. (We recommend Makefile because it appears prominently near the beginning of a directory listing, right near other important fles such as README.) The frst name checked, GNUmakefile, is not recommended for most makefles. You should use this name if you have a makefle that is Chapter 3: Writing Makefles 13 specifc to GNU make, and will not be understood by other versions of make. Other make programs look for makefile and Makefile, but not GNUmakefile.

If make fnds none of these names, it does not use any makefle. Then you must specify a goal with a command argument, and make will attempt to fgure out how to remake it using only its built-in implicit rules. See Chapter 10 [Using Implicit Rules], page 121.

If you want to use a nonstandard name for your makefle, you can specify the makefle name with the ‘-f’ or ‘--file’ option. The arguments ‘-f name’ or ‘--file=name’ tell make to read the fle name as the makefle.

If you use more than one ‘-f’ or ‘--file’ option, you can specify several makefles. All the makefles are efectively concatenated in the order specifed. The default makefle names GNUmakefile, makefile and Makefile are not checked automatically if you specify ‘-f’ or ‘--file’.

 

在使用 make 命令时,GNUmakefile 和 Makefile 文件之间的主要区别在于文件的命名和优先级。 以下是详细的解释: 当你运行 make 命令时,make 会按照以下顺序查找文件:

AN1:这意味着如果同时存在 GNUmakefile 和 Makefile,make 将使用 GNUmakefile,而忽略 Makefile。通常用于一般的 Makefile 项目,适用于大多数情况

AN2:  您可以使用它们中的任何一种,但传统上Makefile优于makefile。如果Makefilemakefile同时位于同一个目录中,并且只需键入make,那么makefile就会被执行,Makefile就会被忽略。

https://cloud.tencent.com/developer/ask/sof/109685604

posted on 2025-11-28 18:29  ENGINEER-F  阅读(3)  评论(0)    收藏  举报