摘要:首先makefile自动化编译文件有两种方法,一种是自己动手写makefile,一种是用automake自动生成工具来生成makefile.
大型项目,工程建议使用automake工具.
小型项目,工程直接自己动手写就行.
了解详细automake移步:automake自动生成makefile流程
一 , 手动创建makefile
1.测试helloworld 小程序. 创建四个文件,分别是:main.c ; hello.c; hello.h;makefile.
--main.c
#include "hello.h"
void main()
{
PrintfHello();
}
--hello.c
#include <stdio.h>
#include "hello.h"
void PrintfHello()
{
printf(" Hello World!\n");
}
--hello.h
#ifndef _HELLO_H_
#define _HELLO_H_
extern void PrintfHello();
#endif
--makefile
#automake_library makefile
objects = main.o hello.o
HelloWorld:$(objects)
cc -o HelloWorld $(objects)
$(objects):hello.h
.PHONY:clean
clean:
-rm HelloWorld $(objects)
2.make 编译 .
3../HelloWorld 运行.
二运用autoconf,automake自动生成makefile
1.
如图所示为automake,autoconf生成makefile的过程(简化)。
程序源码
|
autoscan*
|
configure.scan