⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2.htm

📁 学习MAkefile相关的好资料
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<P><BR><FONT face="Courier New"><STRONG>六、另类风格的makefile</STRONG></FONT></P>
<P><FONT face="Courier New">即然我们的make可以自动推导命令,那么我看到那堆[.o]和[.h]的依赖就有点不爽,那么多的重复的[.h],能不能把其收拢起来,好吧,没有问题,这个对于make来说很容易,谁叫它提供了自动推导命令和文件的功能呢?来看看最新风格的makefile吧。</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; objects = main.o kbd.o command.o display.o \<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert.o search.o files.o utils.o</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; edit : $(objects)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cc -o edit $(objects)</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; $(objects) : defs.h<BR>&nbsp;&nbsp;&nbsp; kbd.o command.o files.o : command.h<BR>&nbsp;&nbsp;&nbsp; display.o insert.o search.o files.o : buffer.h</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; .PHONY : clean<BR>&nbsp;&nbsp;&nbsp; clean :<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm edit $(objects)</FONT></P>
<P><FONT face="Courier New">这种风格,让我们的makefile变得很简单,但我们的文件依赖关系就显得有点凌乱了。鱼和熊掌不可兼得。还看你的喜好了。我是不喜欢这种风格的,一是文件的依赖关系看不清楚,二是如果文件一多,要加入几个新的.o文件,那就理不清楚了。</FONT></P>
<P><BR><FONT face="Courier New"><STRONG>七、清空目标文件的规则</STRONG></FONT></P>
<P><FONT face="Courier New">每个Makefile中都应该写一个清空目标文件(.o和执行文件)的规则,这不仅便于重编译,也很利于保持文件的清洁。这是一个“修养”(呵呵,还记得我的《编程修养》吗)。一般的风格都是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clean:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rm edit $(objects)</FONT></P>
<P><FONT face="Courier New">更为稳健的做法是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; .PHONY : clean<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; clean :<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -rm edit $(objects)</FONT></P>
<P><FONT face="Courier New">前面说过,.PHONY意思表示clean是一个“伪目标”,。而在rm命令前面加了一个小减号的意思就是,也许某些文件出现问题,但不要管,继续做后面的事。当然,clean的规则不要放在文件的开头,不然,这就会变成make的默认目标,相信谁也不愿意这样。不成文的规矩是——“clean从来都是放在文件的最后”。</FONT></P>
<P><BR><FONT face="Courier New">上面就是一个makefile的概貌,也是makefile的基础,下面还有很多makefile的相关细节,准备好了吗?准备好了就来。</FONT></P><FONT face="Courier New">
<P align=right><FONT face="MS Sans Serif"><STRONG>&lt;-</STRONG><A href="http://www.csdn.net/develop/read_article.asp?id=20025"><FONT color=#0000ff><STRONG>上一页</STRONG></FONT></A><STRONG>&nbsp; <A href="http://www.csdn.net/Develop/read_article.asp?id=20098"><FONT color=#0000ff>下一页</FONT></A>-&gt;</STRONG></FONT></P>
<P><FONT face="Courier New"><STRONG>(版权所有,转载时请注明作者和出处)</STRONG></FONT></P></FONT></span>
<br />
<div style="font-size: 14px; line-height: 25px;"><strong>作者Blog:</strong><a id="ArticleContent1_ArticleContent1_AuthorBlogLink" href="http://blog.csdn.net/haoel/" target="_blank">http://blog.csdn.net/haoel/</a></div>
<div style="font-size: 14px; line-height: 25px; color:#900;"><strong>相关文章</strong></div>
<table id="ArticleContent1_ArticleContent1_RelatedArticles" cellspacing="0" border="0">
	<tr>
		<td>
    <a href="/article/29/29472.shtm">标准C++类string的Copy-On-Write技术(三)</a>
  </td>
	</tr><tr>
		<td>
    <a href="/article/29/29470.shtm">标准C++类string的Copy-On-Write技术(二)</a>
  </td>
	</tr><tr>
		<td>
    <a href="/article/29/29469.shtm">标准C++类string的Copy-On-Write技术(一)</a>
  </td>
	</tr><tr>
		<td>
    <a href="/article/23/23559.shtm">以程序的方式操纵NTFS的文件权限(下)</a>
  </td>
	</tr><tr>
		<td>
    <a href="/article/23/23558.shtm">以程序的方式操纵NTFS的文件权限(中)</a>
  </td>
	</tr>
