Makefile 学习
make - 工程管理器
nakefile就是make的执行规则
开发人员在拿到需求时,分到自己的几个功能模块,比如几个.c,然后再由一个人写一个总的makefile,把所有的功能都编译起来,也就是make工程管理区的作用
有时候会看到大写的M和小写的m
makefile–默认会找的小写的
Makefile–一般是程序员上传源码包命名的
因为用户需要拥有更高的权力,对于自己的工程项目可能需要自己写一些makefile文件,就可以新建一个小写的makefile文件,make在执行的时候就会优先调用
语法
target:files
command
现在我们编写一个小麻雀
main.c
#include <stdio.h>
#include "tool1.h"
#include "tool2.h"
int main() {
tool1();
tool2();
return 0;
}
tool1.c tool2.c
#include <stdio.h>
#include "tool1.h"
void tool1() {
printf("in my tool1\n");
}
tool1.h tool2.h
#ifndef TOOL1_H_
#define TOOL1_H_
void tool1(void);
#endif
通过gcc *.c 编译这些文件;这些的依赖关系是:
a.out -> main.o tool1.o tool2.o
main.o -> main.c
tool1.o -> tool1.c
too