The argument to the eval function is expanded, then the results of that expansion are parsed as makefile syntax.
我不太理解make解析器如何处理eval提供的文本,因此我编写了以下makefile进行测试。
define myprint
echo "this is a line"
endef
goal:
$(eval $(call myprint))
gcc -o goal test.c
我知道正确调用
myprint
应该仅使用调用函数:$(call myprint)
并删除echo之前的“Tab”字符。我以这种形式编写makefile只是为了测试eval函数。我的期望是:首先,eval函数会扩展myprint,即一个以“Tab”开头的echo命令,并且“Tab”用于使扩展文本成为合法的配方。然后,eval将扩展的文本提供给maker解析器,后者将识别该文本为配方并运行它。由于该命令是合法的,因此makefile应该正常运行。
然而,我遇到了这样一个错误:
Makefile:6: *** recipe commences before first target. Stop.
有人能解释一下为什么make会出现这样的错误吗?
$(eval $(call myprint))
扩展为make语句,而它应该是纯shell。这与如果您将CFLAGS:= -g
放在配方中的问题相同:在期望shell的地方使用了make语法。 - Renaud Pacalet