本文共 17269 字,大约阅读时间需要 57 分钟。
null=
space = $(null) $(null)
string1 ="Functions for Transforming Text"
print:
@echo $(subst $(space),-, $(string1))
malihou@ubuntu:~$ make
-Functions-for-Transforming-Text
malihou@ubuntu:~$
null=
space = $(null) $(null)
comma =,
lparenthes =(
rparenthes =)
lbrace ={
rbrace =}
# string1 = \(a\) \{b\} c
string1 = $(space)\$(lparenthes)a\$(rparenthes) \$(lbrace)b\$(rbrace) c
print:
@echo $(subst $(space),$(comma),$(string1))
@echo $(subst $(space),$(comma), $(string1))
@echo $(subst $(lparenthes),*,$(string1))
@echo $(subst $(rparenthes),*,$(string1))
@echo $(subst $(lbrace),*,$(string1))
@echo $(subst $(rbrace),*,$(string1))
malihou@ubuntu:~$ make
,(a),{ b},c
,,(a),{ b},c
*a){ b} c
(a*{ b} c
(a)*b} c
(a){ b* c
malihou@ubuntu:~$
staticstruct function_table_entry function_table_init[]=
{
/* Name MIN MAX EXP? Function */
FT_ENTRY ("abspath",0,1,1, func_abspath),
FT_ENTRY ("addprefix",2,2,1, func_addsuffix_addprefix),
FT_ENTRY ("addsuffix",2,2,1, func_addsuffix_addprefix),
FT_ENTRY ("basename",0,1,1, func_basename_dir),
FT_ENTRY ("dir",0,1,1, func_basename_dir),
FT_ENTRY ("notdir",0,1,1, func_notdir_suffix),
FT_ENTRY ("subst",3,3,1, func_subst),
FT_ENTRY ("suffix",0,1,1, func_notdir_suffix),
FT_ENTRY ("filter",2,2,1, func_filter_filterout),
FT_ENTRY ("filter-out",2,2,1, func_filter_filterout),
FT_ENTRY ("findstring",2,2,1, func_findstring),
FT_ENTRY ("firstword",0,1,1, func_firstword),
FT_ENTRY ("flavor",0,1,1, func_flavor),
FT_ENTRY ("join",2,2,1, func_join),
FT_ENTRY ("lastword",0,1,1, func_lastword),
FT_ENTRY ("patsubst",3,3,1, func_patsubst),
FT_ENTRY ("realpath",0,1,1, func_realpath),
FT_ENTRY ("shell",0,1,1, func_shell),
FT_ENTRY ("sort",0,1,1, func_sort),
FT_ENTRY ("strip",0,1,1, func_strip),
FT_ENTRY ("wildcard",0,1,1, func_wildcard),
FT_ENTRY ("word",2,2,1, func_word),
FT_ENTRY ("wordlist",3,3,1, func_wordlist),
FT_ENTRY ("words",0,1,1, func_words),
FT_ENTRY ("origin",0,1,1, func_origin),
FT_ENTRY ("foreach",3,3,0, func_foreach),
FT_ENTRY ("call",1,0,1, func_call),
FT_ENTRY ("info",0,1,1, func_error),
FT_ENTRY ("error",0,1,1, func_error),
FT_ENTRY ("warning",0,1,1, func_error),
FT_ENTRY ("if",2,3,0, func_if),
FT_ENTRY ("or",1,0,0, func_or),
FT_ENTRY ("and",1,0,0, func_and),
FT_ENTRY ("value",0,1,1, func_value),
FT_ENTRY ("eval",0,1,1, func_eval),
FT_ENTRY ("file",1,2,1, func_file),
#ifdef EXPERIMENTAL
FT_ENTRY ("eq",2,2,1, func_eq),
FT_ENTRY ("not",0,1,1, func_not),
#endif
};
函数分类 | 个数 |
字符串替换和分析函数(Functions for String Substitution and Analysis) | 12 |
文件名函数(Functions for File Names) | 10 |
条件语句函数(Functions for Conditionals) | 3 |
foreach 函数(The foreach Function) | 1 |
file 函数(The file Function) | 1 |
call 函数(The call Function) | 1 |
value 函数(The value Function) | 1 |
eval 函数(The eval Function) | 1 |
origin 函数(The origin Function) | 1 |
flavor 函数(The flavor Function) | 1 |
make 控制函数(Functions That Control Make) | 3 |
shell 函数(The shell Function) | 1 |
函数语法 | 函数功能描述 |
$(subst from,to,text) | 字符串替换 |
$(patsubst pattern,replacement,text) | 模式字符串替换 |
$(strip string) | 去空白 |
$(findstring find,in) | 字符串查找 |
$(filter pattern...,text) | 过滤 |
$(filter-out pattern...,text) | 反过滤 |
$(sort list) | 排序 |
$(word n,text) | 取第 n 个位置单词 |
$(wordlist s,e,text) | 取单词列表 |
$(words text) | 单词个数 |
$(firstword names...) | 取首单词 |
$(lastword names...) | 取末尾单词 |
string="feet on the street"
print:
@echo $(subst ee,EE,$(string))
malihou@ubuntu:~$ make
fEEt on the strEEt
malihou@ubuntu:~$
sources =1.c2.c test.c
objects = $(patsubst %.c,%.o,$(sources))
file1 =%1.%.tmp 1%1.%45.%
file2 = $(patsubst \%%.%,%.bak,$(file1))
file3 = $(patsubst %.%,%.bak,$(file1))
print:
@echo"sources=$(sources)"
@echo"objects=$(objects)"
@echo"file1=$(file1)"
@echo"file2=$(file2)"
@echo"file3=$(file3)"
malihou@ubuntu:~$ make
sources=1.c2.c test.c
objects=1.o2.o test.o
file1=%1.%.tmp 1%1.%45.%
file2=%1.%.tmp 1%1.%45.%
file3=%1.%.tmp 1%1.bak45.bak
malihou@ubuntu:~$
cpps = foo.cpp bar.cpp baz.cpp
obj1 = $(cpps:cpp=o)
obj2 = $(cpps:.cpp=.o)
obj3 = $(patsubst %cpp,%o,$(cpps))
obj4 = $(patsubst %.cpp,%.o,$(cpps))
print:
@echo obj1=$(obj1)
@echo obj2=$(obj2)
@echo obj3=$(obj3)
@echo obj4=$(obj4)
malihou@ubuntu:~$ make
obj1=foo.o bar.o baz.o
obj2=foo.o bar.o baz.o
obj3=foo.o bar.o baz.o
obj4=foo.o bar.o baz.o
malihou@ubuntu:~$
string= hello world
ifeq ($(string),hello world)
output_str1 = equal
else
output_str1 =not equal
endif
ifeq ($(strip $(string)),hello world)
output_str2 = equal
else
output_str2 =not equal
endif
print:
@echo"$(string)"
@echo"$(strip $(string))"
@echo"$(output_str1)"
@echo"$(output_str2)"
malihou@ubuntu:~$ make
hello world
hello world
not equal
equal
malihou@ubuntu:~$
string= hello world
ifeq '$(findstring world,$(string))'''
output_str1 = search fail
else
output_str1 = search success
endif
ifeq '$(findstring World,$(string))'''
output_str2 = search fail
else
output_str2 = search success
endif
print:
@echo $(output_str1)
@echo $(output_str2)
malihou@ubuntu:~$ make
search success
search fail
malihou@ubuntu:~$
lists =1.c phone.c Camera.o computer.obj 0.mak phone.c
print: @echo filter=$(filter %.c %.mak,$(lists)) @echo filter_out=$(filter-out%.c %.mak,$(lists))
malihou@ubuntu:~$ make
filter=1.c phone.c 0.mak phone.c
filter_out=Camera.o computer.obj
malihou@ubuntu:~$
lists =1 phone Camera computer 0 phone
print:
@echo"$(sort $(lists))"
malihou@ubuntu:~$ make
01Camera computer phone
malihou@ubuntu:~$
VPATH="src:../headers"
print:
@echo CFLAGS=$(patsubst %,-I%,$(subst :,,$(VPATH)))
malihou@ubuntu:~$ make
CFLAGS=-Isrc-I../headers
malihou@ubuntu:~$
函数语法 | 函数功能描述 |
$(dir names...) | 取文件的目录部分 |
$(notdir names...) | 取文件的非目录部分 |
$(suffix names...) | 取文件的后缀 |
$(basename names...) | 取文件的文件名 |
$(addsuffix suffix,names...) | 给文件附加后缀 |
$(addprefix prefix,names...) | 给文件附加前缀 |
$(join list1,list2) | 列表单词连接 |
$(wildcard pattern) | 文件通配 |
$(realpath names...) | 取真实路径 |
$(abspath names...) | 取绝对路径 |
转载地址:http://rosgi.baihongyu.com/