您的位置:首页 > 其它

学习Makefile第五课------使用判断条件

2014-09-04 09:17 295 查看
1.示例

ibs_for_gcc = -lgnu 

normal_libs = 

foo: $(objects) 

ifeq ($(CC),gcc)    ----------------------如果objects = gcc ,执行$(CC) -o foo $(objects) $(libs_for_gcc) ,否则执行else里面的语句

$(CC) -o foo $(objects) $(libs_for_gcc) 

else 

$(CC) -o foo $(objects) $(normal_libs) 

endif 

2.语法

条件表达式的语法为:

<conditional-directive> 

<text-if-true> 

endif 

以及:

<conditional-directive> 

<text-if-true> 

else 

<text-if-false> 

endif

(1)ifeq

  ifeq (<arg1>, <arg2>) ---------arg1和arg2相同为真

(2)ifneq

   ifneq (<arg1>, <arg2>) -------不同为真

(3)ifdef

   ifdef <variable-name> ---------值非空,为真

(4)ifndef

   ifndef <variable-name>---------和“ifdef”是相反的意思

最好不要使用自动变量,也不要分成多个文件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: