现在的位置: 首页 > 综合 > 正文

2011 2-22 Tuesday

2013年01月21日 ⁄ 综合 ⁄ 共 2092字 ⁄ 字号 评论关闭

6, makefile name: GNUmakefile makefile Makefile or

   any name you could specified : make -f XXmakefile.name

 

 7, include foo.make *.mk $(bar)

  make just expend the makefile content to the position of include xx.make

 

search path: current directory->-I directory(in command make's argument)

-><prefix>/include (/usr/local/bin or /usr)

 

if you want make to ignore the makefile didn't exist, add '-' before the

include keyword like: -include

 

8, env: MAKEFILES, we'd better remove the env. (Strongly recommend)

 

9, the working step of make

 

   a, read all makefile

   b, expend the makefiles which are included

   c, initialize the variables in the makefile

   d, expend 隐式规则, and analyze all rules

   e, build dependency chain of all targets

   f, rebuild target depend the relationships

   g, make the terminal target.

 

from a-e is the step one, f-g is the step two. In step one, the make

expend variable in "delay" method.

 

--------------------------------------------------------------------------------

 

1, rule grammar

targets : prerequisites

command

or

targets : prerequisites ; command

command

 

2, 规则中的通配符

   共享bash的, 例如: *, ?, ~

   make自身支持的, 例如: $?, $<, etc.

 

3, 文件搜索

   如果在当前目录找不到,则到makefile中定义的变量: VPAHT 中找。

   VPATH = src:../headers

   指定了两个目录:./src和../headers。目录由":"分割。

 

   vpath <pattern> <directories> #为符合模式的文件指定搜索目录

   vpath <pattern> #清除符合模式的文件的搜索路径

   vpath #清楚所有之前通过vpath设置的模式

   <pattern>需要包含 “%”, “%”匹配另个或若干字符

e.g: %.h stand for header file. %.c stand for C source code.

    vpath %.h ../headers

    vpath %.c ../source    

    vpath % blish

    vpath %.c ../bar

    搜索策略是先紧着文件类型来搜,然后再搜通用的目录。如上,搜 .c 文件

就是先搜 ../source, 然后是../bar, 最后搜./blish

 

4, 伪目标

    伪目标并不是一个文件,而是一个标签。

.PHONY : clean

不管是否有这个文件(clean),这个目标就是伪目标。

    伪目标的妙用:

######start of makefile#######

all : pg1 pg2 pg3

.PHONY: all

 

pg1: p.o u.o

pg3: x.o u.o

pg2: y.o u.o

######end of makefile#######

#由于伪目标的特性是,总是被执行 的

 

######start of makefile#######

.PHONY: cleanall cleanobj cleandiff

 

cleanall: cleanobj cleandiff

rm pg1 pg2 pg3

cleanobj:

rm *.o

cleandiff:

rm *.diff

######end of makefile#######

 

<<< subst 函数 $(subst string,substitute,$(variable))

obj= x.o y.o

$(subst .o,.c,$(obj))->x.c, y.c>>>

<<< filter 函数 $(filter <pattern>,$(variable))

var = x.o y.c

$(filter %.o,$(var)) -> x.o

5, 静态模式

<targets ...>: <target-pattern>: <prereq-patterns ...>

<commands>

e.g:

objects = foo.o bar.o

 

all: $(objects)

#静态模式

$(objects):%.o:%.c

$(CC) -c $(CFLAGS) $< -o $@

 

 

P23

【上篇】
【下篇】

抱歉!评论已关闭.