Linux Makefile条件指令
下面是Make文件的片段: Makefile1:Linux Makefile条件指令,linux,makefile,Linux,Makefile,下面是Make文件的片段: Makefile1: bar = true foo = bar ifdef $(foo) frobozz = yes endif all = ; @echo The value of frobozz is $(frobozz) Makefile2: bar = foo = $(bar) ifdef foo frobozz = yes else frobozz = no endif all = ; @echo The value of frobozz is $(fr
bar = true
foo = bar
ifdef $(foo)
frobozz = yes
endif
all = ; @echo The value of frobozz is $(frobozz)
Makefile2:
bar =
foo = $(bar)
ifdef foo
frobozz = yes
else
frobozz = no
endif
all = ; @echo The value of frobozz is $(frobozz)
在这两种情况下,输出相同“是”
所以我的结论是:
- 在第一种情况下,ifdef的参数是$(foo),它最终成为bar,这意味着语句实际上看起来像ifdef bar,因此bar的值被选中
- 在第二种情况下,ifdef的参数直接为foo,因此会检查foo的值,因此语句ifdef会检查foo的值,即$(bar)
- Makefile1
- Makefile2
bar=
foo=$(bar)
$(warning origin=$(origin foo), flavor=$(flavor foo), value="$(value foo)")
$(warning origin=$(origin bar), flavor=$(flavor bar), value="$(value bar)")
ifdef foo
$(warning foo defined)
else
$(warning foo is not defined)
endif
ifdef $(bar)
$(warning bar defined)
else
$(warning bar is not defined)
endif
输出:
Makefile:3: origin=file, flavor=recursive, value="$(bar)"
Makefile:4: origin=file, flavor=recursive, value=""
Makefile:7: foo defined
Makefile:15: bar is not defined
但是,您可以强制展开,只需稍作更改:在分配变量foo:foo:=$(bar)时添加冒号,这两个变量都不会定义:
Makefile:3: origin=file, flavor=simple, value=""
Makefile:4: origin=file, flavor=recursive, value=""
Makefile:9: foo is not defined
Makefile:15: bar is not defined
它意味着FIFCKECK只有FO具有值$(bar),它不进一步扩展它,或者扩展它,但它认为空的是空的。@ abijaTyasaseh是的,换句话说,它测试FO是“定义的”,如IFDF所建议的操作。您可以使用函数origin()来测试变量是否未定义,即它检查foo是否有值$(bar),并且它不会进一步展开以检查bar的值,或者它允许定义空值,就像bar=。请澄清。@AbhijatyaSingh Yes表示它检查foo是否已被分配到某个值,并且不会进一步扩展。感谢@pmod澄清疑问。