Using Addprefix function makes the string uncomparable to another string

折月煮酒 提交于 2019-12-13 21:43:59

问题


So, I have the following code:

OBJ := $(addprefix 'obj_', $(basename $(notdir /build/common.mk)))

so now OBJ1 is "obj_common"

ifeq ($(OBJ),obj_common)
    @echo equal (**don't know how to format indent in this website..assume there is.**)
endif

the ifeq can't compare $(OBJ) to obj_common, at least it didn't echo...

(However, if I get rid of addprefix function as follow:)

OBJ := $(basename $(notdir /build/common.mk))

so now OBJ1 is "common"

ifeq ($(OBJ),common)
    @echo equal
endif

this code would echo, which means they can compare and are equal.

I need to reference the variable $(OBJ_common) (I have a big list of this kind of variable, so I can't manually input the string by hand), but now addprefix function makes this string not a string... Could anyone please help me resolve the issue? If my question is not clear, please let me know. Thank you very much.


回答1:


Well, the mistake is in the following statement:

OBJ := $(addprefix 'obj_', $(basename $(notdir /build/common.mk)))
so now OBJ1 is "obj_common"

In fact, OBJ1 becomes 'obj'_common because of quotes that you used in the first argument to addprefix.

So without the quotes it should work fine:

OBJ := $(addprefix obj_, $(basename $(notdir /build/common.mk)))

Tip

Use warning and error functions for debugging your scripts:

OBJ := ...
$(warning so now OBJ1 is [$(OBJ1)])


来源:https://stackoverflow.com/questions/10804809/using-addprefix-function-makes-the-string-uncomparable-to-another-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!