快速业务通道

Linux下编程工具的使用(4) - autoconf/automake工具

作者 佚名技术 来源 Linux系统 浏览 发布时间 2012-04-30
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 wo***ng aclocal... found

checking for wo***ng Autoconf... found

checking for wo***ng Automake... found

checking for wo***ng autoheader... found

checking for wo***ng 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 scrīpt 根据 Mak

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号