[英]Variable substitution in Makefile yields unexpected results
I have a Makefile:我有一个 Makefile:
FOO=one two
$(FOO):
echo $@
Now I run:现在我运行:
make one
and get echo one
make one
并获得echo one
make two
and get echo two
make two
并获得echo two
make three
and get an error make three
并得到一个错误
This is expected.这是预期的。
However, when I change the Makefile to:但是,当我将 Makefile 更改为:
FOO=one two
$(FOO)$(FOO):
echo $@
It is still the same!还是一样!
I would expect that I have to type make oneone
, but this is not the case.我希望我必须输入
make oneone
,但事实并非如此。
Why is that?这是为什么?
Because make
trustfully pastes whatever you give it as contents.因为
make
可靠地粘贴您提供的任何内容作为内容。 Depending on the invisible rest of the line in FOO=one two...
ie if you have a space there or not, you are producing one twoone two
or one two one two
.根据
FOO=one two...
不可见的行的其余部分,即,如果您在那里有空格,则生成one twoone two
或one two one two
。 The latter is, I think, not illegal but will produce a warning like target given more than once in same line
.我认为后者不是非法的,但会产生一个警告,例如
target given more than once in same line
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.