这周学学条件判断的内容
1.语法
<conditional-directive>
<text-if-true>
endif
或者
<conditional-directive>
<text-if-true>
else
<text-if-false>
endif
其中<conditional-directive>表示条件关键字,这里的关键字有四个:ifeq ifneq ifdef ifndef,具体说明如下:
ifeq:
语法:
ifeq(<arg1>,<arg2>)
ifeq '<arg1>' '<arg2>'
ifeq "<arg1>" "<arg2>"
ifeq "<arg1>" '<arg2>'
ifeq '<arg1>' "<arg2>"
比较参数arg1和arg2值是否相同。
ifneq:
语法:
ifneq(<arg1>,<arg2>)
ifneq '<arg1>' '<arg2>'
ifneq "<arg1>" "<arg2>"
ifneq "<arg1>" '<arg2>'
ifneq '<arg1>' "<arg2>"
比较参数arg1和arg2值是否相同。如果不同,则为真
ifdef:
语法:
ifdef<variable-name>
如果变量<variable-name>的值非空,那表达式为真,否之为假。
当然<variable-name>同样可以是一个函数的返回值。
注:ifdef只是测试一个变量是否有值,其并不会把 变量扩展到当前为止。
ifndef:
语法:
ifndef<variable-name>
意思与ifdef相反。
注:
2.示例说明
ifeq(判断$(CC)变量是否“gcc”):
libs_for_gcc=-lgnu
normal_libs=
foo:$(objects)
ifeq($(CC),gcc)
$(CC) -o foo $(objects) $(libs_for_gcc)
else
$(CC) -o foo $(objects) $(normal_libs)
endif
foo:$(objects)
$(CC) -o foo $(objects) $(libs_for_gcc)
foo:$(objects)
$(CC) -o foo $(objects) $(normal_libs)
ifdef:
bar=
foo=$(bar)
ifdef foo
frobozz=yes
else
frobozz=no
endif
说明:
foo非空,所以$frobozz的值为yes
foo=
ifdef foo
frobozz=yes
else
frobozz=no
endif
说明:
foo空,所以$frobozz的值为no