autotools使用简介

上传人:平*** 文档编号:13274467 上传时间:2017-10-23 格式:DOCX 页数:6 大小:31.59KB
返回 下载 相关 举报
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 autoc

2、onf autoheader 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

4、的内容 :wangshengpc01:/work/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

5、# Checks for libraries.# 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根据具体情况 , 适当修改 , 以下加粗部分是修改的内容 :wangshengpc0

6、1:/work/train/make/automake$ cat 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)# Che

7、cks for programs.AC_PROG_CC# Checks 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 宏用来定义软件的名称和版本等信息,

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

9、train/make/automake$ aclocalwangshengpc01:/work/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 con

10、figure configure.in hello.c(5) 运行 autoheader 命令, 生成 config.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.

11、in hello.c(6) 运行 automake 命令, 生成 Makefile.in 文件这一步是创建 Makefile 很重要的一步, automake 要用的脚本配置文件是 Makefile.am, 用户需要自己创建相应的文件. 之后, automake 工具将自动转换成 Makefile.in 本例中, 创建的文件为 Makefile.am, 内容如下:wangshengpc01:/work/train/make/automake$ cat Makefile.amAUTOMAKE_OPTIONS=foreignbin_PROGRAMS=hellohello_SOURCES=hello

12、.c说明: 其中的 AUTOMAKE_OPTIONS 为设置 automake 的选项. 由于 GNU 对自己发布的软件有严格的规范, 比如必须附带许可证声明文件 COPYING 等, 否则 automake 执行时会报错. automake提供了 3 中软件等级 :foreign, gnu 和 gnits, 供用户选择. 默认级别是 gnu. 在本例中, 使用了foreign 等级, 它只检测必须的文件. bin_PROGRAMS 定义要产生的执行文件名. 如果要产生多个执行文件, 每个文件名用空格隔开 hello_SOURCES 定义hello这个可执行程序所需的原始文件 . 如果hell

13、o这个程序是由多个源文件所产生的, 则必须把它所用到的所有源文件都列出来, 并用空格隔开. 如果要定义多个可执行程序, 那么需要对每个可执行程序建立对应的 file_SOURCES.在这里使用-add-missing选项可以让 automake 自动添加一些必须的脚本文件 .wangshengpc01:/work/train/make/automake$ automake -add-missingconfigure.in:7: installing ./install-shconfigure.in:7: installing ./missingMakefile.am: installing .

14、/depcompwangshengpc01:/work/train/make/automake$ lsaclocal.m4 autoscan.log configure depcomp 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 inst

15、all. /usr/bin/install -cchecking whether build environment is sane. yes checking for a thread-safe 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

16、. 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. yes checking whether gcc accepts -g. yes checking for gcc option to accept ISO C89. none needed checking for style of include used by make. GNU checking dependency style o

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

最新文档


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

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