Makefile 的编写指导
跟我一起写 Makefile
作者:陈皓
1 概述..................................................................................................................................................3
2 关于程序的编译和链接..................................................................................................................3
3 Makefile 介绍...................................................................................................................................4
3.1、Makefile 的规则.................................................................................................................4
3.2、一个示例............................................................................................................................5
3.3、make 是如何工作的..........................................................................................................6
3.4、makefile 中使用变量.........................................................................................................6
3.5、让 make 自动推导.............................................................................................................7
3.6、另类风格的 makefile.........................................................................................................8
3.7、清空目标文件的规则........................................................................................................8
4 Makefile 总述...................................................................................................................................9
4.1、Makefile 里有什么?........................................................................................................9
4.2、Makefile 的文件名.............................................................................................................9
4.3、引用其它的 Makefile........................................................................................................9
4.4、环境变量 MAKEFILES..................................................................................................10
4.5、make 的工作方式............................................................................................................10
5 书写规则........................................................................................................................................11
5.1、规则举例..........................................................................................................................11
5.2、规则的语法......................................................................................................................11
5.3、在规则中使用通配符......................................................................................................12
5.4、文件搜寻..........................................................................................................................12
5.5、伪目标..............................................................................................................................13
5.6、多目标..............................................................................................................................14
5.7、静态模式..........................................................................................................................15
5.8、自动生成依赖性..............................................................................................................16
6 书写命令........................................................................................................................................17
6.1、显示命令..........................................................................................................................17
6.2、命令执行..........................................................................................................................18
6.3、命令出错..........................................................................................................................18
6.4、嵌套执行 make................................................................................................................19
6.5、定义命令包......................................................................................................................20
7 使用变量........................................................................................................................................20
7.1、变量的基础......................................................................................................................21
7.2、变量中的变量..................................................................................................................21
7.3、变量高级用法..................................................................................................................23
7.4、追加变量值......................................................................................................................24
7.5、override 指示符...............................................................................................................25
7.6、多行变量..........................................................................................................................25
7.7、环境变量..........................................................................................................................26