automake详解

上传人:野鹰 文档编号:2895085 上传时间:2017-07-28 格式:DOC 页数:9 大小:93KB
返回 下载 相关 举报
automake详解_第1页
第1页 / 共9页
automake详解_第2页
第2页 / 共9页
automake详解_第3页
第3页 / 共9页
automake详解_第4页
第4页 / 共9页
automake详解_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《automake详解》由会员分享,可在线阅读,更多相关《automake详解(9页珍藏版)》请在金锄头文库上搜索。

1、2.6 自动编译调试工具Autoconf/Automake 工具用于自动创建功能完善的 makefile 文件。当前大多数软件包都是用这一工具生成 makefile 文件的。本节首先介绍 Autoconf/Automake 工具的功能以及makefile 创建过程中所涉及的文件和命令。最后以一个实例介绍如何使用Autoconf/Automake 工具自动创建 makefile 文件。2.6.1Autoconf/Automake 工具组简介(1)Autoconf/Automake 工具组主要包括 autoconf、automake、perl 语言环境和 m4。其中FC4 默认安装的 autoco

2、nf 和 automake 软件包信息如下:rootlocalhost hello# rpm -qa |grep autoconf /查看是否安装 autoconfautoconf-2.59-5rootlocalhost hello# rpm -qa |grep automake /查看是否安装 automakeautomake14-1.4p6-12automake-1.9.5-1automake17-1.7.9-6automake15-1.5-13automake16-1.6.3-5默认安装的 perl 语言环境如下:rootlocalhost # rpm -qa |grep perl /查

3、看 perl 的安装情况,已经安装后才有以下信息perl-Filter-1.30-7perl-URI-1.35-2perl-HTML-Tagset-3.04-1perl-libwww-perl-5.803-2perl-XML-Encoding-1.01-27perl-XML-NamespaceSupport-1.08-7perl-Crypt-SSLeay-0.51-6perl-XML-Grove-0.46alpha-27perl-5.8.6-15perl-DateManip-5.42a-4perl-HTML-Parser-3.45-1perl-Compress-Zlib-1.34-2perl-

4、XML-Parser-2.34-6perl-XML-Dumper-0.71-4perl-libxml-enno-1.02-31perl-Convert-ASN1-0.19-1perl-XML-SAX-0.12-7perl-LDAP-0.33-1perl-XML-LibXML-1.58-2perl-XML-Twig-3.17-1perl-Parse-Yapp-1.05-33perl-libxml-perl-0.08-1perl-XML-LibXML-Common-0.13-8默认安装的 m4 软件包如下:rootlocalhost # rpm -qa |grep m4 /查看是否安装 m4工具m

5、4-1.4.3-1如果读者没有获得以上任何一个软件包的完全安装,请直接插入 FC4 安装盘,使用system-config-packages命令更新,在开发工具中选中以上选项即可。以下命令用来查看本节所使用的 Autoconf/Automake 命令所在位置:rootlocalhost hello# whereis aclocal /查看aclocal 命令所在位置aclocal: /usr/bin/aclocal /usr/share/aclocalrootlocalhost hello# whereis autoscan /查看autoscan 命令所在位置autoscan: /usr/b

6、in/autoscan /usr/share/man/man1/autoscan.1.gzrootlocalhost hello# whereis autoconf /查看autoconf 命令所在位置autoconf: /usr/bin/autoconf /usr/share/autoconf /usr/share/man/man1/autoconf.1.gzrootlocalhost hello# whereis autoheader /查看autoheader 命令所在位置autoheader: /usr/bin/autoheader /usr/share/man/man1/autohe

7、ader.1.gzrootlocalhost hello# whereis automake /查看automake 命令所在位置automake: /usr/bin/automake /usr/local/automake使用 Autoconf/Automake 工具自动生成 Makefile 文件的流程图如图 2-5 所示。在此过程中使用的命令主要有 aclocal、autoscan、autoconf、autoheader 和 automake。由图可知运行步骤如下: (点击查看大图)图 2-5 自动创建 Makefile 文件流程(1)创建源代码文件,使用autoscan生成 confi

