【问题标题】:gnu make findstring in argument containing pathgnu 在包含路径的参数中生成 findstring
【发布时间】:2021-12-08 23:49:32
【问题描述】:

我有一个简单的条件语句(我需要内联条件语句):

$(if $(findstring foo,$1),yes,no)

如果我打印出 $1 它可以包含如下路径:

../.././foo/bar/src/io

但是,它不会评估为是? 如果我只是复制粘贴该路径而不是变量(arg):

$(if $(findstring foo,../.././foo/bar/src/io),yes,no)

它评估为是。

【问题讨论】:

  • 除非您告诉使用您在何处以及如何使用此 $(if ...) 语句,否则无法解释此行为。 一切取决于$1 是什么以及如何使用它。它是否用作 make call 的一部分?它在食谱中使用吗?等等。

标签: makefile gnu-make gnu


【解决方案1】:

不,它不会“评估为真”,它扩展为yes

$(findstring foo,../.././foo/bar/src/io)

扩展为foo(因为存在匹配)并且:

$(if foo,yes,no)

扩展为yes(因为foo 不是空字符串)。比较:

$(if $(findstring baz,../.././foo/bar/src/io),yes,no)

扩展为no,因为没有匹配项并且:

$(findstring baz,../.././foo/bar/src/io)

扩展为空字符串。请注意,如果路径作为变量传递,它不会改变任何内容,因为变量首先展开:

$ cat Makefile
define MACRO
$(if $(findstring foo,$1),yes,no)
endef

$(info foo: $(call MACRO,../.././foo/bar/src/io))
$(info baz: $(call MACRO,../.././baz/bar/src/io))

.PHONY: all
all:;
$ make
foo: yes
baz: no
make: 'all' is up to date.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多