GNU Make

前言

GNU make 的编写(编程)非常类似于元编程(metaprogramming),整个MAKE 的运行分成2部分:

  • 生成规则(rule):
  • 执行规则(rule) :
什么是规则(rule)

规则是MAKE 的核心,驱动MAKE执行的pump。</p>
规则(rule) 范式<

Target: Prerequisites
  Recipes 

可以理解成
目标文件(target)的生成依赖于Prerequisites,并结合命令集(Recipes)生成。

  • Prerequisites 可以为空
  • Recipes 可以为空

简单例子

out.text:in.txt
        cp in.txt out.txt

如果out.txt 文件不存在,且in.txt文件存在,那么执行recipe(cp)
out.txt 文件生成依赖in.txt,这里通过cp来生成out.txt
如果out.txt 文件已经存在,且in.txt没有发生变化,那么cp的命令就不会再执行。

编译流程

compile-diagram.jpg

调试工具

  • remake
    非常强大,类似GDB,支持单步,断点。
  • gmd: 侵入式,效果未知,因为remake已经足够好

官方文档

GNU Make

Q&A

A phony target should not be a prerequisite of a real target file; if it is, its recipe will be run every time make goes to update that file. As long as a phony target is never a prerequisite of a real target, the phony target recipe will be executed only when the phony target is a specified goal (see Arguments to Specify the Goals)

  • 关于并行
    以下的例子无法并行,因为只有一条rule。
    用$(info) 来调试makefile
subdirs: for dir in $(SUBDIRS); do \ $(MAKE) -C $$dir; \ done
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容