只写一下比较简单粗暴五分钟可以理解的部分,详细写法引一下大神们的博客http://blog.csdn.net/liang13664759/article/details/1771246
规则:
格式:
Object : dependences
Command
Object是目标文件
Dependences是生成object所需要的头文件
Command是gcc或g++命令,可带参数。
另外makefile支持变量和变量引用(宏)
变量声明直接 变量名=变量内容 就OK
引用的时候要加一个$符号,但是如果变量名超过一个字符需要用()包起来
附一个例好了(引用自百度百科):
# Define a macro for the object files
OBJECTS= filea.o fileb.o filec.o
# Define a macro for the library file
LIBES= -LS
# use macros rewrite makefile
prog: $(OBJECTS)
cc $(OBJECTS) $(LIBES) -o prog