免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 797 | 回复: 0
打印 上一主题 下一主题

autoconf automake使用小例 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-15 12:33 |只看该作者 |倒序浏览
在开始试着用 Automake 之前,请先确认你的系统已经安装以下的软件:
1. GNU Automake
2. GNU Autoconf
3. GNU m4
4. perl
5. GNU Libtool (如果你需要产生 shared library)
以下的范例是在 fedora core 8 的环境下所完成的。
一个简单的例子
        在工作目录下建立一个新的子目录 ``devel'',再在 devel 下建立一个``hello'' 的子目录,这个目录将作为我们存放 hello 这个程式及其相关档案的地方:
% mkdir devel
% cd devel
% mkdir hello
% cd hello
用编辑器写个 hello.c 档,
#include
int main()
{
printf(``Hello, GNU! '');
return 0;
}
接下来就要用 Autoconf 及 Automake 来帮我们产生 Makefile 档了,产生过程如下:

1. 用 autoscan 产生一个 configure.in 的雏型,执行 autoscan 后会产生一个configure.scan 的档案,我们可以用它做为configure.in档的蓝本。
% autoscan
% ls
configure.scan hello.c
2. 编辑 configure.scan 档,如下所示,并且把它的档名改成configure.in
AC_INIT(hello.c)                       //源文件路径为hello.c
AM_INIT_AUTOMAKE(hello, 1.0)          //将要生成的软件的名称及其版本号
AC_PROG_CC                             //系统可用的c编译器
AC_OUTPUT(Makefile)                        //输出的makefile的名字

3. 执行 aclocal 和 autoconf ,分别会产生 aclocal.m4 及 configure 两个档案
% aclocal
% autoheader
% autoconf
% ls
aclocal.m4 configure configure.in hello.c
4. 编辑 Makefile.am 档,内容如下
AUTOMAKE_OPTIONS= foreign   
//[color="#000000"]这个是automake的选项。在执行automake时,它会检查目录下是否存在标准GNU软件包中应具备的各种文件,例如AUTHORS、ChangeLog、NEWS等文件。我们将其设置成foreign时,automake会改用一般软件包的标准来检查。
  bin_PROGRAMS= hello

//[color="#000000"]这个是指定我们所要产生的可执行文件的文件名。如果你要产生多个可执行文件,那么在各个名字间用空格隔开。
  hello_SOURCES= hello.c              



个是指定产生"helloworld"时所需要的源代码。如果它用到了多个源文件,那么请使用空格符号将它们隔开。比如需要
helloworld.h,helloworld.c那么请写成helloworld_SOURCES= helloworld.h
helloworld.c。
如果你在bin_PROGRAMS定义了多个可执行文件,则对应每个可执行文件都要定义相对的filename_SOURCES。

5. Automake 会根据 configure.in 中的巨集把Makefile.am 转成 Makefile.in 。
当执行 automake --add-missing ,Automake 会根据 Makefile.am 档产生一些档案,包含最重要的 Makefile.in
% automake --add-missing
automake: configure.in: installing `./install-sh'
automake: configure.in: installing `./mkinstalldirs'
automake: configure.in: installing `./missing'
6. 最後执行 ./configure ,产生makefile文件
% ./configure
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/in stall -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... found
checking for working autoconf... found
checking for working automake... found
checking for working autoheader... found
checking for working makeinfo... found
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-co mpiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
updating cache ./config.cache
creating ./config.status
creating Makefile
        现在你的目录下已经产生了一个 Makefile 档,执行 ``make'' 指令就可以开始编译 hello.c 成可执行文件。
% make
gcc -DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 -c he llo.c
gcc -g -O2 -o hello hello.o
% ./hello
Hello! GNU!
你还可以试试 ``make clean'',''make install'',''make dist'' 看看会有什么结果。
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/72785/showart_1082331.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP