【问题标题】:I can not understand the output of patsubst in a makefile我无法理解 makefile 中 patsubst 的输出
【发布时间】:2020-03-25 07:00:35
【问题描述】:

这是有罪的makefile:

$ cat -n example.mak
     1  define this
     2          $(patsubst $(1)/%.o,%.o,why_this_does/that.o)
     3          $(patsubst butnot/%.o,%.o, butnot/but_not_that.o)
     4  endef
     5
     6  why:
     7          $(info $(call this, why_this_does) ?)

这是我的问题:

$ make -f example.mak 
        why_this_does/that.o
        but_not_that.o ?
make: 'why' is up to date.

【问题讨论】:

    标签: function makefile output gnu-make substitution


    【解决方案1】:

    根本原因不在patsubst,而是在callThe manual有备注:

    最后的警告:在要调用的参数中添加空格时要小心。与其他函数一样,保留第二个和后续参数中包含的任何空格;这可能会导致奇怪的效果。在提供要调用的参数时,删除所有无关的空格通常是最安全的。

    事实上,如果你替换

    $(info $(call this, why_this_does) ?)
    

    通过

    $(info $(call this,why_this_does) ?)
    

    你得到你想要的。

    【讨论】:

    • @Dadam42,Makefile 中的空格总是很棘手。它们通常是单词分隔符,当您在​​某个地方想要一个空间时可能会很痛苦,然后它们不知从何而来并击中您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-04
    相关资源
    最近更新 更多