**
makefile学习笔记
**
前言
makefile学习过程中的随笔
一、include的使用
语法 include 文件路径
1、初始makefile
all:
@echo “begin page”
@echo “end page”
当在主目录中运行make或make all后,系统会找到文件中的make文件进行运行,默认名采用makefile,结果如下:
begin page
end page
2、采用include包含其他makefile文件
(1)实例1
makefile1文件如下:
all:
@echo “begin page”
make otherthing //指定makefile2中otherthing的内容进行输出
@echo "end page"
include ./otherfile/makefile2 //include的其他makefile文件
./otherfile目录下的makefile2文件:
otherthing:
@echo “here is other makefile”
运行makefile1的结果如下:
begin page
here is other makefile
end page
我们可以看到,makefile2的内容通过makefile1中的make otherfile语句进行了输出。
(2)实例2
makefile1文件如下:
all:
@echo “begin page”
@echo “$(val)"
@echo "end page"
include ./otherfile/makefile2
./otherfile目录下的makefile2文件:
val:= hello
otherthing:
@echo "here won't be display"
运行makefile1的结果如下:
begin page
hello
end page
与C等编程语言不同,makefile的include是放在代码末尾,这样也能被包括在内。