I have a variable in Makefile
:
JAVABIN = $(shell dirname $(which java))
And when I echo the JAVA_HOME
variable in Makefile
, the variable definition complains:
dirname: missing operand
Try 'dirname --help' for more information.
When I quote the $(which java)
, the JAVABIN
is .
, so the result is wrong. And I didn't understand how make reads a Makefile, maybe it is the cause. Thank you very much.
You need to escape the dollar:
JAVABIN = $(shell dirname $$(which java))
See 6.1 Basics of Variable References.
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. Hence the dirname
system command ended up seeing no arguments, in which case it complains of a "missing operand".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With