Dev110403:autoTools入门简记
Email: zcatt@163.com
Blog: http://zcatt.blog.chinaunix.net
内容提要
一个helloworld例子,简要介绍auomake,autoconf等autoTools的使用。以供备忘和参考。
声明
仅限学习交流,禁止商业用途。转载需注明出处。
本文已提交百度文库共享。
版本记录
Date Ver Note
2011-04-3 0.1 Draft. zcatt@Beijing
autoTools是一组构造makefile脚本的工具,它的目的是解决makefile脚本的平台兼容性。使用这组工具生成的脚本,用户可以在不同平台(主要是unix-like)上使用标准流程完成编译:
./configure
make
make install
autoTools包括autoscan,aclocal, autoheader, automake, autoconf, autoscan,和libtool等。这里只是已一个helloworl的例子,简要介绍一个入门。更深入的和详细的学习可以参考[1]。
下面我们首先介绍怎么做,然后解释每一步的具体内容。
1.helloworld的脚本生成
======================================
helloworld的例子有3个需要手工准备的文件:configure.ac, Makefile.am,和main.c。它们的内容如下:
configure.ac:
--------------
dnl Process this file with autoconf to produce a configure script.
AC_INIT(helloworld, 1.0)
AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
AC_CONFIG_HEADERS([config.h])
AM_MAINTAINER_MODE
AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_OUTPUT([
Makefile
])
Makefile.am
------------
## Process this file with automake to produce Makefile.in
bin_PROGRAMS = helloworld
helloworld_SOURCES = main.c
helloworld_LDFLAGS =
helloworld_LDADD =
main.c
------------
/* main.c */
#include
int main()
{
printf("Hello world!\n");
return (0);
}
下面依次执行:
1) 生成aclocal.m4, 使用命令
$ aclocal
2) 生成config.h.in, 使用命令
$ autoheader
3) 生成必要的一些说明文件
$ touch NEWS AUTHORS ChaneLog README
4) 拷贝一些模板文件
$ automake --add-missing
5) 生成Makefile.in
$ automake
6) 生成configure
$ autoconf
至此,configure, Makefile都已生成完成了。下面就是标准的编译步骤了。
7) 运行configure
$ ./configure
8) make
$ make
2.一些说明
======================================
aclocal
----------
aclocal负责生成aclocal.m4文件。
input: configure.in or configure.ac
ouput: alocal.m4
这里说明一下,configure.in和configure.ac这个文件名都是可以的,目前习惯使用configure.in的貌似更多些。
autoheader
----------
生成config.h.in。configure.in或configure.ac中定义的一些宏在config.h.in中以宏的形式出现。
input: configure.in or configure.ac
output: config.h.in
automake
----------
主要是生成Makefile.in。Makefile.in在后面将被configure用来生成Makefile。另外,使用--add-missing命令选项会拷入一些需要的模板文件。
input: Makefile.am, configure.in or configure.ac
output: Makefile.in
stamp-h.in, config.guess, config.stub
COPYING, INSALL, install-sh, missing, mkinstalldirs
autoconf
----------
生成configure。
input: configure.in or configure.ac, aclocal.m4
output: configure
configure
----------
生成Makefile文件。终于到罗马了...
input: config.h.in, Makeifle.in
output: Makefile, config.h, config.status, stamp-h
从上面可以看到,Makefile.am和configure.in需要手工创建。而另一个工具autoscan可以帮助我们生成configure.in。autoscan扫描源文件,会生成configure.scan。在configure.scan文件的基础上修改,然后保存成configure.in即可,记得加上宏AM_INIT_AUTOMAKE。
参考
===============
1. Autoconf, Automake, and Libtool
阅读(704) | 评论(0) | 转发(0) |