Linux下Makefile编写语法
Makefile
|
all : main.c foo1.c foo2.c foo3.c |
targets:prerequisites |
targets:目标文件名可以多个,空格隔开 |
|
|
|
%代表任意长度串,空格不属于 |
|
|
|
|
|
在Makefile中使用命令要Tab开始, 否则会出现“遗漏分隔符,停止”。 变量有(=)和(:=)两种,前者会造成递归定义。 (?=)如果左边变量未定义则赋予右值。 变量使用需要$(变量)或者${变量}。 |
全局变量 |
|
|
|
|
define 变量 |
全局变量 |
|
|
|
|
override 指示符 |
全局变量 |
|
|
|
|
$@目标集合 $<依赖目标集合 |
目标变量 |
自动化变量运行才有值 |
|
|
|
%.o :CFLAGS=-o |
目标模式变量 |
|
|
|
|
$(function argument1,argument2) |
函数调用 |
|
|
|
|
若干个单词串处理函数 |
$(subst replaceword,newword,sourceText |
|
$(subst ee,EE,feet on the street) |
fEEt on the strEEt |
|
空返回‘ ’ |
$(patsubst pattern,replacement,sourcetext) |
|
$(patsubst %.c,%.o,x.c.c bar.c) |
x.c.o bar.o |
|
|
$(findstring find,sourcetext) |
有返回对应,否则' ' |
|
|
|
|
$(filter pattern1 pattern2 ,sourceText) |
过滤器,返回SourceText符合 %.后缀的模式 |
|
|
|
|
$(filter-out pattern1 pattern2,sourceText) |
反过滤,返回不符合对应模式的 |
|
|
|
|
$(sort word1 word2) |
字母序升序排序且去重 |
|
|
|
|
$(word index_1,sourceText) |
取第index个单词(单词不是字符),从1开始 |
|
|
|
|
$(wordlist fromIndex_1,toIndex_1,sourceText) |
去从fromIndex到toIndex的文本单词 |
|
|
|
|
$(words sourceText) |
统计单词个数 |
|
|
|
|
$(firstword sourceText) |
返回首单词 |
|
|
|
文件名操作函数 |
$(dir name1 name2) |
取目录函数,返回文件所在目录,不包括文件名 |
$(dir usr/e/hha.c dd) |
usr/e/ ./ |
|
|
$(notdir name1 name2) |
取文件名 |
$(notdir usr/e/hh.c dd) |
hh.c dd |
|
|
$(suffix name1 name2) |
取后缀,无后缀‘ ’ |
|
|
|
|
$(basename name1 name2) |
取前缀,无前缀‘ ’ |
|
|
|
|
$(addsuffix suffix,sourceText) |
加后缀 |
|
|
|
|
$(addprefix prefix,sourceText) |
加前缀 |
|
|
|
|
$(join list1,list2) |
连接函数,对应index的连接,无对应自己 |
|
|
|
|
$(foreach oneOfList,list,EveryDealText) |
循环函数,list中取之局部变量oneOfList中,用到处理部分,每个返回空格连接 |
|
|
|
条件判断函数 |
ifeq (arg1,arg2) endif |
if equal 判断是否相等?真:假; |
|
|
|
|
ifneq (arg1,arg2) endif |
判断是否不等?真:假; |
|
|
|
|
ifdef variable-name endif |
变量有值?真:假; |
|
|
|
|
ifndef variable-name endif |
变量空值?真:假; |
|
|
|
|
$(if condition,then_part,else_part) |
|
|
|
|
|
$(if condition,then_part) |
|
|
|
|
其他函数 |
$(call expression,parm1,parm2) |
在expression中用到后面的parm1用$(1) |
reverse=$(2) $(2) |
b a |
|
|
$(origin variable) |
Undefined未定义 |
|
|
|
|
$(shell shell命令) |
生成一个shell程序来执行命令 |
$(shell echo just text) |
just text |
|
控制make的函数 |
$(error text) |
|
ifdef ERROR_001 |
|
|
|
$(warning text) |
|
|
|
|
模式规则 |
destiPattern:sourcePattern;command |
%.o:%.c |
|
|
|
@echo just text |
echo just text |
|
|
|
|
echo just text |
just text |
|
|
|
更多推荐



所有评论(0)