使所有规则取决于Makefile本身 [英] making all rules depend on the Makefile itself

查看:69
本文介绍了使所有规则取决于Makefile本身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改Makefile时,其规则可能已更改,因此应重新评估它们,但make似乎并不这么认为.

When I change a Makefile, its rules may have changed, so they should be reevaluated, but make doesn't seem to think so.

在Makefile中,有没有办法说其所有目标(无论哪个目标)都取决于Makefile本身? (不管它的名字如何.)

Is there any way to say, in a Makefile, that all of its targets, no matter which, depend on the Makefile itself? (Regardless of its name.)

我正在使用GNU make.

I'm using GNU make.

推荐答案

这看起来是Make应该可以做的,但不是可以做的一件简单,有用,合乎逻辑的事情.

This looks like one more simple, useful, logical thing that Make should be able to do, but isn't.

这是一种解决方法.如果正确设置了clean规则,则只要使用空白的dummy文件作为标记,Make就可以在更改了Makefile时执行该规则.

Here is a workaround. If the clean rule is set up correctly, Make can execute it whenever the makefile has been altered, using an empty dummy file as a marker.

-include dummy

dummy: Makefile
    @touch $@
    @$(MAKE) -s clean

这将适用于大多数目标,这些目标是实际文件并已被干净删除,并且依赖于这些目标的任何目标.副作用目标和某些PHONY目标将通过网络滑脱.

This will work for most targets, that is targets that are actual files and that are removed by clean, and any targets that depend on them. Side-effect targets and some PHONY targets will slip through the net.

这篇关于使所有规则取决于Makefile本身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