2009年4月7日星期二

HelloWorld in autoconf & automake

写个autoconf和automake的HelloWorld先,以后再慢慢添加些常用宏的含义。
ok,让我们从hello.c开始
#include <stdio.h>
main()
{
printf("Howdy world!
");
}
当然你可以像下面这样简单的编译这个程序
% gcc hello.c -o hello
% hello
让我们看看使用autoconf和automake的编译方法,首先创建下面两个文件
`Makefile.am'
bin_PROGRAMS = hello
hello_SOURCES = hello.c
`configure.in'
AC_INIT(hello.c)
AM_INIT_AUTOMAKE(hello,0.1)
AC_PROG_CC
AC_PROG_INSTALL
AC_OUTPUT(Makefile)
运行 `autoconf':
% aclocal
% autoconf
上面这一步将产生我们熟悉的`configure'脚本。接下来运行 `automake':
% automake -a
required file "./install-sh" not found; installing
required file "./mkinstalldirs" not found; installing
required file "./missing" not found; installing
required file "./INSTALL" not found; installing
required file "./NEWS" not found
required file "./README" not found
required file "./COPYING" not found; installing
required file "./AUTHORS" not found
required file "./ChangeLog" not found
'-a' 的意思是'add missing standard files to
package',第一次运行automake它会帮我们产生一些标准的文件,这些文件都是为了符合GNU编码标准,但也会出现一些文件找不到的错误,这些文件需要我们自己创建:
% touch NEWS README AUTHORS ChangeLog
再跑一下automake:
% automake -a
这时就会产生`Makefile.in'
现在所有的任务都完成,可以打包分发了,使用方法地球人都知道:
% ./configure
% make
% ./hello

没有评论: