0

作为标题,在makefile GNU中,obj_$(variable)$(addprefix "obj_", $(variable))之间的区别是什么。我确信有区别,因为第一个可以与字符串进行比较,而后一个不能被识别为字符串。如果我错了,请告诉我。我想让第二个作为字符串工作,所以我可以使用 $($(addprefix "obj_", $(variable))) 作为变量(现在它不起作用)。

谢谢你们。

4

1 回答 1

0

自己测试一下:

print_values = \
    $(warning Let the value of '$$(variable)' to be [$(variable)]) \
    $(warning then the value of obj_$$(variable) is [obj_$(variable)]) \
    $(warning $$(addprefix  "obj_", $$(variable)) is [$(addprefix "obj_", $(variable))]) \
    $(warning )

variable := foo
$(print_values)

variable := foo bar baz
$(print_values)

variable :=
variable += foo
$(print_values)

您将获得以下输出:

makefile:10: Let the value of '$(variable)' to be [foo]
makefile:10: then the value of obj_$(variable) is [obj_foo]
makefile:10: $(addprefix  "obj_", $(variable)) is ["obj_"foo]
makefile:10: 
makefile:13: Let the value of '$(variable)' to be [foo bar]
makefile:13: then the value of obj_$(variable) is [obj_foo bar]
makefile:13: $(addprefix  "obj_", $(variable)) is ["obj_"foo "obj_"bar]
makefile:13: 
makefile:17: Let the value of '$(variable)' to be [ foo]
makefile:17: then the value of obj_$(variable) is [obj_ foo]
makefile:17: $(addprefix  "obj_", $(variable)) is ["obj_"foo]
makefile:17: 

PS 正如我在另一个问题的答案中告诉你的那样,引号绝对不是你想要的。

使用普通obj_

$(addprefix obj_,$(variable))

代替:

$(addprefix "obj_",$(variable))
于 2012-05-29T21:08:46.947 回答