Makefile : contains string

蹲街弑〆低调 提交于 2019-12-02 21:33:47

The findstring function is what your heart desires:

$(findstring find,in)

Searches in for an occurrence of find. If it occurs, the value is find; otherwise, the value is empty. You can use this function in a conditional to test for the presence of a specific substring in a given string. Thus, the two examples,

$(findstring a,a b c)
$(findstring a,b c)

produce the values "a" and "" (the empty string), respectively. See Testing Flags, for a practical application of findstring.

Something like:

ifneq (,$(findstring NT-5.1,$(VARIABLE)))
    # Found
else
    # Not found
endif
VARIABLE=NT-5.1_Can_be_any_string
ifeq ($(findstring NT-5.1,$(VARIABLE)),NT-5.1)
    # Found
    RESULT=found
else
    # Not found
    RESULT=notfound
endif

all:
    @echo "RESULT=${RESULT} , output=$(findstring NT-5.1,$(VARIABLE))"

It matches the given string and returns

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