今天在修改Makefile时,发现如果condition中包含$*(automatic variables),无论取什么值,ifeq语句永远只执行true语句或false语句。
do_lrg%: ifeq ("$(findstring $*,$(ALL_SHIPHOME_LRGS))", "") echo "regression test..." else echo "shiphome test..." endif
通过参照Makefile: ifeq directive compares special variable to constant does not work找到了答案。
Conditional Statements All instances of conditional syntax are parsed immediately, in their entirety; this includes the ifdef, ifeq, ifndef, and ifneq forms. Of course this means that automatic variables cannot be used in conditional statements, as automatic variables are not set until the command script for that rule is invoked. If you need to use automatic variables in a conditional you must use shell conditional syntax, in your command script proper, for these tests, not make conditionals.
但可以使用$(if condition,then-part[,else-part])去workaround它。
do_lrg%: $(if $(findstring $*, $(ALL_SHIPHOME_LRGS)), echo "shiphome test", echo "regress test" )