[英]Makefile: why command substitution can't work in $(shell) function?
I have a variable in Makefile
: 我在
Makefile
有一个变量:
JAVABIN = $(shell dirname $(which java))
And when I echo the JAVA_HOME
variable in Makefile
, the variable definition complains: 当我在
Makefile
回显JAVA_HOME
变量时,变量定义会抱怨:
dirname: missing operand
Try 'dirname --help' for more information.
When I quote the $(which java)
, the JAVABIN
is .
当我引用
$(which java)
, JAVABIN
就是.
, so the result is wrong. ,结果是错误的。 And I didn't understand how make reads a Makefile, maybe it is the cause.
我不明白make如何读取Makefile,也许是原因。 Thank you very much.
非常感谢你。
You need to escape the dollar: 你需要逃避美元:
JAVABIN = $(shell dirname $$(which java))
See 6.1 Basics of Variable References . 请参见6.1变量引用的基础知识 。
The specific error message you received was caused by the fact that the $(which java)
piece expanded to the empty string, since it was an undefined variable. 您收到的具体错误消息是由于
$(which java)
片段扩展为空字符串,因为它是一个未定义的变量。 Hence the dirname
system command ended up seeing no arguments, in which case it complains of a "missing operand". 因此,
dirname
系统命令最终看不到任何参数,在这种情况下,它会抱怨“缺少操作数”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.