1.文本處理和分析函數正則表達式
$(subst from,to,text) 替換shell
$(patsubst pattern,replacement,text) 模式替換,可用%(只用第一個%有用),如 $(patsubst %.c,%.o,x.c.c bar.c),結果 ‘x.c.o bar.o’ide
$(strip string) 去掉文本兩端空格,以及把2個和2個以上的空格換成一個函數
$(findstring find,in) 查找this
$(filter pattern…,text) 過濾,只保留pattern部分spa
$(filter-out pattern…,text) 過濾掉,不保留pattern部分命令行
$(sort list) 排序code
$(word n,text) 取字符串排序
$(wordlist s,e,text) 取字符串列表 第s(start)個到第e(end)個ip
$(words text) Returns the number of words in text. Thus, the last word of text is $(word $(words text),text)
.
$(firstword names…) 取第一個
$(lastword names…) 去最後一個
2.文件名處理函數
$(dir names…) 取目錄
$(notdir names…) 取文件,但並不徹底正確,注意觀察,由於這個原理是已斜槓「/」爲標識符的,若是文件名中包含斜槓,則返回的文件名就有誤
$(suffix names…) 去文件後綴
$(basename names…) 去文件名,包括前面的目錄部分,如$(basename src/foo.c src-1.0/bar hacks), 結果爲 src/foo src-1.0/bar hacks
$(addsuffix suffix,names…) 添加後綴
$(addprefix prefix,names…) 添加前綴,example : $(addprefix src/,foo bar),produces the result ‘src/foo src/bar’.
$(join list1,list2) 鏈接函數 example: ‘$(join a b,.c .o)’ produces ‘a.c b.o’.
$(wildcard pattern) 通配符函數,表示可使用正則表達式的符號。The argument pattern is a file name pattern, typically containing wildcard characters (as in shell file name patterns). The result of wildcard
is a space-separated list of the names of existing files that match the pattern
$(realpath names…) 真實路徑
$(abspath names…) 絕對路徑
3. foreach函數
$(foreach var,list,text) 至關於for循環函數,不過最終這裏返回的是text的值,這個值是循環獲得的一個list,如
find_files = $(wildcard $(dir)/*) 「=」等號是延時加載(deferred)
dirs := a b c d
files := $(foreach dir,$(dirs),$(find_files))
即
files := $(wildcard a/* b/* c/* d/*)
4. if函數
ifeq (arg1, arg2)
ifneq (arg1, arg2)
ifdef variable-name
ifndef variable-name
5. call函數
$(call VARIABLE,PARAM,PARAM,...)
「call」函數是惟一一個能夠建立定製化參數函數的引用函數。使用這個函數能夠 實現對用戶本身定義函數引用。咱們能夠將一個變量定義爲一個複雜的表達式,用「call」 函數根據不一樣的參數對它進行展開來得到不一樣的結果。
如:reverse = $(2) $(1) foo = $(call reverse,a,b) foo will contain ‘b a
6. value函數
$(value variable)
The result of this function is a string containing the value of variable, without any expansion occurring. For example, in this makefile:
FOO = $PATH all: @echo $(FOO) @echo $(value FOO)
The first output line would be ATH
, since the 「$P」 would be expanded as a make
variable, while the second output line would be the current value of your $PATH
environment variable, since the value
function avoided the expansion.
7. origin函數
$(origin variable) 獲取變量的屬性值,以下幾個
1. undefined 變量「VARIABLE」沒有被定義。
2. default 變量「VARIABLE」是一個默認定義(內嵌變量)。如「CC」、「MAKE」、「RM」等變 量。若是在 Makefile 中從新定義這些變量,函數返回值將相應發生變化。
3. environment 變量「VARIABLE」是一個系統環境變量,而且 make 沒有使用命令行選項「-e」 (Makefile 中不存在同名的變量定義,此變量沒有被替代)。
4. environment override 變量「VARIABLE」是一個系統環境變量,而且 make 使用了命令行選項「-e」。 Makefile 中存在一個同名的變量定義,使用「make -e」時環境變量值替代了文 件中的變量定義。
5. file 變量「VARIABLE」在某一個 makefile 文件中定義。
6. command line 變量「VARIABLE」在命令行中定義。
7. override 變量「VARIABLE」在 makefile 文件中定義並使用「override」指示符聲明。
8. automatic 變量「VARIABLE」是自動化變量。
8. shell函數
contents := $(shell cat foo)
files := $(shell echo *.c)
9. make LOG以及控制函數
$(info text) 打印log
$(warning text) 和 error 同樣,可是 產生致命錯誤退出
$(error text) 產生致命錯誤,並提示「text」信息給用戶,並退出 make 的執行