这是 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 文档)
目标:你可以找到像这样的目标install
,install-strip
变量:您可以在目标文档中阅读“这包括指定为变量值的目录prefix
和exec_prefix
”install
小智 6
最常用的(我认为)是all
、clean
、compile
、run
、install
、test
以及构建您正在构建的任何内容时可能需要的所有常见任务。
您可以在 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)