﻿<?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++博客-RTY 实践出真知-随笔分类-Linux</title><link>http://www.cppblog.com/lauer3912/category/16487.html</link><description>没有理由不学习</description><language>zh-cn</language><lastBuildDate>Thu, 19 Apr 2012 01:15:03 GMT</lastBuildDate><pubDate>Thu, 19 Apr 2012 01:15:03 GMT</pubDate><ttl>60</ttl><item><title>@executable path, @load path and @rpath</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/18/171814.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 17 Apr 2012 22:14:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/18/171814.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/171814.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/18/171814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/171814.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/171814.html</trackback:ping><description><![CDATA[<h1>@executable path, @load path and @rpath</h1> <div> <span title="2010年11月6日 02:26:36">2010年11月6日</span> by <a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#119;&#105;&#110;&#64;&#119;&#105;&#110;&#99;&#101;&#110;&#116;&#46;&#99;&#111;&#109;">Wincent Colaiuta</a> </div>  <div> <p><strong>Note:</strong> <em>this article is actually about the <code>@executable_path</code>, <code>@load_path</code> and <code>@rpath</code> install paths used by the linker on <a href="https://wincent.com/wiki/Mac_OS_X">Mac OS X</a>; wiki titles can't include underscores, however, because they are ambiguous with spaces.</em></p> <h2>Absolute paths</h2> <p>Useful for frameworks installed in shared locations. Example:</p> <ul> <li>Install path: <code>/Library/Frameworks/Foo.framework/Versions/A/Foo</code></li> </ul> <h2><code>@executable_path</code></h2> <p>Useful for frameworks embedded inside applications, because it allows  you to specify the location of the framework relative to the  application's executable:</p> <ul> <li>Install path: <code>@executable_path/../Frameworks/Foo.framework/Versions/A/Foo</code></li> <li>Application location: <code>/Applications/Foo.app</code></li> <li>Executable path: <code>/Applications/Foo.app/Contents/MacOS</code></li> <li>Framework location: <code>/Applications/Foo.app/Contents/Frameworks/Foo.framework</code></li> <li>Linker puts all this together to figure out that the framework binary can be found at: <code>/Applications/Foo.app/Contents/MacOS/../Frameworks/Foo.framework/Versions/A/Foo</code></li> </ul> <h2>@loader_path</h2> <p>Available from <a href="https://wincent.com/wiki/Mac_OS_X">Mac OS X</a> 10.4 <a href="https://wincent.com/wiki/Tiger">Tiger</a>  onwards; useful for frameworks embedded inside plug-ins, because it  allows you to specify the location of the framework relative to the  plug-in's code (remember, plug-ins may not actually know where they are  going to be installed, relative to the application, so knowing <code>@executable_path</code> doesn't help us in this case):</p> <ul> <li>Install path: <code>@loader_path/../Frameworks/Foo.framework/Versions/A/Foo</code></li> <li>Application location: <code>/Applications/Foo.app</code></li> <li>Plug-in location: <code>/Library/Application Support/Foo/Plug-Ins/Bar.bundle</code></li> <li>Executable path: <code>/Applications/Foo.app/Contents/MacOS</code></li> <li>Loader path: <code>/Library/Application Support/Foo/Plug-Ins/Bar.bundle/Contents/MacOS</code></li> <li>Framework location: <code>/Library/Application Support/Foo/Plug-Ins/Bar.bundle/Contents/Frameworks/Foo.framework</code></li> <li>Linker puts all this together to figure out that the framework binary can be found at: <code>/Library/Application Support/Foo/Plug-Ins/Bar.bundle/Contents/MacOS/../Frameworks/Foo.framework/Versions/A/Foo</code></li> </ul> <p>Note that if the "loader" is an application rather than a plug-in, the <code>@loader_path</code> ends up being equivalent to <code>@executable_path</code>.</p> <h2><code>@rpath</code></h2> <p>New in <a href="https://wincent.com/wiki/Mac_OS_X">Mac OS X</a> 10.5 <a href="https://wincent.com/wiki/Leopard">Leopard</a> is <code>@rpath</code>. Key points:</p> <ul> <li><code>@rpath</code> instructs the dynamic linker to search a list of paths in order to locate the framework</li> <li>critically, this list is embedded in the loading application</li> <li>this means that a single framework with <code>@rpath/Foo.framework/Versions/A/Foo</code>  can be made to work in a number of different ways; that is, you are  effectively no longer limited by the choice of specifying your "install  path" using <em>either</em> <code>@executable_path</code> <em>or</em> <code>@loader_path</code></li> <li>the down side: you now have to pass additional linker flags when building the host application (eg. <code>-rpath @executable_path/../Frameworks</code> or <code>/Library/Frameworks</code>; note that specifying <em>both</em> will cause the dynamic linker to try looking in both locations)</li> </ul> <h2>Sources</h2> <ul> <li>Nice overview: <a href="http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html">http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html</a></li> <li>Docs for using PFiddlesoft Frameworks (I've never used these, but  the manual itself makes some nice general points about using  frameworks): <a href="http://pfiddlesoft.com/frameworks/downloads/Assistive_Application_Programming_Guide.pdf">http://pfiddlesoft.com/frameworks/downloads/Assistive_Application_Programming_Guide.pdf</a></li> </ul>  </div> <div> <h2>Tags</h2> <a href="https://wincent.com/tags/mac.os.x" style="font-size: 1.3244274809160306em;" title="85 items tagged with 'mac.os.x'">mac.os.x</a> <a href="https://wincent.com/tags/dynamic.linker" style="font-size: 1.0038167938931297em;" title="1 item tagged with 'dynamic.linker'">dynamic.linker</a></div><img src ="http://www.cppblog.com/lauer3912/aggbug/171814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-18 06:14 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/18/171814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Configure，Makefile.am, Makefile.in, Makefile文件之间关系</title><link>http://www.cppblog.com/lauer3912/archive/2012/04/03/169966.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 03 Apr 2012 14:20:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/04/03/169966.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/169966.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/04/03/169966.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/169966.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/169966.html</trackback:ping><description><![CDATA[<div>Configure，Makefile.am, Makefile.in, Makefile文件之间关系</div> <div>2009-08-12 12:14</div> <table style="width: 100%; table-layout: fixed"> <tbody> <tr> <td> <div id="blog_text"><span style="line-height: 18px; "> <div style="position: static; filter: none; line-height: 20px; word-wrap: break-word; visibility: visible !important; color: #333333; font-size: 14px; overflow-x: hidden; overflow-y: hidden; border-image: initial; "> <p style="line-height: normal"><img border="0" src="http://hiphotos.baidu.com/litaosmile/pic/item/55a6d229122935d798250aa4.jpg" small="0"  alt="" /></p> <p style="line-height: normal">1.autoscan (autoconf):  扫描源代码以搜寻普通的可移植性问题，比如检查编译器，库，头文件等，生成文件configure.scan,它是configure.ac的一个雏形。</p> <p style="line-height: normal">    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">user input files   optional input     process          output files<br />================   ==============     =======          ============<br /><br />                    acinclude.m4 - - - - -.<br />                                          V<br />                                      .-------,<br />configure.ac ------------------------&gt;|aclocal|<br />                 {user macro files} -&gt;|       |------&gt; aclocal.m4<br />                                      `-------'<br />3.autoheader(autoconf): 根据configure.ac中的某些宏，比如cpp宏定义，运行m4，声称config.h.in<br /><br />user input files    optional input     process          output files<br />================    ==============     =======          ============<br /><br />                    aclocal.m4 - - - - - - - .<br />                                             |<br />                                             V<br />                                     .----------,<br />configure.ac -----------------------&gt;|autoheader|----&gt; autoconfig.h.in<br />                                     `----------'</pre> <p style="line-height: normal">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">user input files   optional input   processes          output files<br />================   ==============   =========          ============<br /><br />                                     .--------,<br />                                     |        | - - -&gt; COPYING<br />                                     |        | - - -&gt; INSTALL<br />                                     |        |------&gt; install-sh<br />                                     |        |------&gt; missing<br />                                     |automake|------&gt; mkinstalldirs<br />configure.ac -----------------------&gt;|        |<br />Makefile.am  -----------------------&gt;|        |------&gt; Makefile.in<br />                                     |        |------&gt; stamp-h.in<br />                                 .---+        | - - -&gt; config.guess<br />                                 |   |        | - - -&gt; config.sub<br />                                 |   `------+-'<br />                                 |          | - - - -&gt; config.guess<br />                                 |libtoolize| - - - -&gt; config.sub<br />                                 |          |--------&gt; ltmain.sh<br />                                 |          |--------&gt; ltconfig<br />                                 `----------'</pre> <p style="line-height: normal">5.autoconf:将configure.ac中的宏展开，生成configure脚本。这个过程可能要用到aclocal.m4中定义的宏。</p><pre style="line-height: normal">user input files   optional input   processes          output files<br />================   ==============   =========          ============<br /><br />aclocal.m4 ,autoconfig.h.in - - - - - - -.<br />                                         V<br />                                     .--------,<br />configure.ac -----------------------&gt;|autoconf|------&gt; configure</pre><pre style="line-height: normal"> </pre><pre style="line-height: normal">6. ./configure的过程</pre><pre style="line-height: normal"><br />                                           .-------------&gt; [config.cache]<br />     configure* --------------------------+-------------&gt; config.log<br />                                          |<br />              [config.h.in] -.            v            .--&gt; [autoconfig.h]<br />                             +-------&gt; config.status* -+                   <br />              Makefile.in ---'                         `--&gt;   Makefile</pre><pre style="line-height: normal"> </pre><pre style="line-height: normal">7. make过程</pre><pre style="line-height: normal"> </pre><pre style="line-height: normal">[autoconfig.h] -.<br />                     +--&gt; make* ---&gt;  程序<br />        Makefile   ---'</pre><pre style="line-height: normal"> </pre><pre style="line-height: normal">.---------,<br />                   config.site - - -&gt;|         |<br />                  config.cache - - -&gt;|<strong><u>configure</u></strong>| - - -&gt; config.cache<br />                                     |         +-,<br />                                     `-+-------' |<br />                                       |         |----&gt; config.status<br />                   config.h.in -------&gt;|config-  |----&gt; config.h<br />                   Makefile.in -------&gt;|  .status|----&gt; Makefile<br />                                       |         |----&gt; stamp-h<br />                                       |         +--,<br />                                     .-+         |  |<br />                                     | `------+--'  |<br />                   ltmain.sh -------&gt;|ltconfig|-------&gt; libtool<br />                                     |        |     |<br />                                     `-+------'     |<br />                                       |config.guess|<br />                                       | config.sub |<br />                                       `------------'<p> </p><pre>.--------,<br />                   Makefile ------&gt;|        |<br />                   config.h ------&gt;|  <strong><u>make</u></strong>  |<br />{project sources} ----------------&gt;|        |--------&gt; {project targets}<br />                                 .-+        +--,<br />                                 | `--------'  |<br />                                 |   libtool   |<br />                                 |   missing   |<br />                                 |  install-sh |<br />                                 |mkinstalldirs|<br />                                 `-------------'</pre> </pre></div></span>实例：<br />在/hello/目录下创建一个hello.c文件，并编译运行它：  <p>#cd /hello/</p> <p>(1) 编写源文件hello.c：</p> <p>#include&lt;stdio.h&gt; <br />int main(int argc, char**  argv)<br />{<br />printf("Hello, GNU!n");<br />return 0;<br />}</p> <p>[litao@vm0000131 hello]$ ll<br />total 4<br />-rw-rw-r-- 1 litao litao 68 Aug 12  12:02 hello.c</p> <p>一、autoscan</p> <p>[litao@vm0000131 hello]$ autoscan<br />autom4te:  configure.ac: no such file or directory<br />autoscan: /usr/bin/autom4te failed  with exit status: 1<br />[litao@vm0000131 hello]$ ll<br />total 8<br />-rw-rw-r-- 1  litao litao   0 Aug 12 12:03 autoscan.log<br />-rw-rw-r-- 1 litao litao 457 Aug 12  12:03 configure.scan<br />-rw-rw-r-- 1 litao litao  68 Aug 12 12:02 hello.c</p> <p>已经生成了configure.scan，autoscan.log文件</p> <p>将configure.scan 修改为 configure.in，最后修改的内容如下：</p> <p>[litao@vm0000131  hello]$ mv configure.scan configure.in    <br />[litao@vm0000131 hello]$ vim configure.in  <br /></p> <p>#                                               -*- Autoconf  -*-<br /># Process this file with autoconf to produce a configure  script.<br /><br />AC_PREREQ(2.59)<br />AC_INIT(FULL-PACKAGE-NAME, VERSION,  BUG-REPORT-ADDRESS)<br />AC_CONFIG_SRCDIR([hello.c])<br />#AC_CONFIG_HEADER([config.h])<br />AM_INIT_AUTOMAKE(hello,  1.0)<br /># Checks for programs.<br />AC_PROG_CC<br /><br /># Checks for  libraries.<br /><br /># Checks for header files.<br /><br /># Checks for typedefs,  structures, and compiler characteristics.<br /><br /># Checks for library  functions.<br />AC_OUTPUT(Makefile)</p> <p>二、acloacl<br /></p> <p>[litao@vm0000131 hello]$ aclocal <br /></p> <p>生成 aclocal.m4 和 autom4te.cache  (生成aclocal.m4的过程中涉及到configure.in)</p> <p>[litao@vm0000131 hello]$ ll<br />total  44<br />-rw-rw-r-- 1 litao litao 31120 Aug 12 12:08 aclocal.m4<br />drwxr-xr-x 2  litao litao  4096 Aug 12 12:08 autom4te.cache<br />-rw-rw-r-- 1 litao litao     0  Aug 12 12:03 autoscan.log<br />-rw-rw-r-- 1 litao litao   496 Aug 12 12:08  configure.in<br />-rw-rw-r-- 1 litao litao    68 Aug 12 12:02  hello.c</p> <p>三、antoconf<br /></p>[litao@vm0000131 hello]$ autoconf<br />生成 configure (根据 configure.in, 和  aclocal.m4)<br />[litao@vm0000131 hello]$ ll<br />total  168<br />-rw-rw-r-- 1 litao litao  31120 Aug 12 12:08 aclocal.m4<br />drwxr-xr-x 2  litao litao   4096 Aug 12 12:11 autom4te.cache<br />-rw-rw-r-- 1 litao litao       0 Aug 12 12:03 autoscan.log<br />-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11  configure<br />-rw-rw-r-- 1 litao litao    496 Aug 12 12:08  configure.in<br />-rw-rw-r-- 1 litao litao     68 Aug 12 12:02  hello.c<br /><br />四、编写Makefile.am：  <p>AUTOMAKE_OPTIONS= foreign<br />bin_PROGRAMS= hello<br />hello_SOURCES=  hello.c</p>五、automake  <p>生成 Makefile.in， depcomp， install-sh， 和 missing (根据 Makefile.am, 和  aclocal.m4)</p> <p>[litao@vm0000131 hello]$ automake<br />configure.in:  required file `./install-sh' not found<br />configure.in: required file  `./missing' not found<br />Makefile.am: required file `./depcomp' not  found<br />[litao@vm0000131 hello]$ automake  --add-missing<br />configure.in: installing `./install-sh'<br />configure.in:  installing `./missing'<br />Makefile.am: installing  `./depcomp'<br />[litao@vm0000131 hello]$ ll<br />total 192<br />-rw-rw-r-- 1 litao  litao  31120 Aug 12 12:08 aclocal.m4<br />drwxr-xr-x 2 litao litao   4096 Aug 12  12:14 autom4te.cache<br />-rw-rw-r-- 1 litao litao      0 Aug 12 12:03  autoscan.log<br />-rwxrwxr-x 1 litao litao 122297 Aug 12 12:11  configure<br />-rw-rw-r-- 1 litao litao    496 Aug 12 12:08  configure.in<br />lrwxrwxrwx 1 litao litao     31 Aug 12 12:16 depcomp -&gt;  /usr/share/automake-1.9/depcomp<br />-rw-rw-r-- 1 litao litao     68 Aug 12 12:02  hello.c<br />lrwxrwxrwx 1 litao litao     34 Aug 12 12:16 install-sh -&gt;  /usr/share/automake-1.9/install-sh<br />-rw-rw-r-- 1 litao litao     69 Aug 12  12:15 Makefile.am<br />-rw-rw-r-- 1 litao litao  16561 Aug 12 12:16  Makefile.in<br />lrwxrwxrwx 1 litao litao     31 Aug 12 12:16 missing -&gt;  /usr/share/automake-1.9/missing</p> <p>六、configure<br />生成 Makefile， config.log， 和 config.status</p> <p><br /></p></div></td></tr></tbody></table><div id="in_reader"><table width="100%"><tbody><tr><td><br /></td><td><br /></td><td valign="top" align="center" style="text-align: -webkit-auto;"><span style="font-size: 14px; line-height: 21px;"><br /></span></td> <td valign="top" align="center"><a href="http://hi.baidu.com/%E7%AB%B9%E6%9E%97%E8%8B%B1%E5%AE%A2" target="_blank" pid="9ea3d6f1c1d6d3a2bfcd0508">竹林英客</a></td> <td valign="top" align="center"><a href="http://hi.baidu.com/zxjlwt" target="_blank" pid="99bb7a786a6c7774d201">zxjlwt</a></td> <td valign="top" align="center"><a href="http://hi.baidu.com/luckyltq" target="_blank" pid="ceec6a617a656c74715b02">jazeltq</a></td></tr></tbody></table></div><img src ="http://www.cppblog.com/lauer3912/aggbug/169966.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-04-03 22:20 <a href="http://www.cppblog.com/lauer3912/archive/2012/04/03/169966.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux 终端中常用的快捷键</title><link>http://www.cppblog.com/lauer3912/archive/2012/03/01/166872.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Thu, 01 Mar 2012 07:02:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2012/03/01/166872.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/166872.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2012/03/01/166872.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/166872.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/166872.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 1. 移动光标快捷键ctrl+f 向前移动一个字符ctrl+b 向后移动一个字符alt+f 向前移动一个单词alt+b 向后移动一个单词ctrl+a 移动到当前行首ctrl+e 移动到当前行尾ctrl+l 清屏，并在屏幕最上面开始一个新行 2. 编辑命令行快捷键ctrl+d 删除当前的字符ctrl+t 交换当前字符和前一个字符的位置alt+t 交换当前单词和前一个单词的位置alt+u 把当前单词变...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2012/03/01/166872.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/166872.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2012-03-01 15:02 <a href="http://www.cppblog.com/lauer3912/archive/2012/03/01/166872.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>KBuild MakeFile介绍</title><link>http://www.cppblog.com/lauer3912/archive/2011/07/21/151523.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Wed, 20 Jul 2011 23:24:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/07/21/151523.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/151523.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/07/21/151523.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/151523.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/151523.html</trackback:ping><description><![CDATA[<span class="Apple-style-span" style="font-family: song, Verdana; font-size: 12px; line-height: normal; background-color: #f0f3fa; "><table cellspacing="0" cellpadding="0" style="word-wrap: break-word; empty-cells: show; border-collapse: collapse; line-height: normal; width: 1009px; table-layout: fixed; margin-left: 1px; "><tbody style="word-wrap: break-word; line-height: normal; "><tr style="word-wrap: break-word; line-height: normal; "><td class="t_msgfont" id="postmessage_14162165" style="word-wrap: break-word; color: #000000; font: normal normal normal 12px/normal song, Verdana; line-height: 1.6em; font-size: 14px; "><br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; 从Linux内核2.6开始，<font color="#0000ff" style="word-wrap: break-word; line-height: normal; ">Linux内核的编译采用Kbuild<span href="tag.php?name=%CF%B5%CD%B3" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">系统</span></font>，这同过去的编译系统有很大的不同，尤其对于Linux内核模块的编译。<font color="#0000ff" style="word-wrap: break-word; line-height: normal; ">在新的系统下，Linux编译系统会两次扫描Linux的Makefile：首先编译系统会读取Linux内核顶层的Makefile，然后根据读到的内容第二次读取Kbuild的Makefile来编译Linux内核。</font><br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Linux</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">内核Makefile分类</strong><br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><font color="#ff0000" style="word-wrap: break-word; line-height: normal; ">Kernel Makefile</font>&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />Kernel Makefile位于Linux内核源代码的顶层目录，也叫 Top Makefile。它主要用于指定编译Linux Kernel目标<span href="tag.php?name=%CE%C4%BC%FE" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">文件</span>（vm<span href="tag.php?name=linux" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">linux</span>）和模块（module）。这编译内核或模块是，这个文件会被首先读取，并根据读到的内容配置编译环境变量。对于内核或驱动<span href="tag.php?name=%BF%AA%B7%A2" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">开发</span>人员来说，这个文件几乎不用任何修改。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><font color="#ff0000" style="word-wrap: break-word; line-height: normal; ">Kbuild Makefile</font>&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />Kbuild系统使用Kbuild Makefile来编译内核或模块。当Kernel Makefile被解析完成后，Kbuild会读取相关的Kbuild Makefile进行内核或模块的编译。Kbuild Makefile有特定的语法指定哪些编译进内核中、哪些编译为模块、及对应的源文件是什么等。内核及驱动开发人员需要编写这个Kbuild Makefile文件。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><font color="#ff0000" style="word-wrap: break-word; line-height: normal; ">ARCH Makefile</font>&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />ARCH Makefile位于ARCH/$(ARCH)/Makefile，是系统对应平台的Makefile。Kernel Top Makefile会包含这个文件来指定平台相关信息。只有平台开发人员会关心这个文件。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Kbuild Makefile</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; Kbuild Makefile的文件名不一定是<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Makefile</strong>，尽管推荐使用Makefile这个名字。大多的Kbuild文件的名字都是Makefile。为了与其他Makefile文件相区别，你也可以指定Kbuild Makefile的名字为<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Kbuild</strong>。而且如果&#8220;Makefile&#8221;和&#8220;Kbuild&#8221;文件同时存在，则Kbuild系统会使用&#8220;Kbuild&#8221;文件。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">目标定义&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />Kbuild Makefile的一个最主要功能就是指定编译什么，这个功能是通过下面两个对象指定的obj-?和xxx-objs：<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">obj-?</strong><br style="word-wrap: break-word; line-height: normal; " />obj-?指定编译什么，怎么编译？其中的&#8220;?&#8221;可能是&#8220;y&#8221;或&#8220;m&#8221;，&#8220;y&#8221;指定把对象编译进内核中，&#8220;m&#8221;指定把对象编译为模块。语法如下;<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; obj-? = $(target).o<br style="word-wrap: break-word; line-height: normal; " />target为编译对象的名字。如果没有指定xxx-objs，这编译这个对象需要的源文件就是$(target).c或$(target).s。如果指定了$(target)-objs，则编译这个对象需要的源文件由$(target)-objs指定，并且不能有$(target).c或$(target).s文件。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">xxx-objs&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />xxx-objs指定了编译对象需要的文件，一般只有在源文件是多个时才需要它。<br style="word-wrap: break-word; line-height: normal; " />只要包含了这两行，Kbuild Makefile就应该可以工作了。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">嵌套编译&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />有时一个对象可能嵌入到另一个对象的目录下，那个如何编译子目录下的对象呢?其实很简单，只要指定obj_?的对象为子目录的名字就可以了：<br style="word-wrap: break-word; line-height: normal; " />obj-? = $(sub_target)/<br style="word-wrap: break-word; line-height: normal; " />其中&#8220;?&#8221;可以是&#8220;y&#8221;或&#8220;m&#8221;，$(sub_target)是子目录名字。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">编译器选项&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />尽管在大多数情况下不需要指定编译器选项，有时我们还是需要指定一些编译选项的。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">ccflags-y, asflags-y and ldflags-y&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />这些编译选项用于指定cc、as和ld的编译选项<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">编译外部模块</strong><br style="word-wrap: break-word; line-height: normal; " />有时候我们需要在内核源代码数的外面编译内核模块，编译的基本命令是：<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; make -C $(KERNEL_DIR) M=`pwd` modules<br style="word-wrap: break-word; line-height: normal; " />我们可以把这个命令集成到Makefile里，这样我们就可以只输入&#8220;make&#8221;命令就可以了。回想上一章的那个Makefile，它把Normal Makefile 和Kbuild&nbsp;&nbsp;Makefile集成到一个文件中了。为了区别Kbuild Makefile 和Normal Makefile，这样我们改写Makefile为如下形式，并且添加Kbuild Makefile - &#8220;Kbuild&#8221;。<br style="word-wrap: break-word; line-height: normal; " />##Makefile<br style="word-wrap: break-word; line-height: normal; " />ifneq ($(KERNELRELEASE),)<br style="word-wrap: break-word; line-height: normal; " />include "Kbuild"<br style="word-wrap: break-word; line-height: normal; " />else<br style="word-wrap: break-word; line-height: normal; " />KERNEL_DIR = /lib/modules/`uname -r`/build<br style="word-wrap: break-word; line-height: normal; " />MODULEDIR := $(<span href="tag.php?name=shell" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">shell</span>&nbsp;pwd)<br style="word-wrap: break-word; line-height: normal; " />.PHONY: modules<br style="word-wrap: break-word; line-height: normal; " />default: modules<br style="word-wrap: break-word; line-height: normal; " />modules:<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;make -C $(KERNEL_DIR)&nbsp;&nbsp;M=$(MODULEDIR) modules<br style="word-wrap: break-word; line-height: normal; " />clean distclean:<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rm -f *.o *.mod.c .*.*.cmd *.ko<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;rm -rf .tmp_versions<br style="word-wrap: break-word; line-height: normal; " />endif<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " />## Kbuild<br style="word-wrap: break-word; line-height: normal; " />MODULE_NAME = helloworld<br style="word-wrap: break-word; line-height: normal; " />$(MODULE_NAME)-objs := hello.o<br style="word-wrap: break-word; line-height: normal; " />obj-m&nbsp; &nbsp;:= $(MODULE_NAME).o<br style="word-wrap: break-word; line-height: normal; " />一般不需要在Makefile里包含如下代码,这样写完全是为了兼容老版本的Kbuild系统。KERNELRELEASE变量在Kernel Makefile里定义的，因此只有在第二次由Kbuild读取这个Makefile文件时才会解析到Kbuild的内容。&nbsp;<br style="word-wrap: break-word; line-height: normal; " />ifneq ($(KERNELRELEASE),)<br style="word-wrap: break-word; line-height: normal; " />include "Kbuild"<br style="word-wrap: break-word; line-height: normal; " />else<br style="word-wrap: break-word; line-height: normal; " />...<br style="word-wrap: break-word; line-height: normal; " />endif<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">外部头文件</strong><br style="word-wrap: break-word; line-height: normal; " />有时需要连接内核源代码外部的系统头文件，但Kbuild系统默认的系统头文件都在内核源代码内部，如何使用外部的头文件呢？这个可以借助于Kbuild系统的特殊规则:<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">EXTRA_CFLAGS&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />EXTRA_CFLAGS可以给Kbuild系统添加外部系统头文件，<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; EXTRA_CFLAGS += $(ext_include_path)<br style="word-wrap: break-word; line-height: normal; " />一般外部头文件可能位于外部模块源文件的目录内，如何指定呢？这可以借助$(src)或$(obj)<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(src)/$(obj)&nbsp;</strong><br style="word-wrap: break-word; line-height: normal; " />$(src)是一个相对路径，它就是Makefile/Kbuild文件所在的路径。同样$(obj)就是编译目标保存的路径，默认就是源代码所在路径。<br style="word-wrap: break-word; line-height: normal; " />因此，我们修改Kbuild文件添加 EXTRA_CFLAGS 来包含外部头文件尽管在这个驱动里没有引用外部系统头文件：<br style="word-wrap: break-word; line-height: normal; " />## Kbuild<br style="word-wrap: break-word; line-height: normal; " />MODULE_NAME = helloworld<br style="word-wrap: break-word; line-height: normal; " />$(MODULE_NAME)-objs := hello.o<br style="word-wrap: break-word; line-height: normal; " />EXTRA_CFLAGS := -I$(src)/include<br style="word-wrap: break-word; line-height: normal; " />obj-m&nbsp; &nbsp;:= $(MODULE_NAME).o<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Goal definitions<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;obj-y += foo.o<br style="word-wrap: break-word; line-height: normal; " />告诉kbuild，在文件夹中又一个叫做foo.o的object。foo.o将会被从foo.c或者foo.S被构建。<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " />如果foo.o被构建成一个<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">模块</strong>，则将使用变量<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">obj-m</strong>。<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example</strong>:<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;obj-$(CONFIG_FOO) += foo.o<br style="word-wrap: break-word; line-height: normal; " />$(CONFIG_FOO)要么是y(built-in)要么是m(module)。如果CONFIG_FOO既不是y也不是m，那么文件将不会被编译也不会被连接。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Built-in object goals - obj-y<br style="word-wrap: break-word; line-height: normal; " />kbuild Makefiles在<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(obj-y)</strong>列表中为vmlinux指明object文件。这个列表依靠内核的配置。<br style="word-wrap: break-word; line-height: normal; " />在<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(obj-y)</strong>中的文件的顺序是非常重要的。列表中允许两个相同的文件：<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">第一个</strong>实体将被连接到built-in.o，后面的实体将会<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">被忽略。</strong><br style="word-wrap: break-word; line-height: normal; " />连接的顺序也很重要，因为在boot过程中某些函数(module_init()/_initcall)将会<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">按顺序出现。</strong>因此，如果改变了连接顺序，将会改变你的SCSI控制器的检测顺序，你的磁盘也同时被重新编号了。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#drivers/isdn/i4l/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;# Makefile for the kernel ISDN subsystem and device drivers.<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;# Each configuration option enables a list of files.<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;obj-$(CONFIG_ISDN)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; += isdn.o<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;Loadable module goals - obj-m<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(obj-m)</strong>指明object文件作为可装载的内核模块被构建。一个模块可能从一个或者多个源文件被构建。kbuild maefile只是简单的将源文件加到%(obj-m)<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><br style="word-wrap: break-word; line-height: normal; " /></strong>&nbsp;&nbsp;#drivers/isdn/i4l/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;obj-$(CONFIG_ISDN_PPP_BSDCOMP) += isdn_bsdcomp.o<br style="word-wrap: break-word; line-height: normal; " />注意这里$(CONFIG_ISDN_PPP_BSDCOMP)是m.<br style="word-wrap: break-word; line-height: normal; " />Note: In this example $(CONFIG_ISDN_PPP_BSDCOMP) evaluates to 'm'。<br style="word-wrap: break-word; line-height: normal; " />如果一个内核模块从多个源文件构建，KBuild就必须要知道你想从哪些部分构建模块。因此，你不得不设置<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(-objs</strong>)变量来告诉KBuild。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#drivers/isdn/i4l/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;obj-$(CONFIG_ISDN) += isdn.o<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;isdn-objs := isdn_net_lib.o isdn_v110.o isdn_common.o<br style="word-wrap: break-word; line-height: normal; " />在这个例子中，模块名是isdn.o,Kbuild将会编译列在<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(isdn-objs)</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">的</strong>object文件，然后在这些文件的列表中调用"$(LD) -r"来产生isdn.o。<br style="word-wrap: break-word; line-height: normal; " />Kbuild使用<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">后缀-objs,-y</strong>来识别混合的object文件。这允许Makefiles使用变量<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">CONFIG_sambol</strong>来决定一个object是否是混合object的的一部分。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#fs/ext2/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;obj-$(CONFIG_EXT2_FS)&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;+= ext2.o<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;ext2-y&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;:= balloc.o bitmap.o<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ext2-$(CONFIG_EXT2_FS_XATTR) += xattr.o<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " />在这个例子中，如果$(CONFIG_EXT2_FS_XATTR)是y，则xattr.o只是混合object文件ext2.o的一部分。<br style="word-wrap: break-word; line-height: normal; " />注意，当你构造一个objects到内核中时，上面的语法当然也能够工作。因此，如果你让CONFIG_EXT2=Y,KBuild将会为你构建一个独立的ext2.o文件，并且连接到built-in.o。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Library file goals - lib-y</strong><br style="word-wrap: break-word; line-height: normal; " />用<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">obj-*</strong>连接的Objects在指明的文件夹中被用作模块或者综合进built-in.o。也又可能被列出的objects将会被包含进一个库,lib.a。所有用lib-y列出的objects在那个文件夹中被综合进单独的一个库。列在obj-y和附加列在lib-y中的Objects将不会被包含在库中，因为他们将会被任意的存取。对于被连接在lib-m中，连续的objects将会被包含在lib.a中。值得注意的是kbuild makefile可能列出文件用作built-in，并且作为库的一部分。因此，同一个文件夹可能包含一个built-in.o和lib.a文件。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><br style="word-wrap: break-word; line-height: normal; " /></strong>&nbsp;&nbsp;#arch/i386/lib/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;lib-y&nbsp; &nbsp; := checksum.o delay.o<br style="word-wrap: break-word; line-height: normal; " />这里讲会创建一个基于checksum.o和delay.o的库文件。对于kbuild，识别一个lib.a正在被构建，这个文件夹应该被列在<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">libs-y</strong>中。<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">lib-y</strong>的使用方法通常被限制在lib/和arc/*/lib中。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Descending down in directories</strong><br style="word-wrap: break-word; line-height: normal; " />一个Makefile只负责在他自己的文件夹中构建objects。 在子文件夹中的文件应该由子文件夹中的Makefiles来照顾。如果你知道他们，build系统将会自动递归地用在子文件夹中的make。<br style="word-wrap: break-word; line-height: normal; " />在这种情况下<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">obj-y</strong>和<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">obj-m</strong>就被使用了。ext2存在于不同的文件夹中，Makefile出现在fs/，则告诉kbuild从后面的参数下来。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#fs/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;obj-$(CONFIG_EXT2_FS) += ext2/<br style="word-wrap: break-word; line-height: normal; " />如果CONFIG_EXT2_FS被设置成y(built-in)或者m(modular)，相应的obj-变量将会被设置，并且kbuild将会从ext2文件夹继承下来。Kbuild只会使用这些信息来决定它需要访问这些文件夹，而在子文件夹中的Makefile来指明哪些是modules哪些是built-in。<br style="word-wrap: break-word; line-height: normal; " />当赋值文件夹名字的时候，使用CONFIG_variable是很好的选择。这允许kbuild完全的跳过文件夹，而不管CONFIG_option是否是y或者m。<br style="word-wrap: break-word; line-height: normal; " />&#183;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Compilation flags</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp; EXTRA_CFLAGS, EXTRA_AFLAGS, EXTRA_LDFLAGS, EXTRA_ARFLAGS。<br style="word-wrap: break-word; line-height: normal; " />所有的EXTRA_ variables只<span href="tag.php?name=%D3%A6%D3%C3" class="t_tag" style="word-wrap: break-word; line-height: normal; cursor: pointer; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: #ff0000; white-space: nowrap; ">应用</span>在kbuild中，他们被赋值的地方。EXTRA_variables应用在kbuild makefile中所有的可执行的命令。<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(EXTRA_CFLAGS)</strong>&nbsp;指明用$(CC)编译C文件的时候的选项。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><br style="word-wrap: break-word; line-height: normal; " /></strong>&nbsp;&nbsp;# drivers/sound/emu10k1/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;EXTRA_CFLAGS += -I$(obj)<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;ifdef DEBUG<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;EXTRA_CFLAGS += -DEMU10K1_DEBUG<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;endif<br style="word-wrap: break-word; line-height: normal; " />这里的变量是必须的，因为顶层的Makefile拥有变量<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(CFLAGS)</strong>并且用它来作为整个树的编译标志当编译汇编源文件的时候<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(EXTRA_AFLAGS)</strong>，和每个文件夹的选项是相似的。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#arch/x86_64/kernel/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;EXTRA_AFLAGS := -traditional<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(EXTRA_LDFLAGS)</strong>和<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(EXTRA_ARFLAGS)</strong>&nbsp;对于每个文件夹的$(LD)和$(AR)选项是类似的。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;#arch/m68k/fpsp040/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;EXTRA_LDFLAGS := -x<br style="word-wrap: break-word; line-height: normal; " />CFLAGS_$@, AFLAGS_$@<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">CFLAGS_$@</strong>和<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">AFLAGS_$@</strong>只应用到当前kbuild makefile的命令。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$(CFLAGS_$@)</strong>&nbsp;为每个文件的$(CC)指明选项。<strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">$@</strong><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; "><br style="word-wrap: break-word; line-height: normal; " /></strong>部分有一个字面上的值，指明它是为那个文件。<br style="word-wrap: break-word; line-height: normal; " /><strong style="word-wrap: break-word; text-align: left; font-style: normal; line-height: normal; font-weight: bold; ">Example:</strong><br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;# drivers/scsi/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;CFLAGS_aha152x.o =&nbsp; &nbsp;-DAHA152X_STAT -DAUTOCONF<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;CFLAGS_gdth.o&nbsp; &nbsp; = # -DDEBUG_GDTH=2 -D__SERIAL__ -D__COM2__ \<br style="word-wrap: break-word; line-height: normal; " />&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;-DGDTH_STATISTICS<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;CFLAGS_seagate.o =&nbsp; &nbsp;-DARBITRATE -DPARITY -DSEAGATE_USE_ASM<br style="word-wrap: break-word; line-height: normal; " />These three lines specify compilation flags for aha152x.o,<br style="word-wrap: break-word; line-height: normal; " />gdth.o, and seagate.o<br style="word-wrap: break-word; line-height: normal; " />$(AFLAGS_$@) is a similar feature for source files in assembly<br style="word-wrap: break-word; line-height: normal; " />languages.<br style="word-wrap: break-word; line-height: normal; " />Example:<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;# arch/arm/kernel/Makefile<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;AFLAGS_head-armv.o := -DTEXTADDR=$(TEXTADDR) -traditional<br style="word-wrap: break-word; line-height: normal; " />&nbsp;&nbsp;AFLAGS_head-armo.o := -DTEXTADDR=$(TEXTADDR) -traditional<br style="word-wrap: break-word; line-height: normal; " /></td></tr></tbody></table></span><img src ="http://www.cppblog.com/lauer3912/aggbug/151523.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-07-21 07:24 <a href="http://www.cppblog.com/lauer3912/archive/2011/07/21/151523.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux on Power 上的调试工具和技术 (gdb ）及valgrind</title><link>http://www.cppblog.com/lauer3912/archive/2011/07/19/151353.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Mon, 18 Jul 2011 23:30:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/07/19/151353.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/151353.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/07/19/151353.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/151353.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/151353.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: Linux on Power 上的调试工具和技术Calvin Sze&nbsp;(calvins@us.ibm.com), Linux 顾问 , EMC简介：&nbsp;调试是一项主要的软件开发活动，作为应用程序开发人员，您无法避免对程序进行调试。有效的调试不仅能缩短软件开发周期，而且可以节省成本。本文简要介绍了在用户空间的 C/C++ 和 Java? 应用程序中查找 bug 的技术，并介绍了一些...&nbsp;&nbsp;<a href='http://www.cppblog.com/lauer3912/archive/2011/07/19/151353.html'>阅读全文</a><img src ="http://www.cppblog.com/lauer3912/aggbug/151353.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-07-19 07:30 <a href="http://www.cppblog.com/lauer3912/archive/2011/07/19/151353.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VirtualBox 4.0.8 发布, 提升3D支持</title><link>http://www.cppblog.com/lauer3912/archive/2011/05/17/146586.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Tue, 17 May 2011 10:55:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/05/17/146586.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/146586.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/05/17/146586.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/146586.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/146586.html</trackback:ping><description><![CDATA[<div id="OSChina_News_18038" class="NewsContent TextContent NewsType1">
<p>VirtualBox 宣布了 4.0.8 版本，该版本改进了对 Gnome 3 的 3D 支持。同时还修复了不少bug，包括改变 guest 窗体大小时可能导致程序崩溃的问题以及 Ubuntu 11.04 以及 Fedora 15 下 Gnome 3 的渲染问题。</p>
<p>VirtualBox 是一款功能强大的 x86 虚拟机软件，它不仅具有丰富的特色，而且性能也很优异。</p>
<p><img alt="" src="http://www.oschina.net/uploads/img/201003/26104750_gVMf.png" /></p>
<p class="ProjectOfNews">更多关于<a href="http://www.oschina.net/p/virtualbox"><u><font color="#0066cc">VirtualBox</font></u></a>的详细信息，或者下载地址请点<a href="http://www.oschina.net/action/project/go?id=1196&amp;p=download"><u><font color="#0066cc">这里</font></u></a></p></div><img src ="http://www.cppblog.com/lauer3912/aggbug/146586.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-05-17 18:55 <a href="http://www.cppblog.com/lauer3912/archive/2011/05/17/146586.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux Python 好用的开发工具gecrit</title><link>http://www.cppblog.com/lauer3912/archive/2011/04/23/144861.html</link><dc:creator>RTY</dc:creator><author>RTY</author><pubDate>Sat, 23 Apr 2011 10:07:00 GMT</pubDate><guid>http://www.cppblog.com/lauer3912/archive/2011/04/23/144861.html</guid><wfw:comment>http://www.cppblog.com/lauer3912/comments/144861.html</wfw:comment><comments>http://www.cppblog.com/lauer3912/archive/2011/04/23/144861.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/lauer3912/comments/commentRss/144861.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/lauer3912/services/trackbacks/144861.html</trackback:ping><description><![CDATA[下载地址：<a  href="http://sourceforge.net/projects/gecrit/files/">http://sourceforge.net/projects/gecrit/files/</a><img src ="http://www.cppblog.com/lauer3912/aggbug/144861.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/lauer3912/" target="_blank">RTY</a> 2011-04-23 18:07 <a href="http://www.cppblog.com/lauer3912/archive/2011/04/23/144861.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>