您的位置:软件测试 > 开源软件测试 > 开源配置管理工具 > cvs
CVS、Automake与Autoconf简介
作者:网络转载 发布时间:[ 2012/12/28 14:18:46 ] 推荐标签:

1. 用 autoscan 产生一个 configure.in 的原型,执行autoscan 后会产生一个configure.scan 的文件,可以用它作为 configure.in文件的蓝本。
 
% autoscan
% ls
configure.scan hello.c

2. 编辑 configure.scan文件,如下所示,?且改名为configure.in

dnl Process this file with Autoconf to produce a configure script.
AC_INIT(hello.c)
AM_INIT_AUTOMAKE(hello, 1.0)
dnl Checks for programs.
AC_PROG_CC
dnl Checks for libraries.
dnl Checks for header files.
dnl Checks for typedefs, structures, and compiler characteristics.
dnl Checks for library functions.
AC_OUTPUT(Makefile)

3. 执行 aclocal 和 Autoconf ,分?会产生 aclocal.m4 及 configure 两个文件

% aclocal
% Autoconf
% ls
aclocal.m4 configure configure.in hello.c

4. 编辑 Makefile.am 文件,?容如下

AUTOMAKE_OPTIONS= foreign
bin_PROGRAMS= hello
hello_SOURCES= hello.c

5. 执行 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:

% ./configure
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -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-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
updating cache ./config.cache
creating ./config.status
creating Makefile

$ ls
Makefile aclocal.m4 config.status hello.c mkinstalldirs
Makefile.am config.cache configure install-sh
Makefile.in config.log configure.in missing

?在你的目录下已经产生了一个 Makefile 文件,输入make指令可以编译 hello.c 了!

% make
gcc -DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 -c hello.c
gcc -g -O2 -o hello hello.o

你还可以试试 “make clean“,”make install“,”make dist“:
[root@localhost hello]# make clean
test -z "hello " || rm -f hello
rm -f *.o core *.core
[root@localhost hello]# make install
gcc -DPACKAGE="hello" -DVERSION="1.0" -I. -I. -g -O2 -c hello.c
gcc -g -O2 -o hello hello.o
make[1]: Entering directory `/home/joe/devel/hello'
/bin/sh ./mkinstalldirs /usr/local/bin
/usr/bin/install -c hello /usr/local/bin/hello
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/home/joe/devel/hello'
[root@localhost hello]# make dist
rm -rf hello-1.0
mkdir hello-1.0
chmod 777 hello-1.0
here=`cd . && pwd`;
top_distdir=`cd hello-1.0 && pwd`;
distdir=`cd hello-1.0 && pwd`;
cd .
&& Automake --include-deps --build-dir=$here --srcdir-name=. --output-dir=$top_distdir --foreign Makefile
chmod -R a+r hello-1.0
GZIP=--best gtar chozf hello-1.0.tar.gz hello-1.0
rm -rf hello-1.0
一切工作得很好! 当然,在make install时由于需要向系统目录拷贝文件,您需要有root权限。

更进一步
上述产生Makefile 的过程和以往自行编写的方式非常不一样,使用 Automake 只需用到一些已经定义好的宏可以了。我们把宏及目标 (target)写在Makefile.am 文件内,Automake 读入 Makefile.am 文件后会把这一串已经定义好的宏展开并产生相对应的
Makefile.in 文件,然后再由configure这个 shell script 根据 Makefile.in 产生合适的Makefile。
具体流程如下所示:
代码 --> [autoscan*] --> [configure.scan] --> configure.in
configure.in --. .------> Autoconf* -----> configure
+---+
[aclocal.m4] --+ `---.
[acsite.m4] ---' |
+--> [autoheader*] -> [config.h.in]
[acconfig.h] ----. |
+-----'
[config.h.top] --+
[config.h.bot] --'

Makefile.am -- [Autoconf*] -------> Makefile.in

.-------------> config.cache
configure* ------------+-------------> config.log
|
[config.h.in] -. v .-> [config.h] -.
+--> config.status* -+ +--> make*
Makefile.in ---' `-> Makefile ---'

上图表示在整个过程中要使用的文件及产生出来的文件,有星号 (*) 代表可执行文件。在此示例中可由 Autoconf 及 Automake 工具所产生的额外文件有 configure.scan、aclocal.m4、configure、Makefile.in,需要加入设置的有configure.in 及 Makefile.am。 开发者要书写的文件集中为confiugre.in和Makefile.am,在minigui项目中,我们把一系列的命令集中到一个批处理文件中:autogen.sh:

#!/bin/sh
aclocal
autoheader
Automake --add-missing
Autoconf

只要执行该批处理文件,结合configure.in和Makefile.am,可以生成需要的Makefile了。

编辑 configure.in 文件
Autoconf 是用来产生 'configure'文件的工具。'configure' 是一个 shell script,它可以自动设定一些编译参数使程序能够条件编译以符合各种不同平台的Unix 系统。Autoconf会读取configure.in 文件然后产生'configure' 这个 shell script。

configure.in 文件内容是一系列GNU m4 的宏,这些宏经Autoconf处理后会变成检查系统特性的shell scripts。 configure.in文件中宏的顺序并没有特别的规定,但是每一个configure.in 文件必须在所有其它宏前加入 AC_INIT 宏,然后在所有其它宏的后加上 AC_OUTPUT宏。一般可先用 autoscan 扫描原始文件以产生一个 configure.scan 文件,再对 configure.scan 做些修改成 configure.in 文件。在例子中所用到的宏如下:

dnl
这个宏后面的内容不会被处理,可以视为注释

AC_INIT(FILE)
该宏用来检查源代码所在路径,autoscan 会自动产生,一般无须修改它。 

上一页1234下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd