[make] - GNUmakefile, makefile, Makefile 区别及应该选择哪一个命名? - (推荐答案:Makefile)

 

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

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

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

 

Source

Chapter 3: Writing Makefiles:

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

Chapter 9.1 Arguments to Specify the Makefile

If you do not use the ‘-f’ or ‘--file’ flag, the default is to try GNUmakefile, makefile, and Makefile, in that order, and use the first of these three which exists or can be made (see Chapter 3 [Writing Makefiles], page 11).

 

Source #2: https://cloud.tencent.com/developer/ask/sof/109685604

 

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