Makefile 中可以使用函数来处理变量,调用方式如下
$(foo a, b, c)
其中 foo 是函数名 a, b, c 是函数参数
make 编译中常用函数如下
字符串操作函数
函数名 | 原型 |
---|---|
字符串替换函数 | $(subst <from>, <to>, <text>) |
模式字符串替换函数 | $(patsubst <pattern>, <replacement>, <text>) |
字符串去空格函数 | $(strip <string>) |
字符串查找函数 | $(findstring <find>, <in>) |
字符串过滤函数 | $(filter <pattern...>, <text>) |
字符串反过滤函数 | $(filter-out <pattern...>, <text>) |
字符串排序函数 | $(sort <list>) |
取单词串函数 | $(wordlist <s>, <e>, <text>) |
统计单词数函数 | $(words <text>) |
取首单词函数 | $(firstword <text>) |
1. 字符串替换函数是将 < text > 字符串中的 < from > 子串替换为 < to > 串并返回,例如
$(subst .c, .o, foo.c bar.c.c)
此时函数的返回值为 foo.o bar.o.o
2. 模式字符串替换函数是查找 < text >中的单词符合模式 < pattern >的子串替换为 < replacement >