📄 1060.html
字号:
&& Automake --include-deps --build-dir=$here --srcdir-name=. --output-dir=$top_distdir --foreign Makefile<br>
chmod -R a+r hello-1.0<br>
GZIP=--best gtar chozf hello-1.0.tar.gz hello-1.0<br>
rm -rf hello-1.0<br>
一切工作得很好! 当然,在make install时由于需要向系统目录拷贝文件,您需要有root权限。<br>
<br>
更进一步<br>
上述产生Makefile 的过程和以往自行编写的方式非常不一样,使用 Automake 只需用到一些已经定义好的宏就可以了。我们把宏及目标 (target)写在Makefile.am 文件内,Automake 读入 Makefile.am 文件后会把这一串已经定义好的宏展开并产生相对应的<br>
Makefile.in 文件,然后再由configure这个 shell script 根据 Makefile.in 产生合适的Makefile。<br>
具体流程如下所示:<br>
代码 --> [autoscan*] --> [configure.scan] --> configure.in<br>
configure.in --. .------> Autoconf* -----> configure<br>
+---+<br>
[aclocal.m4] --+ `---.<br>
[acsite.m4] ---' |<br>
+--> [autoheader*] -> [config.h.in]<br>
[acconfig.h] ----. |<br>
+-----'<br>
[config.h.top] --+<br>
[config.h.bot] --'<br>
<br>
Makefile.am -- [Autoconf*] -------> Makefile.in<br>
<br>
.-------------> config.cache<br>
configure* ------------+-------------> config.log<br>
|<br>
[config.h.in] -. v .-> [config.h] -.<br>
+--> config.status* -+ +--> make*<br>
Makefile.in ---' `-> Makefile ---'<br>
<br>
上图表示在整个过程中要使用的文件及产生出来的文件,有星号 (*) 代表可执行文件。在此示例中可由 Autoconf 及 Automake 工具所产生的额外文件有 configure.scan、aclocal.m4、configure、Makefile.in,需要加入设置的有configure.in 及 Makefile.am。开发者要书写的文件集中为confiugre.in和Makefile.am,在minigui项目中,我们把一系列的命令集中到一个批处理文件中: autogen.sh:<br>
<br>
#!/bin/sh<br>
aclocal<br>
autoheader<br>
Automake --add-missing<br>
Autoconf<br>
<br>
只要执行该批处理文件,结合configure.in和Makefile.am,就可以生成需要的Makefile了。<br>
<br>
编辑 configure.in 文件<br>
Autoconf 是用来产生 'configure'文件的工具。'configure' 是一个 shell script,它可以自动设定一些编译参数使程序能够条件编译以符合各种不同平台的Unix 系统。Autoconf会读取configure.in 文件然后产生'configure' 这个 shell script。<br>
<br>
configure.in 文件内容是一系列GNU m4 的宏,这些宏经Autoconf处理后会变成检查系统特性的shell scripts。 configure.in文件中宏的顺序并没有特别的规定,但是每一个configure.in 文件必须在所有其它宏前加入 AC_INIT 宏,然后在所有其它宏的最后加上 AC_OUTPUT宏。一般可先用 autoscan 扫描原始文件以产生一个 configure.scan 文件,再对 configure.scan 做些修改成 configure.in 文件。在例子中所用到的宏如下:<br>
<br>
dnl<br>
这个宏后面的内容不会被处理,可以视为注释<br>
<br>
AC_INIT(FILE)<br>
该宏用来检查源代码所在路径,autoscan 会自动产生,一般无须修改它。<br>
<br>
AM_INIT_AUTOMAKE(PACKAGE,VERSION)<br>
这个是使用 Automake 所必备的宏,PACKAGE 是所要产生软件的名称,VERSION 是版本编号。<br>
<br>
AC_PROG_CC<br>
检查系统可用的C编译器,若源代码是用C写的就需要这个宏。<br>
<br>
AC_OUTPUT(FILE)<br>
设置 configure 所要产生的文件,若是Makefile ,configure 便会把它检查出来的结果填充到Makefile.in 文件后产生合适的 Makefile。<br>
<br>
实际上,在使用 Automake 时,还需要一些其他的宏,这些额外的宏我们用 aclocal来帮助产生。执行 aclocal会产生aclocal.m4 文件,如果没有特别的用途,不需要修改它,用 aclocal 所产生的宏会告诉 Automake如何动作。<br>
<br>
有了 configure.in 及 aclocal.m4两个文件以后,便可以执行 Autoconf来产生 configure 文件了。<br>
<br>
编辑Makefile.am 文件<br>
接下来要编辑Makefile.am 文件,Automake 会根据 configure.in 中的宏并在perl的帮助下把Makefile.am 转成 Makefile.in 文件。 Makefile.am 文件定义所要产生的目标:<br>
<br>
AUTOMAKE_OPTIONS<br>
设置 Automake 的选项。Automake 主要是帮助开发 GNU 软件的人员来维护软件,所以在执行Automake 时,会检查目录下是否存在标准 GNU 软件中应具备的文件,例如 'NEWS'、'AUTHOR'、<br>
'ChangeLog' 等文件。设置为foreign 时,Automake 会改用一般软件的标准来检查。<br>
<br>
bin_PROGRAMS<br>
定义要产生的执行文件名。如果要产生多个执行文件,每个文件名用空白符隔开。<br>
<br>
hello_SOURCES<br>
定义 'hello' 这个执行程序所需要的原始文件。如果 'hello'这个程序是由多个原始文件所产生,<br>
必須把它所用到的所有原始文件都列出来,以空白符隔开。假设 'hello' 还需要 'hello.c'、'main.c'、'hello.h' 三个文件的话,则定义<br>
hello_SOURCES= hello.c main.c hello.h<br>
如果定义多个执行文件,则对每个执行程序都要定义相对的filename_SOURCES。<br>
<br>
编辑好 Makefile.am 文件,就可以用 Automake --add-missing来产生 Makefile.in。加上 --add-missing 选项来告诉 Automake顺便加入包装一个软件所必须的文件,如果你不使用该选项,Automake可能会抱怨缺少了什么文件。Automake产生出來的 Makefile.in 文件是完全符合 GNU Makefile 惯例的,只要执行 configure这个shell<br>
script 便可以产生合适的 Makefile 文件了。<br>
<br>
使用 Makefile<br>
利用 configure 所产生的 Makefile文件有几个预先设定的目标可供使用,这里只用几个简述如下:<br>
<br>
make all<br>
产生设定的目标,既范例中的可执行文件。只敲入make 也可以,此时会开始编译源代码,然后连接并产生执行文件。<br>
<br>
make clean<br>
清除之前所编译的可执行文件及目标文件(object file, *.o)。<br>
<br>
make distclean<br>
除了清除可执行文件和目标文件以外,也把 configure 所产生的 Makefile 清除掉。 通常在发布软件前执行该命令。<br>
<br>
make install<br>
将程序安装到系统中,若源码编译成功,且执行结果正确,便可以把程序安装到系统预先设定的执行文件存放路径中,若用 bin_PROGRAMS 宏的话,程序会被安装到 /usr/local/bin下。<br>
<br>
make dist<br>
将程序和相关的文档包装为一个压缩文档以供发布 (distribution) 。执行完在目录下会产生一个以<br>
PACKAGE-VERSION.tar.gz 为名称的文件。PACKAGE 和 VERSION 这两个参数是根据 configure.in 文中<br>
AM_INIT_AUTOMAKE(PACKAGE, VERSION) 的定义。在我们的例子中会产生 'hello-1.0.tar.gz' 的文件。<br>
<br>
make distcheck<br>
和 make dist 类似,但是加入检查包装以后的压缩文件是否正常,这个目标除了把程序和相关文档包装成 tar.gz 文件外,还会自动把这个压缩文件解开,执行 configure,并执行 make all ,确认编译无错误以后,方显示这个 tar.gz 文件已经准备好并可以发布了。当你看到:<br>
==========================================<br>
hello-1.0.tar.gz is ready for distribution<br>
==========================================<br>
<br>
就可以放心地发布您的软件了,检查过关的套件,基本上可以给任何具备 GNU 开发环境的人去重新编译成功。<br>
要注意的是,利用 Autoconf 及 Automake 所产生出來的软件套件是可以在没有安装 Autoconf 及 Automake 的环境使用的,因为 configure 是一个 shell script,它己被设计为可以在一般 Unix 的 sh 这个 shell 下执行。但是如果要修改 configure.in 及 Makefile.am 文件再产生新的 configure 及 Makefile.in 文件时就一定要有 Autoconf 及 Automake 了。<br>
<br>
相关资料<br>
通常我们掌握了一些入门知识就可以开始实践了,在有新的需求时,参照相关的文档和别人的例子解决问题,在实践中不断提高。<br>
Autoconf 和 Automake 功能十分强大,可以从它们附带的 info 文档中找到详细的使用说明。或者您喜欢html,可以从gun站点上下载hmtl版本。你也可以从许多现有的GNU 软件或 Open Source 软件如Minigui中找到相关的 configure.in 或 Makefile.am 文件,他们是学习 Autoconf 及 Automake 更多技巧的最佳范例。<br>
<br>
鸣谢<br>
由于本人的实践有限,所以这份文档主要是整理出来的。特此感谢:<br>
高嘉良 clkao@cirx.org<br>
許明彥 myhsu@cyberdude.com<br>
当然,还有GNU!'
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -