autotools使用简介

上传人:xiao****1972 文档编号:84078887 上传时间:2019-03-02 格式:DOCX 页数:6 大小:30.82KB
返回 下载 相关 举报
autotools使用简介_第1页
第1页 / 共6页
autotools使用简介_第2页
第2页 / 共6页
autotools使用简介_第3页
第3页 / 共6页
autotools使用简介_第4页
第4页 / 共6页
autotools使用简介_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《autotools使用简介》由会员分享,可在线阅读,更多相关《autotools使用简介(6页珍藏版)》请在金锄头文库上搜索。

1、autotools的使用 2010-04-07 15:05:39| 分类: 软件开发 | 标签:autotools |字号大中小 订阅 在较大项目中, 如果手动维护Makefile, 那将是一件复杂并痛苦的事情. 那么, 有没有一种轻松的手段生成Makefile呢? autotools系列工具正是在这样的呼声中诞生的. 它只需用户输入简单的目标文件, 依赖文件, 文件目录等就可以轻松地生成Makefile了. 另外, 这些工具还可以完成系统配置信息的收集, 从而可以方便地处理各种移植性问题.autotools是系列工具, 它包含有: aclocal autoscan autoconf auto

2、header automakeautotools使用流程:下面用一个简单的hello.c程序, 演示autotools的使用流程. hello.c如下:wangshengpc01:/work/train/make/automake$ lshello.cwangshengpc01:/work/train/make/automake$ cat hello.c#include int main()printf(Hello, autotools!n);return 0;(1) 使用autoscan命令自动生成configure.scan文件它会在给定目录及其子目录树中检查源文件, 若没有给出目录, 就

3、在当前目录及其子目录树中进行检查.它会搜索源文件以寻找一般的移植性问题并创建一个文件configure.scan, 该文件就是接下来autoconf要用到的configure.in原型.wangshengpc01:/work/train/make/automake$ autoscanwangshengpc01:/work/train/make/automake$ lsautoscan.log configure.scan hello.c(2)将configure.scan重命名为configure.in, 并做适当修改configure.scan的内容:wangshengpc01:/work/

4、train/make/automake$ cat configure.scan# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.65)AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)AC_CONFIG_SRCDIR(hello.c)AC_CONFIG_HEADERS(config.h)# Checks for programs.AC_PROG_CC# Checks for libraries.#

5、Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_OUTPUT将configure.scan重命名为configure.inwangshengpc01:/work/train/make/automake$ mv configure.scan configure.in根据具体情况, 适当修改, 以下加粗部分是修改的内容:wangshengpc01:/work/train/make/automake$ ca

6、t configure.in# -*- Autoconf -*-# Process this file with autoconf to produce a configure script.AC_PREREQ(2.65)#AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)AC_INIT(hello,1.0)AM_INIT_AUTOMAKE(hello,1.0)AC_CONFIG_SRCDIR(hello.c)AC_CONFIG_HEADERS(config.h)# Checks for programs.AC_PROG_CC# Ch

7、ecks for libraries.# Checks for header files.# Checks for typedefs, structures, and compiler characteristics.# Checks for library functions.AC_CONFIG_FILES(Makefile)AC_OUTPUT下面对这个脚本进行解释: 以#号开始的行为注释 AC_PREREQ宏声明本文要求的autoconf版本, 如本例中的版本 2.65 AC_INIT宏用来定义软件的名称和版本等信息, 在本例中省略了BUG-REPROT-ADDRESS, 一般为作者的E-

8、mail AM_INIT_AUTOMAKE是手动添加的, 它是automake所必备的宏, 也同前面一样, PACKAGE是所要产生软件套件的名称,VERSION是版本编号. AC_CONFIG_SCRDIR宏用来侦测所指定的源码文件是否存在, 来确定源码目录的有效性. 在此处指当前目录下hello.c AC_CONFIG_FILES宏用于生成相应的Makefile文件.(3) 运行aclocal命令,生成aclocal.m4文件, 该文件主要处理本地的宏定义wangshengpc01:/work/train/make/automake$ aclocalwangshengpc01:/work/

9、train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log configure.in hello.c(4) 运行autoconf命令生成configure可执行文件wangshengpc01:/work/train/make/automake$ autoconfwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c(5) 运行autoheader命令, 生成con

10、fig.h.in文件.该工具通常会从acconfig.h文件中复制用户附加的符号定义. 本例中没有附加的符号定义, 所以不需要创建acconfig.h文件.wangshengpc01:/work/train/make/automake$ autoheaderwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autom4te.cache autoscan.log config.h.in configure configure.in hello.c(6) 运行automake命令, 生成Makefile.in文件这一步是创建Makefile

11、很重要的一步, automake要用的脚本配置文件是Makefile.am, 用户需要自己创建相应的文件. 之后, automake工具将自动转换成Makefile.in 本例中, 创建的文件为Makefile.am, 内容如下:wangshengpc01:/work/train/make/automake$ cat Makefile.amAUTOMAKE_OPTIONS=foreignbin_PROGRAMS=hellohello_SOURCES=hello.c说明: 其中的AUTOMAKE_OPTIONS为设置automake的选项. 由于GNU对自己发布的软件有严格的规范, 比如必须附带

12、许可证声明文件COPYING等, 否则automake执行时会报错. automake提供了3中软件等级:foreign, gnu和gnits, 供用户选择. 默认级别是gnu. 在本例中, 使用了foreign等级, 它只检测必须的文件. bin_PROGRAMS定义要产生的执行文件名. 如果要产生多个执行文件, 每个文件名用空格隔开 hello_SOURCES定义hello这个可执行程序所需的原始文件. 如果hello这个程序是由多个源文件所产生的, 则必须把它所用到的所有源文件都列出来, 并用空格隔开. 如果要定义多个可执行程序, 那么需要对每个可执行程序建立对应的file_SOURCE

13、S.在这里使用-add-missing选项可以让automake自动添加一些必须的脚本文件.wangshengpc01:/work/train/make/automake$ automake -add-missingconfigure.in:7: installing ./install-shconfigure.in:7: installing ./missingMakefile.am: installing ./depcompwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autoscan.log configure depcomp

14、 install-sh Makefile.inautom4te.cache config.h.in configure.in hello.c Makefile.am missing(7)运行configure, 生成Makfefile文件wangshengpc01:/work/train/make/automake$ ./configurechecking for a BSD-compatible install. /usr/bin/install -cchecking whether build environment is sane. yes checking for a thread-s

15、afe mkdir -p. /bin/mkdir -p checking for gawk. gawk checking whether make sets $(MAKE). yes checking for gcc. gcc checking whether the C compiler works. yes checking for C compiler default output file name. a.out checking for suffix of executables. checking whether we are cross compiling. no checking for suffix of object files. o checking whether we are using the GNU C compiler

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

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