转自:http://blog.csdn.net/scucj/article/details/6079052
手工写Makefile是一件很有趣的事情,对于比较大型的项目,如果有工具可以代劳,自然是一件好事。在Linux系统开发环境中,GNU Autotools 无疑就充当了这个重要角色。(在Windows系统的开发环境中,IDE工具,诸如Visual Studio,来管理项目也很方便。)
本文以一个简单项目为例子,来讲述GNU Autotools的一列工具及其命令的用法。
autotools是系列工具, 它主要由autoconf、automake、perl语言环境和m4等组成;所包含的命令有五个:
(1)aclocal
(2)autoscan
(3)autoconf
(4)autoheader
(5)automake
一、准备源代码
(1)目录project包含一个main.c的文件和两个子目录lib与include;lib目录中包含一个test.c,include目录中包含一个test.h。在系统中,显示如下:
- [root@localhost project]# ls
- include lib main.c
- [root@localhost project]#
- [root@localhost project]# ls include/
- test.h
- [root@localhost project]# ls lib/
- test.c
- [root@localhost project]#
(2)源代码如下:
- /* project/main.c */
- #include <stdio.h>
- #include "include/test.h"
- int main()
- {
- printf("main entrance./n");
- test_method();
- return 0;
- }
- /* project/lib/test.c */
- #include <stdio.h>
- #include "../include/test.h"
- void test_method()
- {
- printf("test method./n");
- }
- /* project/include/test.h*/
- void test_method();
二、autotools 使用步骤
2.1 使用autoscan命令,它将扫描工作目录,生成 configure.scan 文件。
- [root@localhost project]# autoscan
- autom4te: configure.ac: no such file or directory
- autoscan: /usr/bin/autom4te failed with exit status: 1
- [root@localhost project]# ls
- autoscan.log configure.scan include lib main.c
- [root@localhost project]#
2.2 将configure.scan 文件重命名为configure.ac,并做适当的修改。在 configure.ac 中,# 号开始的行是注释,其他都是m4 宏命令;configure.ac里面的宏的主要作用是侦测系统。
- [root@localhost project]mv configure.scan configure.ac
- [root@localhost project]# ls
- autoscan.log configure.ac include lib main.c
- [root@localhost project]#
- [root@localhost project]# cat configure.ac
- # -*- Autoconf -*-
- # Process this file with autoconf to produce a configure script.
- AC_PREREQ(2.59)
- AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)
- AC_CONFIG_SRCDIR([main.c])