making all rules depend on the Makefile itself

こ雲淡風輕ζ 提交于 2019-11-27 22:05:57

问题


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

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.)

I'm using GNU make.


回答1:


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

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

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.




回答2:


The only answer I know to this is to add makefile explicitly to the dependencies. For example,

%.o: %.c makefile
        $(CC) $(CFLAGS) -c $<


来源:https://stackoverflow.com/questions/3871444/making-all-rules-depend-on-the-makefile-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!