Makefile : 包含字符串 [英] Makefile : contains string

查看:42
本文介绍了Makefile : 包含字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个变量返回 MINGW32_NT-5.1CYGWIN_NT-5.1.(是的,点在末尾)

需要比较给定的 var 包含位于任何位置的 NT-5.1.

使用 cygwin 并希望与几乎任何 *nix 兼容.

解决方案

findstring 功能是你的心愿:

<块引用>

$(findstring find,in)

in 中搜索 find.如果发生,则值为find;否则,该值为空.您可以在条件中使用此函数来测试给定字符串中是否存在特定子字符串.因此,这两个例子,

$(查找字符串 a,a b c)$(查找字符串 a,b c)

分别产生值 "a"""(空字符串).Testing Flags查找字符串.

类似:

ifneq (,$(findstring NT-5.1,$(VARIABLE)))# 成立别的# 未找到万一

<块引用>

这里 ifneq (,$(...?

的逗号是什么

将其解析为 ifneq(A,B) 其中 A 是空字符串,B$(findstring...).这看起来很奇怪,因为您没有在 Makefile 中引用字符串.

A variable returns MINGW32_NT-5.1 or CYGWIN_NT-5.1. (yea, dot at the end)

Need to compare that given var contains NT-5.1 positioned anywhere.

Using cygwin and would like to be compatible with pretty much any *nix.

解决方案

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

What is the comma here for ifneq (,$(...?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