Flo*_*ues 7

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

目标

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

test-debug:
    $(build_dir)/debug/bin
Run Code Online (Sandbox Code Playgroud)

变量

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

src_dir = $(CURDIR)/src
build_dir = $(CURDIR)/build
Run Code Online (Sandbox Code Playgroud)

参考:

Makefile 风格指南(基于 GNU Makefile 文档)

GNU Makefile 标准目标

  • 目标:你可以找到像这样的目标installinstall-strip

  • 变量:您可以在目标文档中阅读“这包括指定为变量值的目录prefixexec_prefixinstall

  • 虽然这最接近我正在寻找的答案,但我不确定这有多正确。这似乎是关于这个主题的唯一且非常简短的资源。也许答案是没有通用的约定。查看标准目标名称文档(上面链接),您会发现“install-strip”,但也找到“installcheck”、“mostlyclean”之类的文件...不过,感谢您提供的信息。在接受答案之前我会稍等一下。 (3认同)

小智 6

最常用的(我认为)是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)
Run Code Online (Sandbox Code Playgroud)

并且,为了使这种情况按预期发生,我必须插入依赖项,例如:

all: run

run: link
    # Instructions for run

link: lib
    # Instructions for link

lib: compile
    # Instructions for make the lib

compile:
    #Instructions for compilation



 
Run Code Online (Sandbox Code Playgroud)