代码之家  ›  专栏  ›  技术社区  ›  Pablo

makefile:包含字符串

  •  54
  • Pablo  · 技术社区  · 14 年前

    变量返回 MINGW32_NT-5.1 CYGWIN_NT-5.1. (是的,结尾有点)

    需要比较给定的var包含的 NT-5.1 定位在任何地方。

    使用cygwin,希望与几乎所有*nix兼容。

    2 回复  |  直到 8 年前
        1
  •  90
  •   John Kugelman Michael Hodel    14 年前

    这个 findstring 功能是你的心脏所需要的:

    $(findstring 找到 , 在里面 )

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

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

    产生价值观 "a" "" (空字符串)。见 Testing Flags ,以便实际应用 findstring .

    类似:

    ifneq (,$(findstring NT-5.1,$(VARIABLE)))
        # Found
    else
        # Not found
    endif
    
        2
  •  15
  •   vimjet    8 年前
    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))"
    

    它匹配给定的字符串并返回

    推荐文章