Makefile --- functions

Functions

Call Syntax

$(<function> <arguments>) or ${<function> <arguments>}

1) string handling function

1.1) subst
		Usage: $(subst <from>,<to>,<text>)	# replace <from> to <to> in <text>.
1.2) patsubst
		Usage: $(patsubst <pattern>,<replacement>,<text>)	# replace <pattern> in <text> to <replacement>.
1.3) filter
		Usage: $(filter <pattern>,<text>)	# return <pattern> in <text>.
1.4) fileter-out
		Usage: $(filter-out <pattern>,<text>)	# return out of <pattern> in <text>.
1.5) word
		Usage: $(word <n>,<text>)	# return the nth string in <text>.
1.6) words
		Usage: $(words <text>)	# return the numbers of string in <text>.
1.7) firstword
		Usage: $(firstword <text>)	# return the first string in <text>.
1.8) wordlist
		Usage: $(wordlist <n1>,<n2>,<text>)	# return the n1th to n2th string in <text>.
1.9) strip
		Usage: $(strip <text>)	# return the string after remove null characters at beginning and end of <text>.
1.10) findstring
		Usage: $(findstring <string> <text>)	# return the <string> in <text> or null string.
1.11) sort
		Usage: $(sort <text>)	# return the string sorted by ascending order.

2) filename handling function

2.1) dir
		Usage: $(dir <filepath>)	# return the part of Directory(the last part before "/" )
2.2) notdir
		Usage: $(notdir <filepath>)	# return the part of Non-directory(after the last "/" )
2.3) suffix
		Usage: $(suffix <filepath>)	# return the suffix of <filepath>
2.4) addsuffix
		Usage: $(addsuffix <suffix>,<file>)	# return the <file> added <suffix>
2.5) basename
		Usage: $(basename <filepath>)	# return the prefix(include path) of <filepath>
2.6) addprefix
		Usage: $(addprefix <prefix>,<file>)	# add <prefix> in front of <file>
2.7) join
		Usage: $(join <list1>,<list2>)	# add the content of list1 in front of the content of list2,respectively; Finally return the string after the connection.
										# if the numbers of list1 < the numbers of list2, then the rest content of list2 are copied in list2;   
										# if the numbers of list1 > the numbers of list2, then the rest content of list1 are remained the same;

3) foreach

	Usage: $(foreach <var>,<list>,<text> )
		   # 把参数<list>中的单词逐一取出放到参数<var>所指定的变量中,
		   # 然后再执行<text>所包含的表达式。每一次<text>会返回一个字符串,循环过程中,<text>的所返回的每个字符串会以空格分隔,
		   # 最后当整个循环结束时,<text>所返回的每个字符串所组成的整个字符串(以空格分隔)将会是foreach函数的返回值。
		e.x.
		 $(foreach d, spl tpl, $(patsubst %,$d/%,$(filter-out include, $(shell ls -1 $d 2>/dev/null))))
	   			 # d==spl $(patsubst %,$spl/%,$(filter-out include, $(shell ls -1 $spl 2>/dev/null)))
	   			 # d==tpl,$(patsubst %,$tpl/%,$(filter-out include, $(shell ls -1 $tpl 2>/dev/null)))

4) if

	Usage: $(if <condition>,<then-part>,<else-part>)
		# 如果<condition>为真(非空字符串),<then- part>会是整个函数的返回值;
		# 如果<condition>为假(空字符串),<else-part>会是整个函数的返回值; 此时如果<else-part>没有被定义,那么,整个函数返回空字串。

5) call

	Usage: $(call <expression>,<parm1>,<parm2>,<parm3>,...)
		# First, the <expression> is defined before;
		# When the <expression> is called by call function, the $1,$2,$3,..will be replaced by parm1,parm2,parm3...

6) origin

	Usage: $(origin <var>)
		# The purpose of the function is where the <var> came from;
		# Normally, return value probably is "command line","environment","default","override","undefined","file","automatic"

7) shell

	Usage: $(shell <command>)
		# <command> is OS shell commands.

8) 控制make的函数

	8.1) $(error <text>)	# Output the error information---<text>;
	8.2) $(warning <text>)	# Only output the warning information---<text>, the make is continue performed.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值