Makefile:包含字符串 [英] Makefile : contains string
问题描述
变量返回MINGW32_NT-5.1
或CYGWIN_NT-5.1.
(是的,结尾处是点)
A variable returns MINGW32_NT-5.1
or CYGWIN_NT-5.1.
(yea, dot at the end)
需要比较给定的var包含位于任何位置的NT-5.1
.
Need to compare that given var contains NT-5.1
positioned anywhere.
使用cygwin,并希望与几乎所有* nix兼容.
Using cygwin and would like to be compatible with pretty much any *nix.
推荐答案
The findstring function is what your heart desires:
$(findstring find,in)
在 in 中搜索是否找到 .如果发生,则值为 find ;否则,该值为空.您可以在有条件的情况下使用此函数来测试给定字符串中是否存在特定子字符串.因此,这两个例子
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)
分别产生值"a"
和""
(空字符串).请参阅测试标记,以了解findstring
.
produce the values "a"
and ""
(the empty string), respectively. See Testing Flags, for a practical application of findstring
.
类似的东西:
ifneq (,$(findstring NT-5.1,$(VARIABLE)))
# Found
else
# Not found
endif
这里
ifneq (,$(...
的逗号是什么?
将其解析为ifneq(A,B)
,其中 A 是空字符串,而 B 是$(findstring...)
.看起来很奇怪,因为您没有在Makefile中引用字符串.
Parse it as ifneq(A,B)
where A is the empty string and B is $(findstring...)
. It looks odd because you don't quote strings in Makefiles.
这篇关于Makefile:包含字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!