GNU make manual 翻译( 一百八十一)

继续翻译

   The syntax of the CONDITIONAL-DIRECTIVE is the same whether the
conditional is simple or complex; after an `else' or not.  There are
four different directives that test different conditions.  Here is a
table of them:

`ifeq (ARG1, ARG2)'
`ifeq 'ARG1' 'ARG2''
`ifeq "ARG1" "ARG2"'
`ifeq "ARG1" 'ARG2''
`ifeq 'ARG1' "ARG2"'
     Expand all variable references in ARG1 and ARG2 and compare them.
     If they are identical, the TEXT-IF-TRUE is effective; otherwise,
     the TEXT-IF-FALSE, if any, is effective.

     Often you want to test if a variable has a non-empty value.  When
     the value results from complex expansions of variables and
     functions, expansions you would consider empty may actually
     contain whitespace characters and thus are not seen as empty.
     However, you can use the `strip' function (*note Text Functions::)
     to avoid interpreting whitespace as a non-empty value.  For
     example:

          ifeq ($(strip $(foo)),)
          TEXT-IF-EMPTY
          endif

     will evaluate TEXT-IF-EMPTY even if the expansion of `$(foo)'
     contains whitespace characters.

`ifneq (ARG1, ARG2)'
`ifneq 'ARG1' 'ARG2''
`ifneq "ARG1" "ARG2"'
`ifneq "ARG1" 'ARG2''
`ifneq 'ARG1' "ARG2"'
     Expand all variable references in ARG1 and ARG2 and compare them.
     If they are different, the TEXT-IF-TRUE is effective; otherwise,
     the TEXT-IF-FALSE, if any, is effective.

对条件式指令的语法而言,无论条件是简单还是复杂,是否在else之后或不适,语法都是相同的。测试不同的条件,可以由四种不同的指令。下面是一个列表:

`ifeq (ARG1, ARG2)'
`ifeq 'ARG1' 'ARG2''
`ifeq "ARG1" "ARG2"'
`ifeq "ARG1" 'ARG2''
`ifeq 'ARG1' "ARG2"'

扩展在ARG1 和 ARG2中所有的变量参照。如果它们是相同的,那么 TEXT-IF-TRUE 生效;否则 如果有TEXT-IF-FALSE, 则 TEXT-IF-FALSE 生效。

经常性地,你可能想要测试是否一个变量是非空值。当一个值来自于复杂的变量扩展或者函数,那么你认为的因当时空的扩展,很可能实际上包含的空格字符,此时不能被认为是空。但是你可以用 strip函数(*note Text Function::)来防止把空格字符翻译为非空值。例如:

ifeq ($(strip $(foo)),)
TEXT-IF-EMPTY
endif

即使$(foo)包含了空格字符,也会获得 TEXT-IF-EMPTY 。

`ifneq (ARG1, ARG2)'
`ifneq 'ARG1' 'ARG2''
`ifneq "ARG1" "ARG2"'
`ifneq "ARG1" 'ARG2''
`ifneq 'ARG1' "ARG2"'
Expand all variable references in ARG1 and ARG2 and compare them.
If they are different, the TEXT-IF-TRUE is effective; otherwise,
the TEXT-IF-FALSE, if any, is effective.

扩展ARG1和ARG2中所有的变量参照并比较它们。如果不同则TEXT-IF-TRUE有效。否则,若TEXT-IF-FALSE存在,则 TEXT-IF-FALSE有效。

后文待续

posted @ 2012-10-08 14:20  健哥的数据花园  阅读(206)  评论(0编辑  收藏  举报