Makefile一直没有仔细的去看看,最近下狠心看了看,有一些收获;
先来看看这个例子:
main.c:
#include "dep.h"
void main()
{
dep(1);
printf("we are in main now !\n");
}
dep.c:
#include "dep.h"
void dep(int i)
{
printf("copy from main is %d\n",i);
}
dep.h:
#include <stdio.h>
void dep(int i);
再来看看Makefile:
test : main.o dep.o
cc -o test main.o dep.o
main.o : main.c dep.h
cc -c main.c
dep.o : dep.c dep.h
cc -c dep.c
注意:
(1)makefile 结构是:
target file : dependency file
【tab】 command
也就是说,command之前必须得有Tab键;
(2)Make 之后的流程:
1.make之后会寻找Makefile
2.查找第一个目标文件,也就是本例子中的test
3.如果没有test,检查有没有以来文件main.o和test.o,如果缺其一,则用规则生成依赖文件。