Makefile的使用与分析4--Makefile的函数

Makefile的函数

$(foreach var,list,text)var变量 list列表 text执行效果

a = a b c
b = $(foreach f, $a, $(f).o)
all:
	@echo b = $b

执行make

b = a.o b.o c.o

$(filter pattern…,text)在text中取出符合patten格式的值

a = a.o b.o c
b = $(filter %.o, $(a))
all:
	@echo b = $b

执行make

b = a.o b.o

$(filter-out pattern…,text) # 在text中取出不符合patten格式的值

a = a.o b.o c
b = $(filter-out %.o, $(a))
all:
	@echo b = $b

执行make

b = c

$(wildcard pattern) # pattern定义了文件名的格式, # wildcard取出其中存在的文件

在这里插入图片描述

file = $(wildcard *.c)
all:
	@echo file = $(file)

执行make

file = a.c b.c

判断文件是否真正存在

file1 = a.c b.c c.c e.c 
file = $(wildcard $(file1))
all:
	@echo file = $(file)

执行make

file = a.c b.c

$ ( p a t s u b s t p a t t e r n , r e p l a c e m e n t , (patsubst pattern,replacement, (patsubstpattern,replacement,(var)) # 从列表中取出每一个值 # 如果符合pattern则替换为replacement

file1 = a.c b.c c.c e.c 
file = $(patsubst %.c,%.d,$(file1))
all:
	@echo file = $(file)

执行make

file = a.d b.d c.d e.d

你可能感兴趣的:(GCC和Make的使用与分析)