Chinaunix首页 | 论坛 | 博客
  • 博客访问: 70977
  • 博文数量: 26
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 35
  • 用 户 组: 普通用户
  • 注册时间: 2015-09-27 23:09
文章分类

全部博文(26)

文章存档

2016年(14)

2015年(12)

我的朋友

分类: LINUX

2016-02-18 14:55:34

Makefile---相同目标如何处理
如果Makefile中有多个相同的目标,它是怎么执行的?

target1: dep1
target1: dep2
           cmd2

这种情况下,这两个相同的target1会被合并成

 target1: dep1 dep2
         cmd2

sample01:
[javascript] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #测试多个相同目标,是如何执行的  
  2.   
  3. all: test  
  4.   
  5. test: a.c a.h  
  6.       
  7. test: a.c  
  8.     echo "02 target" #flag the second target  
  9.     echo $^          #print the second target depend      
  10.       
执行结果:



但如果第一条规则本身也带一个命令的话, makefile就无法合并, 给出警告,并用后面的规则替代前面的规则

target1: dep1
          cmd1
target1: dep2
           cmd2


最后生成的是, 其实就是后一条替代了前一条,然后给出警告

 target1: dep2
       cmd2
sample02:
[javascript] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. #测试多个相同目标,是如何执行的  
  2.   
  3. all: test  
  4.   
  5. test: a.c a.h  
  6.     echo "01 target" #flag the first target  
  7.     echo $^          #print the first target depend  
  8.       
  9. test: a.c  
  10.     echo "02 target" #flag the second target  
  11.     echo $^          #print the second target depend      
  12.       

执行结果:

阅读(1365) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~