Makefile中字符串操作函数

makefile函数调用的形式:

$(function args)

function:函数名
args: 函数参数。参数和函数名之间用空格或tab键隔开,多个参数之间用逗号隔开。

1、subst – 特定字符串替换

$(subst from,to,text)

在文本"text"中使用"to"替换每一处"from"
例子:

$(subst ee,EE, feet on the street)

输出:
在这里插入图片描述

2、patsubst – 类似正则表达式的替换

$(patsubst pattern,replacement,text)

寻找"text"中符合格式"pattern"的字,用"replacement"替换他们。"pattern"和"replacement"可以使用通配符(%)。

%通配符是Makfile内的;

*通配符是shell脚本里的。

例子:

$(patsubst %.c,%.o,x.c.c bar.c)

输出结果为:
在这里插入图片描述

3、strip – 去除多余空格

$(strip string)

去掉前导和结尾空格,并将中间的多个空格压缩为单个空格
例子:

$(strip a    b c)

输出:a b c

4、findstring – 字符串查找

$(findstring find,in)

在in字符串中寻找find字符串,找到的话返回find否则返回空
例子:

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

输出为:

a 和  " "

5、filter – 类似正则表达式的字符筛选操作

$(filter pattern..., text)

返回在"text"中用空格隔开且匹配格式"pattern…"的字,去除不符合格式"pattern…"的字。
例子:

$(filter %.c %.s, foo.c bar.c baz.s ugh.h)

输出为:

foo.c bar.c baz.s

6、sort – 排序去重

$(sort  list)

将"list"中的字按字母顺序排序并去掉重复的字。输出由单个空格隔开的字的列表
例子:

$(sort foo bar lose)

输出:

"bar foo lose"

猜你喜欢

转载自blog.csdn.net/FPGATOM/article/details/84549566