makefile编写(三)

2018-09-27  本文已影响0人  yshi2017

----1.makefile内置变量都是大写的。

-----2. 自定义变量

obj  = main.o  add.o  sub.o  mul.o 

取obj的值 : $obj

------3. 自动变量:(只能用在命令里)

$@:规则中的目标

$< :规则中的第一个依赖

$^ :规则中的所有依赖

改进makefile如下:

obj  = main.o  add.o  sub.o  mul.o 

target  = app

$(target) : $(obj)

(tab)  gcc  $(obj)  -o  $(target)

%.o : %.c     //  makefile中的模式匹配,依次用%套用main,add,sub,mul

(tab)   gcc  -c  $<  -o  %@

缺点:通用性差

上一篇 下一篇

猜你喜欢

热点阅读