GNU make manual 翻译( 一百八十二)
继续翻译
`ifdef VARIABLE-NAME' The `ifdef' form takes the _name_ of a variable as its argument, not a reference to a variable. The value of that variable has a non-empty value, the TEXT-IF-TRUE is effective; otherwise, the TEXT-IF-FALSE, if any, is effective. Variables that have never been defined have an empty value. The text VARIABLE-NAME is expanded, so it could be a variable or function that expands to the name of a variable. For example: bar = true foo = bar ifdef $(foo) frobozz = yes endif The variable reference `$(foo)' is expanded, yielding `bar', which is considered to be the name of a variable. The variable `bar' is not expanded, but its value is examined to determine if it is non-empty. Note that `ifdef' only tests whether a variable has a value. It does not expand the variable to see if that value is nonempty. Consequently, tests using `ifdef' return true for all definitions except those like `foo ='. To test for an empty value, use `ifeq ($(foo),)'. For example, bar = foo = $(bar) ifdef foo frobozz = yes else frobozz = no endif sets `frobozz' to `yes', while: foo = ifdef foo frobozz = yes else frobozz = no endif sets `frobozz' to `no'.
`ifdef VARIABLE-NAME'
`ifdef' 把变量的名字作为它的参数,并不是对变量的一个参照。此变量的值有一个非空值。此时TEXT-IF-TRUE is effective 有效;否则,若TEXT-IF-FALSE存在,则TEXT-IF-FALSE有效。从未定义的变量拥有一个空值 。VARIABLE-NAME 文本会被扩展,因此它可以是一个变量或者函数的扩展,例如:
bar = true
foo = bar
ifdef $(foo)
frobozz = yes
endif
变量参照$(foo)被扩展,转化为bar,它可以视为一个变量的名字。变量bar不再扩展,但是它的值会用来被检查看其是否为空。
请注意 ifdef 只测试是否一个变量有一个值。它并不扩展词比变量来看它是否为非空。此外,用ifdef来测试会返回真,只有像foo=那种测试才会是例外。为了测试一个空值,可以使用 ifeq($(foo),)。例如:
bar =
foo = $(bar)
ifdef foo
frobozz = yes
else
frobozz = no
endif
设置 `frobozz' 为 `yes', 而:
foo =
ifdef foo
frobozz = yes
else
frobozz = no
endif
设置 `frobozz' 为 `no'.
后文待续