是否有 makefile 目标和变量的命名约定

Is there a naming convention for makefile targets and variables

我在 GNU Makefile Conventions 中找不到任何内容。

最常用的(我认为)是 allcleancompileruninstalltest 和您可能需要构建的所有常见任务。

您可以在 Linux、Vim 等大型项目中研究 makefile,但如果您想将标准纳入您的项目,您也需要使用 Autotools。

对于小型项目,我通常会根据上下文使用有意义的名称,所以我可以这样做:

$make compile   (to compile)
$make lib       (to create the libraries)
$make link      (to link the objects into the executable)
$make run       (to run the program)
$make all       (to make all of them at once)

并且,为了让这一切按预期发生,我必须插入如下依赖项:

all: run

run: link
    # Instructions for run

link: lib
    # Instructions for link

lib: compile
    # Instructions for make the lib

compile:
    #Instructions for compilation



 

这是 GNU Makefile 文档遵循的隐式命名约定:

目标

目标名称应使用小写字母。单词用连字符 - 分隔或不分隔。例如:

test-debug:
    $(build_dir)/debug/bin

testdebug:
    $(build_dir)/debug/bin

变量

不是特殊制作或从环境中继承的变量应该是小写的。单词应该用下划线符号 _ 分隔。例如:

src_dir = $(CURDIR)/src
build_dir = $(CURDIR)/build

参考文献:

Makefile style guide(基于 GNU Makefile 文档)

GNU Makefile Standard Targets

  • 目标: 您可以找到 installinstall-stripinstallcheck

    等目标
  • 变量: 你可以阅读“这包括指定为变量值 prefixexec_prefix 的目录” install 目标文档