Makefile的call函数

http://blog.csdn.net/codesinger/article/details/9316251


写了个例子来研究Makefile的call函数:

[plain]  view plain copy
  1. #define a multiline variable  
  2. define target   
  3.     echo $@  
  4.     echo $@  
  5. endef  
  6.   
  7. #define the target which is the first target, so default target  
  8. all:  
  9.     $(call target,all)  
  10.   
  11. #define the second target, we must explicitly make it  
  12. clean:  
  13.     $(call target,clean)      
  14.   
  15. #declare that all and clean are phony targets  
  16. .PHONY: all clean  

执行make或make all的结果是:

[plain]  view plain copy
  1. echo all  
  2. all  
  3. echo all  
  4. all  


执行make clean的结果是:

[plain]  view plain copy
  1. echo clean  
  2. clean  
  3. echo clean    
  4. clean  

其实源代码可以这么写的:

[plain]  view plain copy
  1. #define a multiline variable  
  2. define target   
  3.     echo $@  
  4.     echo $@  
  5. endef  
  6.   
  7. #define the target which is the first target, so default target  
  8. all:  
  9.     $(call target)  
  10.   
  11. #define the second target, we must explicitly make it  
  12. clean:  
  13.     $(call target)    
  14.   
  15. #declare that all and clean are phony targets  
  16. .PHONY: all clean  

结果跟上面一样。


小结:Makefile中的第一个目标是最终目标,是make默认执行的目标,call函数会以此调用多行变量的每一个(此处是make命令,所以会被执行了)。然后$@自动化变量在make执行是会被赋值为当前的目标。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值