8、gure.scan 文件,将其重命名为configure.ac,并做适当修改,然后使用aclocal命令生成 aclocal.m4 文件,使用autoconf命令由 configure.ac 和 aclocal.m4 文件生成 configure 文件。(2)手工编辑 Makefile.am 文件,使用automake命令生成 configure.in 文件。(3)手工编辑或由系统给定 acconfig.h 文件,使用autoheader命令生成 config.h.in 文件。(4)使用configure命令由 configuer、configure.in 和 config.h.in 文件生成

9、 Makefile 文件。从而完成 Makefile 文件的创建过程。下面以自动编译 hello.c 程序为例介绍如何使用这组工具生成 makefile 文件。1使用 Vi 编辑器编辑源程序在 Linux 操作 Shell 提示符使用 Vi 编辑器下创建 hello.c 源程序。rootlocalhost ch0206# mkdir hello /创建文件夹rootlocalhost ch0206# cd hello /切换文件rootlocalhost hello# ls /已经创建的 hello.c 文件hello.crootlocalhost hello# cat hello.c /C

10、源程序代码int main(int argc,char* argv)printf(hello!GNUn);return 0;2使用 Autoscan 工具生成 configure.ac 文件Autoscan 工具用来扫描源代码以搜寻一般的可移植性问题,比如检查编译器、库和头文件等,并创建 configure.scan 文件,它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。如下所示:rootlocalhost hello# autoscan ./在当前文件夹中搜索autom4te: configure.ac: no such file or direc

11、toryautoscan: /usr/bin/autom4te failed with exit status: 1rootlocalhost hello# ls /生成 configure.scan 文件,它是 configure.ac 文件原型autoscan.log configure.scan hello.crootlocalhost hello# cat configure.scan /configure.scan 文件内容# -*- Autoconf -*-# Process this file with autoconf to produce a configure script

12、.AC_PREREQ(2.59) /autoconf 版本号AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS) /软件的名称和版本等信息AC_CONFIG_SRCDIR(hello.c) /侦测源码文件AC_CONFIG_HEADER(config.h) /用于生成 config.h 文件# Checks for programs.AC_PROG_CC /编译器# Checks for libraries.# Checks for header files.# Checks for typedefs, structures, and

13、compiler characteristics.# Checks for library functions.AC_OUTPUT /输入文件名 2.6.1Autoconf/Automake 工具组简介(2)下面给出本文件的简要说明(所有以#号开始的行为注释):(1)AC_PREREQ 宏声明本文件要求的 autoconf 版本,本例使用的版本为 2.59。(2)AC_INIT 宏用来定义软件的名称和版本等信息, FULL-PACKAGE-NAME为软件包名称,VERSION 为软件版本号,BUG-REPORT-ADDRESS为 BUG 报告地址(一般为软件作者邮件地址)。(3)AC_CONF

14、IG_SRCDIR 宏用来侦测所指定的源码文件是否存在,来确定源码目录的有效性。此处为当前目录下的 hello.c。 (4)AC_CONFIG_HEADER 宏用于生成 config.h 文件,以便 autoheader 使用。 (5)AC_PROG_CC 用来指定编译器,如果不指定,选用默认 gcc。(6)AC_OUTPUT 用来设定 configure 所要产生的文件,如果是 makefile,configure会把它检查出来的结果带入 makefile.in 文件产生合适的 makefile。使用 Automake 时,还需要一些其他的参数,这些额外的宏用 aclocal 工具产生。中间

15、的注释可以分别添加用户测试程序、测试函数库和测试头文件等宏定义。此文件只是下面要使用的 configure.ac 文件的原型,要使用此文件,还需要根据情况修改相关内容。rootlocalhost hello# cp configure.scan configure.ac /复制文件rootlocalhost hello# lsautoscan.log configure.ac configure.scan hello.crootlocalhost hello# cat configure.ac # -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.59)AC_INIT(hello,1.0,) /在此行内容中设置当前软件包信息AM_INIT_AUTOMAKE(hello,1.0) /automake 所必备的宏,必须添加AC_CONFIG_SRCDIR(hello.c) /源文件名AC_CONFIG_HEADER(config.h)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号