</table>
</td>
              </tr>
            </table>
            <a name="#Comment"></a>
            <table width="100%" border="0" cellpadding="0">
              <tr>
                <td>
                  



  <table cellSpacing=0 cellPadding=0 width="100%" align=center bgColor=#006699 border=0>
    <tr bgColor=#006699>
      <td id=white align=center width=556 bgColor=#006699>
      <font color=#ffffff >对该文的评论</font> </td>
    </tr>
  </table>
  
    <table border="0" cellpadding="2" cellspacing="1" width="100%" align="center" bgcolor="#666666">
      <tr>
        <td colspan="3" bgcolor="#cccccc">
          <span style="color:#990000;">
            <img src="/images/ico_pencil.gif" hspace="1" height="16" width="16">
          </span>
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl0_lblUserName">CSDN 网友</span>
          <i>(
            <span id="CommnetList1_CommnetList1_rpCommentList__ctl0_lblPostTime">2005-04-15</span>)</i>
        </td>
      </tr>
      <tr>
        <td colspan="3" width="532" bgcolor="#ffffff">
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl0_lblContent">深谷幽兰芳,心如皓月明<br>作者了不起!!</span>
        </td>
      </tr>
    </table>
  
    <table border="0" cellpadding="2" cellspacing="1" width="100%" align="center" bgcolor="#666666">
      <tr>
        <td colspan="3" bgcolor="#cccccc">
          <span style="color:#990000;">
            <img src="/images/ico_pencil.gif" hspace="1" height="16" width="16">
          </span>
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl1_lblUserName">CSDN 网友</span>
          <i>(
            <span id="CommnetList1_CommnetList1_rpCommentList__ctl1_lblPostTime">2005-04-12</span>)</i>
        </td>
      </tr>
      <tr>
        <td colspan="3" width="532" bgcolor="#ffffff">
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl1_lblContent">精彩</span>
        </td>
      </tr>
    </table>
  
    <table border="0" cellpadding="2" cellspacing="1" width="100%" align="center" bgcolor="#666666">
      <tr>
        <td colspan="3" bgcolor="#cccccc">
          <span style="color:#990000;">
            <img src="/images/ico_pencil.gif" hspace="1" height="16" width="16">
          </span>
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl2_lblUserName">CSDN 网友</span>
          <i>(
            <span id="CommnetList1_CommnetList1_rpCommentList__ctl2_lblPostTime">2004-11-15</span>)</i>
        </td>
      </tr>
      <tr>
        <td colspan="3" width="532" bgcolor="#ffffff">
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl2_lblContent">感谢</span>
        </td>
      </tr>
    </table>
  
<div align=right>
<a id="CommnetList1_CommnetList1_Morelink" href="http://comment.csdn.net/Comment.aspx?c=2&amp;s=20026">【评论】</a>
<a id="CommnetList1_CommnetList1_Hyperlink1" href="javascript:window.close();">【关闭】</a>
<a href="mailto:webmaster@csdn.net">【报告bug】</a>
</div>
<br>
                </td>
              </tr>
            </table>
          </TD>
        </TR>
      </TABLE>
    </form>
    
<!-- 版权 -->
<hr width="770" noShade size="1" align="center">
<table cellspacing="0" cellpadding="0" width="500" border="0" align="center">
	<tr>
		<td valign="bottom" height="10" align="center">
			<a href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</a>
			-
			<a href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</a>
			-
			<a href="http://www.csdn.net/map/map.shtm">网站地图</a>
			-
			<a href="http://www.csdn.net/help/help.asp">帮助信息</a>
			-
			<a href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</a>
			-
			<a href="http://www.csdn.net/english">English</a>
		</td>
		<td align="center" rowspan="3"><a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><img height="48" src="/images/biaoshi.gif" width="40" border="0"></a></td>
	</tr>
	<tr>
		<td valign="top" align="center">北京百联美达美数码科技有限公司 版权所有 京ICP证020026号</td>
	</tr>
	<tr align="center">
		<td valign="top"><font face="Verdana">Copyright &copy; CSDN.NET, Inc. All Rights Reserved</font></td>
	</tr>
	<tr><td height="15"></td></tr>
</table>
<!-- /版权 -->

    <script>
      document.write("<img src=http://count.csdn.net/count/pageview1.asp?columnid=4&itemid=11 border=0 width=0 height=0>");
    </script>
  </body>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -