关于makefile中,一直显示“XXX is up to date”的解决方法

最近更新一个项目的makefile文件,在添加一个makefile target的时候,发现总是出现“is up to date”的提示,书写语法无任何不妥,始终找不到原因,最后google了下,找到了解决方案。


在stackoverflow上,有人给出的问题原因如下:

Your have directories with the same name as your targets.

Since your targets don't depend on anything, they'll always be considered up to date.


可见这是makefile target和dir名字冲突造成的,解决方法则是借助.PHONY。


在GNU的官网上,是这么解释的:

A phony target is one that is not really the name of a file; rather it is just a name for a recipe to be executed when you make an explicit request. There are two reasons to use a phony target: to avoid a conflict with a file of the same name, and to improve performance.

If you write a rule whose recipe will not create the target file, the recipe will be executed every time the target comes up for remaking. 


出处: http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html


不难看出,GNU默认makefile target是一个文件,因此他会先检测同级目录下是否已存在这个文件,如果存在,则会abort掉make 进程,但目标不是文件的话,则会出现up to date的情况,这种情况需要.PHONY来避免问题的出现,phony的意思是“赝品”,在这里可以形象的理解成“不是文件”。


  • 8
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值