http://topic.youkuaiyun.com/t/20040313/22/2840083.html
近段时间因为在Linux下工作的关系,开始使用automake等一些列工具。从最初的一点不懂,到现在对其有所了解,并能够有效的
应用在自己的工作中,其中遇到了不少问题,都是通过查阅炎黄角马的autoconf手册找到了解决方法,有兴趣进一步
了解这些工具的朋友可以到:http://www.cngnu.org/technology/145747f6d616b656.html 查询更为详细的资料。
而我在这里只是简单的提一下我在工作中所常使用到的一些东西^ ^!
实用 automake (一)
从最简单的例子开始讲起,当所有的文件都在一个目录中时,也就是说automake 所支持的"flat"的目录结构
例如:
新建一个文件夹 automake
[lq@localhost automake]$ mkdir automake
[lq@localhost automake]$ cd automake
新建一个test.cpp文件如下:
#include <stdio.h>
int main()
{
printf(" Hello, automake/n");
}
OK,首先使用autoscan,他会扫描当前目录树,根据目录中源代码的层次结构生成一个configure.scan文件
[lq@localhost automake]$ autoscan
[lq@localhost automake]$ ls
autoscan.log configure.scan test.cpp
修改consigure.scan如下:
AC_INIT(automake, 0.1)
AM_INIT_AUTOMAKE(automake, 0.1)
AC_PROG_CXX
AC_OUTPUT([Makefile])
宏AC_INIT是autoconf所需要用到的表示项目的名称和版本号
宏AM_INIT_AUTOMAKE是automake所需要用到的
其它的顾名思义
宏AC_OUTPUT表明输出的Makefile文件的路径
OK,将其该名成configure.in
[lq@localhost automake]$ cp configure.scan configure.in
[lq@localhost automake]$ ls
autoscan.log configure.in configure.scan test.cpp
接下来:
[lq@localhost automake]$ aclocal
[lq@localhost automake]$ ls
aclocal.m4 autoscan.log configure.in configure.scan test.cpp
会生成一个aclocal.m4,里面包含了autoconf所需要所有的宏
接下来:
[lq@localhost automake]$ autoconf
[lq@localhost automake]$ ls
aclocal.m4 autom4te.cache autoscan.log configure configure.in configure.scan test.cpp
又多出来好几个文了
接下来编写一个Makefile.am文件如下:
[lq@localhost automake]$ vi Makefile.am
bin_PROGRAMS=test
test_SOURCES=test.cpp
我们的automake就可以通过它生成Makfile.in文件
在这里讲一下automake的几种严格性级别:
`foreign'(外来)
Automake将仅仅检查那些为保证正确操作所必需的事项。例如,尽管GNU标准指出文件`NEWS'必须存在,
在本方式下,并不需要它。该模式名来自于Automake 是被设计成用于GNU程序的事实的;它放松了标准
模式的操作规则。
`gnu'
Automake将尽可能地检查包是否服从GNU标准。这是缺省设置。
`gnits'
Automake将按照还没有完成的Gnits标准进行检查。它们是基于GNU标准的,但更加详尽。除非你是Gnits
标准的参与奉献者,我们建议您在Gnits标准正式出版之前不要使用这一选项。
在我们的例子里将会才用"gnu"的级别,所以需要如下几个文件,空文件也可以,大家可以先生成他们:
[lq@localhost automake]$ >NEWS
[lq@localhost automake]$ >README
[lq@localhost automake]$ >AUTHORS
[lq@localhost automake]$ >ChangeLog
接下来:
[lq@localhost automake]$ automake -a
这个时候就可以configure了
[lq@localhost automake]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
configure就扫描Makefile.in生成Makefile文件了
接下来该做什么就不用我说了吧
这次的例子比较简单,在以后我会介绍一下automake所支持的其他几种目录层次和生成共享库的例子
希望我写的这些对大家能有帮助
各位如果有什么意见或看法可以直接写信给我:
winux0@msn.com
谢谢
2004.3.13
winux
参考资料: http://www.cngnu.org/technology/145747f6d616b656.html
不错,我想知道有目录层次的例子。比如在我的src目录下有多个子目录,每个子目录中有若干个cpp文件,这种情况下该如何使用AutoMake呢?
多谢!Top
2 楼ufwt(uuu)回复于 2004-03-14 17:58:25 得分 0
我觉得autobook比较好。上面应该有答案!
好像是在Makefile。am中加入目录就可以了!
autobook的地址是
http://sources.redhat.com/autobook/Top
3 楼anonimousboy(stiwen)回复于 2004-03-15 12:22:28 得分 0
这是一些列 工具:automake;autoconf,autoscanf;不过还是需要用户自己写Makefile.am文件和configure.in文件,不过等生成了makefile以后就比较爽了
make 编译
make install 安装
make clean 清除临时文件
make distcheck 发布软件
。。。。
本文介绍了如何使用automake工具生成Makefile文件的过程。从创建简单的C++程序开始,逐步讲解了使用autoscan、aclocal、autoconf及automake命令的步骤。同时,文章还解释了configure.in和Makefile.am文件的作用,并提供了基本的目录结构示例。
2171

被折叠的 条评论
为什么被折叠?



