﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-beautykingdom-随笔分类-makefile</title><link>http://www.cppblog.com/beautykingdom/category/12364.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 17 Jun 2010 04:56:28 GMT</lastBuildDate><pubDate>Thu, 17 Jun 2010 04:56:28 GMT</pubDate><ttl>60</ttl><item><title>跟我一起写 Makefile</title><link>http://www.cppblog.com/beautykingdom/archive/2010/05/14/115369.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 14 May 2010 07:02:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2010/05/14/115369.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/115369.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2010/05/14/115369.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/115369.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/115369.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 概述——什么是makefile？或许很多Winodws的程序员都不知道这个东西，因为那些Windows的IDE都为你做了这个工作，但我觉得要作一个好的和professional的程序员，makefile还是要懂。这就好像现在有这么多的HTML的编辑器，但如果你想成为一个专业人士，你还是要了解HTML的标识的含义。特别在Unix下的软件编译，你就不能不自己写makefile了，会...&nbsp;&nbsp;<a href='http://www.cppblog.com/beautykingdom/archive/2010/05/14/115369.html'>阅读全文</a><img src ="http://www.cppblog.com/beautykingdom/aggbug/115369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2010-05-14 15:02 <a href="http://www.cppblog.com/beautykingdom/archive/2010/05/14/115369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>G++编译选项</title><link>http://www.cppblog.com/beautykingdom/archive/2010/03/19/110070.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Fri, 19 Mar 2010 01:23:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2010/03/19/110070.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/110070.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2010/03/19/110070.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/110070.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/110070.html</trackback:ping><description><![CDATA[<span style="widows: 2; text-transform: none; text-indent: 0px; border-collapse: separate; font: medium simsun; white-space: normal; orphans: 2; letter-spacing: normal; color: #000000; word-spacing: 0px;" class="Apple-style-span"><span style="text-align: left; line-height: 25px; font-family: 宋体; font-size: 14px;" class="Apple-style-span">
<p style="padding: 0px; margin: 10px 0px 0px; word-wrap: break-word;">gcc/g++ 在执行编译时，需要4步</p>
<p style="padding: 0px; margin: 10px 0px 0px; word-wrap: break-word;">　　1.预处理,生成.i的文件[使用-E参数]</p>
<p style="padding: 0px; margin: 10px 0px 0px; word-wrap: break-word;">　　2.将预处理后的文件不转换成汇编语言,生成文件.s[使用-S参数]</p>
<p style="padding: 0px; margin: 10px 0px 0px; word-wrap: break-word;">　　3.有汇编变为目标代码(机器代码)生成.o的文件[使用-c参数]</p>
<p style="padding: 0px; margin: 10px 0px 0px; word-wrap: break-word;">　　4.连接目标代码,生成可执行程序[使用-o参数]<br><br>-x language filename</p>
<p>　　设定文件所使用的语言,使后缀名无效,对以后的多个有效.也就是根据约定C语言的后缀名称是.c的，而<a class="channel_keylink" href="http://c.chinaitlab.com/" target="_blank"><u><font color="#0000ff">C++</font></u></a>的后缀名是.C或者.cpp,如果你很个性，决定你的C代码文件的后缀名是.pig 哈哈，那你就要用这个参数,这个参数对他后面的文件名都起作用，除非到了下一个参数的使用。</p>
<p>-ansi</p>
<p>　　关闭gnu c中与ansi c不兼容的特性,激活ansi c的专有特性(包括禁止一些asm inline typeof关键字,以及UNIX,vax等预处理宏,</p>
<p>-fno-asm</p>
<p>　　此选项实现ansi选项的功能的一部分，它禁止将asm,inline和typeof用作关键字。</p>
<p>-fno-strict-prototype</p>
<p>　　只对g++起作用,使用这个选项,g++将对不带参数的函数,都认为是没有显式的对参数的个数和类型说明,而不是没有参数.而gcc无论是否使用这个参数,都将对没有带参数的函数,认为城没有显式说明的类型</p>
<p>-fthis-is-varialble</p>
<p>　　就是向传统c++看齐,可以使用this当一般变量使用.</p>
<p>-fcond-mismatch</p>
<p>　　允许条件表达式的第二和第三参数类型不匹配,表达式的值将为void类型</p>
<p>　　-funsigned-char</p>
<p>　　-fno-signed-char</p>
<p>　　-fsigned-char</p>
<p>　　-fno-unsigned-char</p>
<p>　　这四个参数是对char类型进行设置,决定将char类型设置成unsigned char(前两个参数)或者 signed char(后两个参数)</p>
<p>-include file</p>
<p>　　包含某个代码,简单来说,就是便以某个文件,需要另一个文件的时候,就可以用它设定,功能就相当于在代码中使#include&lt;filename&gt;</p>
<p>　　例子用法:</p>
<p>　　gcc hello.c -include /root/pianopan.h</p>
<p>　　-imacros file</p>
<p>　　将file文件的宏,扩展到gcc/g++的输入文件,宏定义本身并不出现在输入文件中</p>
<p>　　-Dmacro</p>
<p>　　相当于C语言中的#define macro</p>
<p>　　-Dmacro=defn</p>
<p>　　相当于C语言中的#define macro=defn</p>
<p>　　-Umacro</p>
<p>　　相当于C语言中的#undef macro</p>
<p>　　-undef</p>
<p>　　取消对任何非标准宏的定义</p>
<p>　　-Idir</p>
<p>　　在你是用#include"file"的时候,gcc/g++会先在当前目录查找你所制定的头文件,如果没有找到,他回到缺省的头文件目录找,如果使用-I制定了目录,他回先在你所制定的目录查找,然后再按常规的顺序去找.对于#include&lt;file&gt;,gcc/g++会到-I制定的目录查找,查找不到,然后将到系统的缺省的头文件目录查找</p>
<p>　　-I-</p>
<p>　　就是取消前一个参数的功能,所以一般在-Idir之后使用</p>
<p>　　-idirafter dir</p>
<p>　　在-I的目录里面查找失败,讲到这个目录里面查找.</p>
<p>　　-iprefix prefix</p>
<p>　　-iwithprefix dir</p>
<p>　　一般一起使用,当-I的目录查找失败,会到prefix+dir下查找</p>
<p>　　-nostdinc</p>
<p>　　使编译器不再系统缺省的头文件目录里面找头文件,一般和-I联合使用,明确限定头文件的位置</p>
<p>　　-nostdin <a class="channel_keylink" href="http://c.chinaitlab.com/" target="_blank"><u><font color="#0000ff">C++</font></u></a></p>
<p>　　规定不在g++指定的标准路经中搜索,但仍在其他路径中搜索,.此选项在创建libg++库使用</p>
<p>　　-C</p>
<p>　　在预处理的时候,不删除注释信息,一般和-E使用,有时候分析程序，用这个很方便的</p>
<p>　　-M</p>
<p>　　生成文件关联的信息。包含目标文件所依赖的所有源代码</p>
<p>　　你可以用gcc -M hello.c来<a class="channel_keylink" href="http://softtest.chinaitlab.com/" target="_blank"><u><font color="#0000ff">测试</font></u></a>一下，很简单。</p>
<p>　　-MM</p>
<p>　　和上面的那个一样，但是它将忽略由#include&lt;file&gt;造成的依赖关系。</p>
<p>　　-MD</p>
<p>　　和-M相同，但是输出将导入到.d的文件里面</p>
<p>　　-MMD</p>
<p>　　和-MM相同，但是输出将导入到.d的文件里面</p>
<p>　　-Wa,option</p>
<p>　　此选项传递option给汇编程序;如果option中间有逗号,就将option分成多个选项,然后传递给会汇编程序</p>
<p>　　-Wl.option</p>
<p>　　此选项传递option给连接程序;如果option中间有逗号,就将option分成多个选项,然后传递给会连接程序.</p>
<p>　　-llibrary</p>
<p>　　制定编译的时候使用的库</p>
<p>　　例子用法</p>
<p>　　gcc -lcurses hello.c</p>
<p>　　使用ncurses库编译程序</p>
<p>　　-Ldir</p>
<p>　　制定编译的时候，搜索库的路径。比如你自己的库，可以用它制定目录，不然编译器将只在标准库的目录找。这个dir就是目录的名称。</p>
<p>　　-O0</p>
<p>　　-O1</p>
<p>　　-O2</p>
<p>　　-O3</p>
<p>　　编译器的优化选项的4个级别，-O0表示没有优化,-O1为缺省值，-O3优化级别最高</p>
<p>　　-g</p>
<p>　　只是编译器，在编译的时候，产生条是信息。</p>
<p>　　-gstabs</p>
<p>　　此选项以stabs格式声称调试信息,但是不包括gdb调试信息.</p>
<p>　　-gstabs+</p>
<p>　　此选项以stabs格式声称调试信息,并且包含仅供gdb使用的额外调试信息.</p>
<p>　　-ggdb</p>
<p>　　此选项将尽可能的生成gdb的可以使用的调试信息.</p>
<p>　　-static</p>
<p>　　此选项将禁止使用动态库，所以，编译出来的东西，一般都很大，也不需要什么动态连接库，就可以运行.</p>
<p>　　-share</p>
<p>　　此选项将尽量使用动态库，所以生成文件比较小，但是需要系统由动态库.</p>
<p>　　-traditional</p>
<p>　　试图让编译器支持传统的C语言特性</p>
from：<br><a href="http://c.chinaitlab.com/ccjq/803616_2.html">http://c.chinaitlab.com/ccjq/803616_2.html</a><br></span></span><img src ="http://www.cppblog.com/beautykingdom/aggbug/110070.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2010-03-19 09:23 <a href="http://www.cppblog.com/beautykingdom/archive/2010/03/19/110070.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>autotools制作Makefile 和configure文件</title><link>http://www.cppblog.com/beautykingdom/archive/2009/11/21/101566.html</link><dc:creator>chatler</dc:creator><author>chatler</author><pubDate>Sat, 21 Nov 2009 10:33:00 GMT</pubDate><guid>http://www.cppblog.com/beautykingdom/archive/2009/11/21/101566.html</guid><wfw:comment>http://www.cppblog.com/beautykingdom/comments/101566.html</wfw:comment><comments>http://www.cppblog.com/beautykingdom/archive/2009/11/21/101566.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/beautykingdom/comments/commentRss/101566.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/beautykingdom/services/trackbacks/101566.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;<img border=0 src="http://blogimg.chinaunix.net/blog/upfile2/090924111737.jpg" onload="javascript:if(this.width>500)this.width=500;"><br>
<p style="FONT: 12px song, Verdana">1.autoscan (autoconf): 扫描源代码以搜寻普通的可移植性问题，比如检查编译器，库，头文件等，生成文件configure.scan,它是configure.ac的一个雏形。</p>
<p style="FONT: 12px song, Verdana">&nbsp;&nbsp;&nbsp; your source files --&gt; [autoscan*] --&gt; [configure.scan] --&gt; configure.ac</p>
2.aclocal (automake):根据已经安装的宏，用户定义宏和acinclude.m4文件中的宏将configure.ac文件所需要的宏集中定义到文件 aclocal.m4中。aclocal是一个perl 脚本程序，它的定义是：&#8220;aclocal - create aclocal.m4 by scanning configure.ac&#8221;
<pre style="LINE-HEIGHT: normal" class=example>user input files   optional input     process          output files<br style="FONT: 12px song, Verdana">================   ==============     =======          ============<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">                    acinclude.m4 - - - - -.<br style="FONT: 12px song, Verdana">                                          V<br style="FONT: 12px song, Verdana">                                      .-------,<br style="FONT: 12px song, Verdana">configure.ac ------------------------&gt;|aclocal|<br style="FONT: 12px song, Verdana">                 {user macro files} -&gt;|       |------&gt; aclocal.m4<br style="FONT: 12px song, Verdana">                                      `-------'<br style="FONT: 12px song, Verdana">3.autoheader(autoconf): 根据configure.ac中的某些宏，比如cpp宏定义，运行m4，声称config.h.in<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">user input files    optional input     process          output files<br style="FONT: 12px song, Verdana">================    ==============     =======          ============<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">                    aclocal.m4 - - - - - - - .<br style="FONT: 12px song, Verdana">                                             |<br style="FONT: 12px song, Verdana">                                             V<br style="FONT: 12px song, Verdana">                                     .----------,<br style="FONT: 12px song, Verdana">configure.ac -----------------------&gt;|autoheader|----&gt; autoconfig.h.in<br style="FONT: 12px song, Verdana">                                     `----------'</pre>
<p style="FONT: 12px song, Verdana">4.automake: automake将Makefile.am中定义的结构建立Makefile.in，然后configure脚本将生成的Makefile.in文件转换 为Makefile。如果在configure.ac中定义了一些特殊的宏，比如AC_PROG_LIBTOOL，它会调用libtoolize，否则它 会自己产生config.guess和config.sub</p>
<pre style="LINE-HEIGHT: normal" class=example>user input files   optional input   processes          output files<br style="FONT: 12px song, Verdana">================   ==============   =========          ============<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">                                     .--------,<br style="FONT: 12px song, Verdana">                                     |        | - - -&gt; COPYING<br style="FONT: 12px song, Verdana">                                     |        | - - -&gt; INSTALL<br style="FONT: 12px song, Verdana">                                     |        |------&gt; install-sh<br style="FONT: 12px song, Verdana">                                     |        |------&gt; missing<br style="FONT: 12px song, Verdana">                                     |automake|------&gt; mkinstalldirs<br style="FONT: 12px song, Verdana">configure.ac -----------------------&gt;|        |<br style="FONT: 12px song, Verdana">Makefile.am  -----------------------&gt;|        |------&gt; Makefile.in<br style="FONT: 12px song, Verdana">                                     |        |------&gt; stamp-h.in<br style="FONT: 12px song, Verdana">                                 .---+        | - - -&gt; config.guess<br style="FONT: 12px song, Verdana">                                 |   |        | - - -&gt; config.sub<br style="FONT: 12px song, Verdana">                                 |   `------+-'<br style="FONT: 12px song, Verdana">                                 |          | - - - -&gt; config.guess<br style="FONT: 12px song, Verdana">                                 |libtoolize| - - - -&gt; config.sub<br style="FONT: 12px song, Verdana">                                 |          |--------&gt; ltmain.sh<br style="FONT: 12px song, Verdana">                                 |          |--------&gt; ltconfig<br style="FONT: 12px song, Verdana">                                 `----------'</pre>
<p style="FONT: 12px song, Verdana">5.autoconf:将configure.ac中的宏展开，生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。</p>
<pre style="LINE-HEIGHT: normal" class=example>user input files   optional input   processes          output files<br style="FONT: 12px song, Verdana">================   ==============   =========          ============<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">aclocal.m4 ,autoconfig.h.in - - - - - - -.<br style="FONT: 12px song, Verdana">                                         V<br style="FONT: 12px song, Verdana">                                     .--------,<br style="FONT: 12px song, Verdana">configure.ac -----------------------&gt;|autoconf|------&gt; configure</pre>
<pre style="LINE-HEIGHT: normal" class=example> </pre>
<pre style="LINE-HEIGHT: normal" class=example>6. ./configure的过程</pre>
<pre style="LINE-HEIGHT: normal" class=example><br style="FONT: 12px song, Verdana">                                           .-------------&gt; [config.cache]<br style="FONT: 12px song, Verdana">     configure* --------------------------+-------------&gt; config.log<br style="FONT: 12px song, Verdana">                                          |<br style="FONT: 12px song, Verdana">              [config.h.in] -.            v            .--&gt; [autoconfig.h]<br style="FONT: 12px song, Verdana">                             +-------&gt; config.status* -+                   <br style="FONT: 12px song, Verdana">              Makefile.in ---'                         `--&gt;   Makefile</pre>
<pre style="LINE-HEIGHT: normal" class=example> </pre>
<pre style="LINE-HEIGHT: normal" class=example>7. make过程</pre>
<pre style="LINE-HEIGHT: normal" class=example> </pre>
<pre style="LINE-HEIGHT: normal" class=example>[autoconfig.h] -.<br style="FONT: 12px song, Verdana">                     +--&gt; make* ---&gt;  程序<br style="FONT: 12px song, Verdana">        Makefile   ---'</pre>
<pre style="LINE-HEIGHT: normal" class=example> </pre>
<pre style="LINE-HEIGHT: normal" class=example>.---------,<br style="FONT: 12px song, Verdana">                   config.site - - -&gt;|         |<br style="FONT: 12px song, Verdana">                  config.cache - - -&gt;|<strong style="LINE-HEIGHT: normal"><u style="LINE-HEIGHT: normal">configure</u></strong>| - - -&gt; config.cache<br style="FONT: 12px song, Verdana">                                     |         +-,<br style="FONT: 12px song, Verdana">                                     `-+-------' |<br style="FONT: 12px song, Verdana">                                       |         |----&gt; config.status<br style="FONT: 12px song, Verdana">                   config.h.in -------&gt;|config-  |----&gt; config.h<br style="FONT: 12px song, Verdana">                   Makefile.in -------&gt;|  .status|----&gt; Makefile<br style="FONT: 12px song, Verdana">                                       |         |----&gt; stamp-h<br style="FONT: 12px song, Verdana">                                       |         +--,<br style="FONT: 12px song, Verdana">                                     .-+         |  |<br style="FONT: 12px song, Verdana">                                     | `------+--'  |<br style="FONT: 12px song, Verdana">                   ltmain.sh -------&gt;|ltconfig|-------&gt; libtool<br style="FONT: 12px song, Verdana">                                     |        |     |<br style="FONT: 12px song, Verdana">                                     `-+------'     |<br style="FONT: 12px song, Verdana">                                       |config.guess|<br style="FONT: 12px song, Verdana">                                       | config.sub |<br style="FONT: 12px song, Verdana">                                       `------------'
<p style="FONT: 12px song, Verdana"> </p>
<pre style="LINE-HEIGHT: normal">.--------,<br style="FONT: 12px song, Verdana">                   Makefile ------&gt;|        |<br style="FONT: 12px song, Verdana">                   config.h ------&gt;|  <strong style="LINE-HEIGHT: normal"><u style="LINE-HEIGHT: normal">make</u></strong>  |<br style="FONT: 12px song, Verdana">{project sources} ----------------&gt;|        |--------&gt; {project targets}<br style="FONT: 12px song, Verdana">                                 .-+        +--,<br style="FONT: 12px song, Verdana">                                 | `--------'  |<br style="FONT: 12px song, Verdana">                                 |   libtool   |<br style="FONT: 12px song, Verdana">                                 |   missing   |<br style="FONT: 12px song, Verdana">                                 |  install-sh |<br style="FONT: 12px song, Verdana">                                 |mkinstalldirs|<br style="FONT: 12px song, Verdana">                                 `-------------'</pre>
</pre>
<font style="LINE-HEIGHT: normal" color=#ff0000>实例</font>：<br style="FONT: 12px song, Verdana">在/hello/目录下创建一个hello.c文件，并编译运行它：
<p style="FONT: 12px song, Verdana">#cd /hello/</p>
<p style="FONT: 12px song, Verdana">(1) 编写源文件hello.c：</p>
<p style="FONT: 12px song, Verdana">#include&lt;stdio.h&gt;&nbsp;<br style="FONT: 12px song, Verdana">int main(int argc, char** argv)<br style="FONT: 12px song, Verdana">{<br style="FONT: 12px song, Verdana">printf("Hello, GNU!n");<br style="FONT: 12px song, Verdana">return 0;<br style="FONT: 12px song, Verdana">}</p>
<p style="FONT: 12px song, Verdana">[litao@vm0000131 hello]$ ll<br style="FONT: 12px song, Verdana">total 4<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao 68 Aug 12 12:02 hello.c</p>
<p style="FONT: 12px song, Verdana">一、autoscan</p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ autoscan</font><br style="FONT: 12px song, Verdana">autom4te: configure.ac: no such file or directory<br style="FONT: 12px song, Verdana">autoscan: /usr/bin/autom4te failed with exit status: 1<br style="FONT: 12px song, Verdana">[litao@vm0000131 hello]$ ll<br style="FONT: 12px song, Verdana">total 8<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp; 0 Aug 12 12:03 autoscan.log<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao 457 Aug 12 12:03 configure.scan<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp; 68 Aug 12 12:02 hello.c</p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>已经生成了configure.scan，autoscan.log文件</font></p>
<p style="FONT: 12px song, Verdana"><span style="LINE-HEIGHT: normal">将configure.scan 修改为&nbsp;<span style="LINE-HEIGHT: normal" class=IL_SPAN>configure</span>.in，最后修改的内容如下：</span></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000><font style="LINE-HEIGHT: normal" color=#000000><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ mv configure.scan configure.in&nbsp;&nbsp;</font>&nbsp;&nbsp;<br style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ vim configure.in</font>&nbsp;<br style="FONT: 12px song, Verdana"></font></font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000><font style="LINE-HEIGHT: normal" color=#000000>#&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -*- Autoconf -*-<br style="FONT: 12px song, Verdana"># Process this file with autoconf to produce a configure script.<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">AC_PREREQ(2.59)<br style="FONT: 12px song, Verdana">AC_INIT(FULL-PACKAGE-NAME, VERSION, BUG-REPORT-ADDRESS)<br style="FONT: 12px song, Verdana">AC_CONFIG_SRCDIR([hello.c])<br style="FONT: 12px song, Verdana">#AC_CONFIG_HEADER([config.h])<br style="FONT: 12px song, Verdana">AM_INIT_AUTOMAKE(hello, 1.0)<br style="FONT: 12px song, Verdana"># Checks for programs.<br style="FONT: 12px song, Verdana">AC_PROG_CC<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana"># Checks for libraries.<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana"># Checks for header files.<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana"># Checks for typedefs, structures, and compiler characteristics.<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana"># Checks for library functions.<br style="FONT: 12px song, Verdana">AC_OUTPUT(Makefile)</font></font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000><font style="LINE-HEIGHT: normal" color=#000000>二、acloacl</font><br style="FONT: 12px song, Verdana"></font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ aclocal&nbsp;<br style="FONT: 12px song, Verdana"></font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>生成 aclocal.m4 和 autom4te.cache (生成aclocal.m4的过程中涉及到configure.in)</font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000><font style="LINE-HEIGHT: normal" color=#000000>[litao@vm0000131 hello]$ ll<br style="FONT: 12px song, Verdana">total 44<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4<br style="FONT: 12px song, Verdana">drwxr-xr-x 2 litao litao&nbsp; 4096 Aug 12 12:08 autom4te.cache<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 0 Aug 12 12:03 autoscan.log<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp; 496 Aug 12 12:08 configure.in<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp; 68 Aug 12 12:02 hello.c</font></font></p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000><font style="LINE-HEIGHT: normal" color=#000000>三、antoconf<br style="FONT: 12px song, Verdana"></font></font></p>
<font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ autoconf<br style="FONT: 12px song, Verdana"><span style="LINE-HEIGHT: normal">生成&nbsp;<span style="LINE-HEIGHT: normal" class=IL_SPAN>configure</span>&nbsp;(根据&nbsp;<span style="LINE-HEIGHT: normal" class=IL_SPAN>configure</span>.in, 和 aclocal.m4)</span></font><br style="FONT: 12px song, Verdana">[litao@vm0000131 hello]$ ll<br style="FONT: 12px song, Verdana">total 168<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp; 31120 Aug 12 12:08 aclocal.m4<br style="FONT: 12px song, Verdana">drwxr-xr-x 2 litao litao&nbsp;&nbsp; 4096 Aug 12 12:11 autom4te.cache<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 Aug 12 12:03 autoscan.log<br style="FONT: 12px song, Verdana">-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp; 496 Aug 12 12:08 configure.in<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 68 Aug 12 12:02 hello.c<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">四、编写Makefile.am：
<p style="FONT: 12px song, Verdana">AUTOMAKE_OPTIONS= foreign<br style="FONT: 12px song, Verdana">bin_PROGRAMS= hello<br style="FONT: 12px song, Verdana">hello_SOURCES= hello.c</p>
五、automake
<p style="FONT: 12px song, Verdana">生成 Makefile.in， depcomp， install-sh， 和 missing (根据 Makefile.am, 和 aclocal.m4)</p>
<p style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ automake</font><br style="FONT: 12px song, Verdana">configure.in: required file `./install-sh' not found<br style="FONT: 12px song, Verdana">configure.in: required file `./missing' not found<br style="FONT: 12px song, Verdana">Makefile.am: required file `./depcomp' not found<br style="FONT: 12px song, Verdana"><font style="LINE-HEIGHT: normal" color=#ff0000>[litao@vm0000131 hello]$ automake --add-missing</font><br style="FONT: 12px song, Verdana">configure.in: installing `./install-sh'<br style="FONT: 12px song, Verdana">configure.in: installing `./missing'<br style="FONT: 12px song, Verdana">Makefile.am: installing `./depcomp'<br style="FONT: 12px song, Verdana">[litao@vm0000131 hello]$ ll<br style="FONT: 12px song, Verdana">total 192<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp; 31120 Aug 12 12:08 aclocal.m4<br style="FONT: 12px song, Verdana">drwxr-xr-x 2 litao litao&nbsp;&nbsp; 4096 Aug 12 12:14 autom4te.cache<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0 Aug 12 12:03 autoscan.log<br style="FONT: 12px song, Verdana">-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11 configure<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp; 496 Aug 12 12:08 configure.in<br style="FONT: 12px song, Verdana">lrwxrwxrwx 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 31 Aug 12 12:16 depcomp -&gt; /usr/share/automake-1.9/depcomp<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 68 Aug 12 12:02 hello.c<br style="FONT: 12px song, Verdana">lrwxrwxrwx 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 34 Aug 12 12:16 install-sh -&gt; /usr/share/automake-1.9/install-sh<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 69 Aug 12 12:15 Makefile.am<br style="FONT: 12px song, Verdana">-rw-rw-r-- 1 litao litao&nbsp; 16561 Aug 12 12:16 Makefile.in<br style="FONT: 12px song, Verdana">lrwxrwxrwx 1 litao litao&nbsp;&nbsp;&nbsp;&nbsp; 31 Aug 12 12:16 missing -&gt; /usr/share/automake-1.9/missing</p>
<p style="FONT: 12px song, Verdana">六、configure<br style="FONT: 12px song, Verdana">生成 Makefile， config.log， 和 config.status</p>
<p style="FONT: 12px song, Verdana"><font class=Apple-style-span size=4><span style="LINE-HEIGHT: 18px; FONT-SIZE: 14px; FONT-WEIGHT: bold; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px" class=Apple-style-span>生成makefile整个过程</span></font></p>
<p style="FONT: 12px song, Verdana"><span style="LINE-HEIGHT: 20px" class=Apple-style-span><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>configure.in ：<br style="FONT: 12px song, Verdana"></span></font></span><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>configure.in</span></font></span><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>文件内容是一系列GNU m4 的宏，这些宏经autoconf处理后会变成检查系统特性的shell scripts。 configure.in 内宏的顺序并没有特别的规定，但是每一个configure.in 文件必須在所有宏前加入 AC_INIT 宏，然后在所有宏的最后加上 AC_OUTPUT宏。可先用 autoscan 扫描原始文件以产生一个 configure.scan 文件，再对 configure.scan 做些修改成 configure.in 文件。</span></font></span><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>在范例中所用到的宏如下：<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">dnl&nbsp;<br style="FONT: 12px song, Verdana">这个宏后面的字不会被处理，可以视为注释&nbsp;<br style="FONT: 12px song, Verdana"></span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>AC_INIT(FILE)&nbsp;</span></font><span style="FONT-SIZE: small" class=Apple-style-span><br style="FONT: 12px song, Verdana">该宏用来检查源代码所在路径，autoscan 会自动产生，一般无须修改它。&nbsp;<br style="FONT: 12px song, Verdana"></span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>AM_INIT_AUTOMAKE(PACKAGE,VERSION)&nbsp;</span></font><span style="FONT-SIZE: small" class=Apple-style-span><br style="FONT: 12px song, Verdana">这个是使用 Automake 所</span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>必备的宏</span></font><span style="FONT-SIZE: small" class=Apple-style-span>，PACKAGE 是所要产生软件套件的名称，VERSION 是版本编号。&nbsp;<br style="FONT: 12px song, Verdana">AC_PROG_CC&nbsp;<br style="FONT: 12px song, Verdana">检查系统可用的C编译器，若源代码是用C写的就需要这个宏。&nbsp;<br style="FONT: 12px song, Verdana">AC_OUTPUT(FILE)&nbsp;<br style="FONT: 12px song, Verdana">设置 configure 所要产生的文件，若是</span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>Makefile</span></font><span style="FONT-SIZE: small" class=Apple-style-span>&nbsp;，configure 便会把它检查出来的结果带入&nbsp; Makefile.in 文件后产生合适的 Makefile。&nbsp;<br style="FONT: 12px song, Verdana">实际上，这里使用 Automake 时，还需要一些其他的宏，这些额外的宏我们用 aclocal来帮助产生。執行 aclocal会产生aclocal.m4 文件，如果无特别的用途，可以不需要修改它，用 aclocal 所产生的宏会告诉 Automake如何动作。&nbsp;<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">有了 configure.in 及 aclocal.m4两个文件以后，便可以执行 autoconf来产生 configure 文件了。<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana"></span></font></span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>Makefile.am</span></font></span></font><span style="FONT-SIZE: small" class=Apple-style-span><br style="FONT: 12px song, Verdana"></span><span style="LINE-HEIGHT: normal"><font style="LINE-HEIGHT: normal"><span style="FONT-SIZE: small" class=Apple-style-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Automake 会根据 configure.in 中的宏把Makefile.am 转成 Makefile.in 文件。 Makefile.am 文件定义所要产生的目标：&nbsp;<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">AUTOMAKE_OPTIONS&nbsp;<br style="FONT: 12px song, Verdana">设置 automake 的选项。<br style="FONT: 12px song, Verdana">Automake 主要是帮助开发 GNU 软件的人员来维护软件，所以在执行 automake 时，会检查目录下是否存在标准 GNU 软件中应具备的文件，例如 'NEWS'、'AUTHOR'、'ChangeLog' 等文件。</span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>设置 foreign 时，automake 会改用一般软件的标准来检查。&nbsp;</span></font><span style="FONT-SIZE: small" class=Apple-style-span><br style="FONT: 12px song, Verdana">bin_PROGRAMS&nbsp;<br style="FONT: 12px song, Verdana">定义要产生的执行文件名。如果要产生多个执行文件，每个文件名用空白符隔开。&nbsp;<br style="FONT: 12px song, Verdana">hello_SOURCES&nbsp;<br style="FONT: 12px song, Verdana">定义&nbsp;</span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>'hello' 这个执行程序</span></font><span style="FONT-SIZE: small" class=Apple-style-span>所需要的原始文件。如果 'hello'这个程序是由多个原始文件所产生，必須把它所用到的所有原始文件都列出来，以空白符隔开。假设 'hello' 还需要 'hello.c'、'main.c'、'hello.h' 三个文件的话，则定义&nbsp;<br style="FONT: 12px song, Verdana">hello_SOURCES= hello.c main.c hello.h&nbsp;<br style="FONT: 12px song, Verdana">如果定义多个执行文件，则对每个执行程序都要定义相对的filename_SOURCES。&nbsp;<br style="FONT: 12px song, Verdana"><br style="FONT: 12px song, Verdana">编辑好 Makefile.am 文件，就可以用</span><font style="LINE-HEIGHT: normal" color=#ff0000><span style="FONT-SIZE: small" class=Apple-style-span>&nbsp;automake --add-missing</span></font><span style="FONT-SIZE: small" class=Apple-style-span>来产生 Makefile.in。加上 --add-missing 选项来告诉 automake顺便假如包装一个软件所必须的文件。Automake产生生出來的 Makefile.in 文件是完全符合 GNU Makefile 的惯例，只要执行 configure这个shell script 便可以产生合适的 Makefile 文件了。&nbsp;</span></font></span></span></p>
<br>转自：<br><a href="http://blog.chinaunix.net/u2/76292/showart.php?id=2099939">http://blog.chinaunix.net/u2/76292/showart.php?id=2099939</a><br><br>
<img src ="http://www.cppblog.com/beautykingdom/aggbug/101566.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/beautykingdom/" target="_blank">chatler</a> 2009-11-21 18:33 <a href="http://www.cppblog.com/beautykingdom/archive/2009/11/21/101566.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>