Makefile的编写

e.g.

hello: hello.c

gcc -o hello hello.c

clean:

rm -f hello

 

1. 规则

目标(target)...:依赖(prerequiries)...

命令(command)

 

2. 赋值

延时变量

    =、?=、define

立即变量

    :=

 

3. 函数

字符串替换和分析函数

    (1)$ (subst from,to,text)

    (2)$ (patsubst pattern,replacement,text)

    (3)$ (strip string)

    (4)$ (findstring find,in)

    (5)$ (filter pattern...,text)

    (6)$ (filter-out pattern...,text)

    (7)$ (sort list)

文件名函数

    (1)$ (dir names...)

    (2)$ (notdir names...)

    (3)$ (suffix names...)

    (4)$ (basename names...)

    (5)$ (addsuffix suffix,names...)

    (6)$ (addprefix prefix,names...)

    (7)$ (wildcard pattern)

其他函数

    (1)$ (foreach var,list,next)

    (2)$ (if condition,then-part[,else-part])

    (3)$ (origin variable)

    (4)$ (shell command arguments)

其它

    $@ : 表示规则的目标文件名

    $^ : 表示所有依赖的名字,名字之间用空格隔开

    $< : 表示第一个依赖的文件名

    % : 通配符

 

posted @ 2017-10-27 16:48  wmxfd  阅读(142)  评论(0编辑  收藏  举报