编译工具之makefile的常用函数
来源:互联网 发布:js修改class名称 编辑:程序博客网 时间:2024/06/06 13:10
字符串操作函数
wildcard
用法:$(wildcard pattern…)描述:匹配任何满足匹配规则的文件返回:返回包含所有匹配项的字符串
subst
用法:$(subst from,to,text)描述:将text中匹配from的字符替换为to返回:被替换后的字符串例子: $(subst ee,EE,feet on the street)结果: ‘fEEt on the strEEt’
patsubst
用法:$(patsubst pattern,replacement,text)描述:text中以空格分割的每个子串若匹配模式pattern则替换成replacement返回:替换后的字符串例子: $(patsubst %.c,%.o,x.c.c bar.c) $(var:suffix=replacement) 等价于 $(patsubst %suffix,%replacement,$(var))结果: ‘x.c.o bar.o’
strip
用法:$(strip string)描述:去掉字符串头或尾的空白字符返回:头或尾无空白字符的字符串
findstring
用法:$(findstring find,in)描述:查找满足查找条件find的字符串返回:查找结果例子: $(findstring a,a b c)结果: 'a'
filter
用法:$(filter pattern…,text)描述:过滤所有满足模式pattern的字符串返回:符合pattern的字符串例子: sources := foo.c bar.c baz.s ugh.h foo: $(sources) cc $(filter %.c %.s,$(sources)) -o foo结果: 'foo.c, bar.c, baz.s'
filter-out
用法:$(filter-out pattern…,text)描述:过滤所有不满足模式pattern的字符串返回:不符合pattern的字符串
sort
用法:$(sort list)描述:按首字母排序返回:排序后的字符串,空格分割例子: $(sort foo bar lose)结果: ‘bar foo lose’
word
用法:$(word n,text)描述:获取以空格分隔的字符串中的第n个子串,n从1开始返回:第n个子串例子: $(word 2, foo bar baz)结果: ‘bar’
wordlist
用法:$(wordlist s,e,text)描述:获取s->e的n个子串返回:返回从s开始到e的子串
words
用法:$(words text)描述:获取子串个数返回:返回用空格分隔的子串的个数
firstword
用法:$(firstword names…)描述:获取第一个子串返回:第一个子串
lastword
用法:$(lastword names…)描述:获取最后一个子串返回:最后一个子串
文件操作函数
dir
用法:$(dir names…)描述:获取当前names中的每个文件所对应的目录返回:对应的目录字符串例子: $(dir src/foo.c hacks)结果: ‘src/ ./’
notdir
用法:$(notdir names…)描述:获取当前names中的字符串所描述的文件部分返回:文件名字符串例子: $(notdir src/foo.c hacks)结果: ‘foo.c hacks’
suffix
用法:$(suffix names…)描述:返回文件后缀例子: $(suffix src/foo.c src-1.0/bar.c hacks)结果: ‘.c .c’
basename
用法:$(basename names…)描述:获取文件不带后缀的名例子: $(basename src/foo.c src-1.0/bar hacks)结果: ‘src/foo src-1.0/bar hacks’
addsuffix
用法:$(addsuffix suffix,names…)描述:给文件名添加后缀例子: $(addsuffix .c,foo bar)结果: ‘foo.c bar.c’
addprefix
用法:$(addprefix prefix,names…)描述:给文件名添加前缀例子: $(addprefix src/,foo bar)结果: ‘src/foo src/bar’
join
用法:$(join list1,list2)描述:将list1与list2连接起来例子: $(join a b,.c .o)结果: ‘a.c b.o’
realpath
用法:$(realpath names…)描述:返回每个文件的绝对路径
abspath
用法:$(abspath names…)描述:与realpath功能相同,但abspath不处理链接,也不保证相应文件一定存在
条件判断函数
if
用法:$(if condition,then-part[,else-part])描述:用于if条件判断
or
用法:$(or condition1[,condition2[,condition3…]])描述:用于或条件判断
and
用法:$(and condition1[,condition2[,condition3…]])描述:用于与条件判断
其它函数
foreach
用法:$(foreach var,list,text)描述:遍历list中的元素,text是额外的过滤条件例子: dirs := a b c d files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))结果: files := $(wildcard a/* b/* c/* d/*)
file
用法:$(file op filename[,text])描述:用于读写文件,读模式下没有参数text,写模式下text将被写入文件filename,op与filename之间可以没有空格分隔 op的可选项为: <——读 >——写 >>——追加写例子: program: $(OBJECTS) $(file >$@.in,$^) $(CMD) $(CMDFLAGS) @$@.in @rm $@.in
call
用法:$(call variable,param,param,…)描述:可以创建复杂的宏定义表达式,用call进行展开例子: pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH))))) LS := $(call pathsearch,ls)结果: LS将变成一个可用的ls命令所在的路径
value
用法:$(value variable)描述:例子: FOO = $PATH all: @echo $(FOO) @echo $(value FOO)
eval
用法:$(eval expression)描述:eval包含的表达式或值会被扩展两次,返回值为空例子: PROGRAMS = server client server_OBJS = server.o server_priv.o server_access.o server_LIBS = priv protocol client_OBJS = client.o client_api.o client_mem.o client_LIBS = protocol .PHONY: all all: $(PROGRAMS) define PROGRAM_template = $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) ALL_OBJS += $$($(1)_OBJS) endef $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog)))) $(PROGRAMS): $(LINK.o) $^ $(LDLIBS) -o $@ clean: rm -f $(ALL_OBJS) $(PROGRAMS)
origin
用法:$(origin variable)描述:用于检查一个变量的属性返回: ‘undefined’——这个变量未定义 ‘default’——该变量默认被定义,如CC等 ‘environment’——表明该变量继承自环境变量 ‘environment override’——变量继承自环境变量,在makefile中已经被重写 ‘file’——该变量在makefile中被定义 ‘command line’——该变量在命令行中被定义 ‘override’——该变量在makefile中用override重写 ‘automatic’——该变量是一个自动变量
flavor
用法:$(flavor variable)描述:检查变量的属性返回: ‘undefined’——这个变量未定义 ‘recursive’——变量是一个递归展开的变量 ‘simple’——变量是一个简单展开的变量
shell
用法:$(shell command)描述:执行shell命令
guile
用法:$(guile variable)描述:variable先会由make进行扩展,然后会被送入GNU Guile求值器,最终求值器得到的值会被转化为字符串作为variable的最终结果
控制make的函数
error
用法:$(error text…)描述:产生一个错误信息,终止编译
warn
用法:$(warning text…)描述:产生一个警告信息
info
用法:$(info text…)描述:打印常规log信息
0 0
- 编译工具之makefile的常用函数
- Makefile之------Makefile中常用的函数
- [编译相关]系列4:Makefile中常用的函数
- Makefile的常用函数
- Makefile文件之我的常用模板编译中小型项目
- Makefile之常用函数介绍
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- makefile 中常用的函数
- Makefile中常用的函数
- Makefile中常用的函数
- app的api维护多个版本
- java 高并发解决方案和高负载优化方法
- 欢迎使用CSDN-markdown编辑器
- ios微信支付
- Myeclipse中Mybatis Generator自动创建代码总结
- 编译工具之makefile的常用函数
- ie9杂项兼容
- NDIS中间层驱动网络连接属性隐藏
- Maven最佳实践:划分模块
- H5 按钮置底
- The Linux Programming Interface 16
- 完全数
- JDK7源码阅读-String
- Eclipse 没有Data Source Explorer