标签:style blog io ar color os 使用 sp for
二、autotools是系列工具, 它主要由autoconf、automake、perl语言环境和m4等组成;所包含的命令有五个 :
它会在给定目录及其子目录树中检查源文件,若没有给出目录,就在当前目录及其子目录树中进行检查。它会搜索源文件以寻找一般的移植性问题并创建一个文件“configure.scan”,该文件就是接下来autoconf要 用到的“configure.in”原型。如下所示:
[root@localhost automake]# autoscan
autom4te: configure.ac: no such file or directory
autoscan: /usr/bin/autom4te failed with exit status: 1
[root@localhost automake]# ls
autoscan.log configure.scan hello.c
如上所示,autoscan首先会尝试去读入“configure.ac”(同configure.in的配置文件)文件,此时还没有创建该配置文件,于是它会自动生成一个“configure.in”的原型文件“configure.scan”。
configure.in是autoconf的脚本配置文件,它的原型文件“configure.scan”如下所示:
1 # -*- Autoconf -*-
2 3 # Process this file with autoconf to produce a configure script. 4 5 AC_PREREQ(2.59) 6 7 #The next one is modified by sunq 8 9 #AC_INIT(FULL-PACKAGE-NAME,VERSION,BUG-REPORT-ADDRESS) 10 11 AC_INIT(hello,1.0) 12 13 # The next one is added by sunq 14 15 AM_INIT_AUTOMAKE(hello,1.0) 16 17 AC_CONFIG_SRCDIR([hello.c]) 18 19 AC_CONFIG_HEADER([config.h]) 20 21 # Checks for programs. 22 23 AC_PROG_CC 24 25 # Checks for libraries. 26 27 # Checks for header files. 28 29 # Checks for typedefs, structures, and compiler characteristics. 30 31 # Checks for library functions. 32 33 AC_CONFIG_FILES([Makefile]) 34 35 AC_OUTPUT
下面对这个脚本文件进行解释:
接下来首先运行aclocal,生成一个“aclocal.m4”文件,该文件主要处理本地的宏定义。如下所示:
[root@localhost automake]# aclocal
再接着运行autoconf,生成“configure”可执行文件。如下所示:
[root@localhost automake]# autoconf
[root@localhost automake]# ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in hello.c
接着使用autoheader命令,它负责生成config.h.in文件。该工具通常会从“acconfig.h”文件中复制用户附加的符号定义,因此此处没有附加符号定义,所以不需要创建“acconfig.h”文件。如下所示:
[root@localhost automake]# autoheader
这一步是创建Makefile很重要的一步,automake要用的脚本配置文件是Makefile.am,用户需要自己创建这个文件。之后,automake工具将其转换成Makefile.in。
在该例中,创建的文件为Makefile.am如下所示:
AUTOMAKE_OPTIONS=foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c hello.h
下面对该脚本文件的对应项进行解释。
接下来可以使用automake对其生成“configure.in”文件,在这里使用选项“—adding-missing”可以让automake自动添加有一些必需的脚本文件。如下所示:
[root@localhost automake]# automake --add-missing
configure.in: installing ‘./install-sh‘
configure.in: installing ‘./missing‘
Makefile.am: installing ‘depcomp‘
[root@localhost automake]# ls
aclocal.m4 autoscan.log configure.in hello.c Makefile.am missing
autom4te.cache configure depcomp install-sh Makefile.in config.h.in
可以看到,在automake之后就可以生成configure.in文件。
标签:style blog io ar color os 使用 sp for
原文地址:http://www.cnblogs.com/naray/p/4160089.html