基本介绍的话可以看这个链接:
https://seisman.github.io/how-to-write-makefile/introduction.html
这里就主要总结一下使用过程:
这个是基本的目录结构:
makefile里面的内容:
OBJ = main.o g_a.o g_b.o
target : $(OBJ)
gcc -o target $(OBJ)
$(OBJ) : main.c g_a.c g_b.c
gcc -c main.c
gcc -c g_a.c
gcc -c g_b.c
#.PHONY : cleanall cleana\
#cleanb cleanmain
cleanall : cleana cleanb cleanmain
rm target
cleana :
rm g_a.o
cleanb :
rm g_b.o
cleanmain :
rm main.o
clean :
rm $(OBJ) target
首先我创建了一个clean的文件,,由于我没有用.PHONY 将clean声明为伪目标,所以在执行make clean的时候,系统反而有点懵逼了,执行这个命令时,系统会按照make的执行规则,去寻找这个目标文件的依赖,,由于这个目标clean已经是最新(已经生成了)的了,,又没有用PHONY这个修饰,所以系统在这里就不会去执行clean下面那条指令了。
在其它的介绍当中,我们也可以利用伪目标的特性,生成多个目标文件。