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

问题描述 投票:7回答:2

我在这里找不到任何答案:

http://www.gnu.org/software/make/manual/html_node/Makefile-Conventions.html#Makefile-Conventions

makefile naming-conventions gnu-make
2个回答
1
投票

最常用(我认为)是全部,清理,编译,运行,安装,测试,以及您可能要构建的所有常见任务。

您可以在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

0
投票

[基于GNU文档,有一个简单但功能强大的Makefile样式指南here

这里是对目标和变量的描述:

目标

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

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

如果我们检查GNU documentation,他们会建议install-format类型的目标,例如install-strip

变量

不是特殊的变量,也不是从环境继承的变量,应小写。单词之间应使用下划线符号“ _”分隔。例如:

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

如果检查GNU documentation,请在install目标文档中阅读:“这包括指定为变量prefixexec_prefix的值的目录”

© www.soinside.com 2019 - 2024. All rights reserved.