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

📄 8.htm

📁 学习MAkefile相关的好资料
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<P><FONT face="Courier New">可见,在上面示例的这个规则中,目标“foo”可以根据变量“$(CC)”值来选取不同的函数库来编译程序。</FONT></P>
<P><FONT face="Courier New">我们可以从上面的示例中看到三个关键字:ifeq、else和endif。ifeq的意思表示条件语句的开始,并指定一个条件表达式,表达式包含两个参数,以逗号分隔,表达式以圆括号括起。else表示条件表达式为假的情况。endif表示一个条件语句的结束,任何一个条件表达式都应该以endif结束。</FONT></P>
<P><FONT face="Courier New">当我们的变量$(CC)值是“gcc”时,目标foo的规则是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; foo: $(objects)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CC) -o foo $(objects) $(libs_for_gcc)</FONT></P>
<P><FONT face="Courier New">而当我们的变量$(CC)值不是“gcc”时(比如“cc”),目标foo的规则是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; foo: $(objects)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CC) -o foo $(objects) $(normal_libs)</FONT></P>
<P><FONT face="Courier New">当然,我们还可以把上面的那个例子写得更简洁一些:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; libs_for_gcc = -lgnu<BR>&nbsp;&nbsp;&nbsp; normal_libs =</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifeq ($(CC),gcc)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libs=$(libs_for_gcc)<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; libs=$(normal_libs)<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; foo: $(objects)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(CC) -o foo $(objects) $(libs)</FONT></P>
<P><BR><FONT face="Courier New"><STRONG>二、语法</STRONG></FONT></P>
<P><FONT face="Courier New">条件表达式的语法为:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; &lt;conditional-directive&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;text-if-true&gt;<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">以及:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; &lt;conditional-directive&gt;<BR>&nbsp;&nbsp;&nbsp; &lt;text-if-true&gt;<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; &lt;text-if-false&gt;<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">其中&lt;conditional-directive&gt;表示条件关键字,如“ifeq”。这个关键字有四个。</FONT></P>
<P><FONT face="Courier New">第一个是我们前面所见过的“ifeq”</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifeq (&lt;arg1&gt;, &lt;arg2&gt;) <BR>&nbsp;&nbsp;&nbsp; ifeq '&lt;arg1&gt;' '&lt;arg2&gt;' <BR>&nbsp;&nbsp;&nbsp; ifeq "&lt;arg1&gt;" "&lt;arg2&gt;" <BR>&nbsp;&nbsp;&nbsp; ifeq "&lt;arg1&gt;" '&lt;arg2&gt;' <BR>&nbsp;&nbsp;&nbsp; ifeq '&lt;arg1&gt;' "&lt;arg2&gt;" </FONT></P>
<P><FONT face="Courier New">比较参数“arg1”和“arg2”的值是否相同。当然,参数中我们还可以使用make的函数。如:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifeq ($(strip $(foo)),)<BR>&nbsp;&nbsp;&nbsp; &lt;text-if-empty&gt;<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">这个示例中使用了“strip”函数,如果这个函数的返回值是空(Empty),那么&lt;text-if-empty&gt;就生效。</FONT></P>
<P><FONT face="Courier New">第二个条件关键字是“ifneq”。语法是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifneq (&lt;arg1&gt;, &lt;arg2&gt;) <BR>&nbsp;&nbsp;&nbsp; ifneq '&lt;arg1&gt;' '&lt;arg2&gt;' <BR>&nbsp;&nbsp;&nbsp; ifneq "&lt;arg1&gt;" "&lt;arg2&gt;" <BR>&nbsp;&nbsp;&nbsp; ifneq "&lt;arg1&gt;" '&lt;arg2&gt;' <BR>&nbsp;&nbsp;&nbsp; ifneq '&lt;arg1&gt;' "&lt;arg2&gt;" </FONT></P>
<P><FONT face="Courier New">其比较参数“arg1”和“arg2”的值是否相同,如果不同,则为真。和“ifeq”类似。</FONT></P>
<P><FONT face="Courier New">第三个条件关键字是“ifdef”。语法是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifdef &lt;variable-name&gt; </FONT></P>
<P><FONT face="Courier New">如果变量&lt;variable-name&gt;的值非空,那到表达式为真。否则,表达式为假。当然,&lt;variable-name&gt;同样可以是一个函数的返回值。注意,ifdef只是测试一个变量是否有值,其并不会把变量扩展到当前位置。还是来看两个例子:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; 示例一:<BR>&nbsp;&nbsp;&nbsp; bar =<BR>&nbsp;&nbsp;&nbsp; foo = $(bar)<BR>&nbsp;&nbsp;&nbsp; ifdef foo<BR>&nbsp;&nbsp;&nbsp; frobozz = yes<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; frobozz = no<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; 示例二:<BR>&nbsp;&nbsp;&nbsp; foo =<BR>&nbsp;&nbsp;&nbsp; ifdef foo<BR>&nbsp;&nbsp;&nbsp; frobozz = yes<BR>&nbsp;&nbsp;&nbsp; else<BR>&nbsp;&nbsp;&nbsp; frobozz = no<BR>&nbsp;&nbsp;&nbsp; endif</FONT></P>
<P><FONT face="Courier New">第一个例子中,“$(frobozz)”值是“yes”,第二个则是“no”。</FONT></P>
<P><FONT face="Courier New">第四个条件关键字是“ifndef”。其语法是:</FONT></P>
<P><FONT face="Courier New">&nbsp;&nbsp;&nbsp; ifndef &lt;variable-name&gt;</FONT></P>
<P><FONT face="Courier New">这个我就不多说了,和“ifdef”是相反的意思。</FONT></P>
<P><FONT face="Courier New">在&lt;conditional-directive&gt;这一行上,多余的空格是被允许的,但是不能以[Tab]键做为开始(不然就被认为是命令)。而注释符“#”同样也是安全的。“else”和“endif”也一样,只要不是以[Tab]键开始就行了。</FONT></P>
<P><FONT face="Courier New">特别注意的是,make是在读取Makefile时就计算条件表达式的值,并根据条件表达式的值来选择语句,所以,你最好不要把自动化变量(如“$@”等)放入条件表达式中,因为自动化变量是在运行时才有的。</FONT></P>
<P><FONT face="Courier New">而且,为了避免混乱,make不允许把整个条件语句分成两部分放在不同的文件中。</FONT></P>
<P align=right><STRONG><FONT face="Courier New">&lt;-</FONT></STRONG><A href="http://www.csdn.net/develop/read_article.asp?id=20438"><FONT face="Courier New" color=#0000ff><STRONG>上一页</STRONG></FONT></A><STRONG><FONT face="Courier New">&nbsp; <A href="http://www.csdn.net/Develop/Read_Article.asp?Id=20547"><FONT color=#0000ff>下一页</FONT></A>-&gt;</FONT></STRONG></P>
<P><STRONG><FONT face="Courier New">(版权所有,转载时请注明作者和出处)</FONT></STRONG></P></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">jiangcr81</span>
          <i>(
            <span id="CommnetList1_CommnetList1_rpCommentList__ctl0_lblPostTime">2005-06-21</span>)</i>
        </td>
      </tr>
      <tr>
        <td colspan="3" width="532" bgcolor="#ffffff">
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl0_lblContent">如果写成这样:<br>ifeq&nbsp;($(GOAL),$(findstring&nbsp;$(GOAL),$(CJK_CHAR_TARGETS)))<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">2004-07-02</span>)</i>
        </td>
      </tr>
      <tr>
        <td colspan="3" width="532" bgcolor="#ffffff">
          <span id="CommnetList1_CommnetList1_rpCommentList__ctl1_lblContent">so&nbsp;good,thank&nbsp;you!!</span>
        </td>
      </tr>
    </table>
  
<div align=right>
<a id="CommnetList1_CommnetList1_Morelink" href="http://comment.csdn.net/Comment.aspx?c=2&amp;s=20464">【评论】</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 + -