I have a top-level makefile which is auto-generated by my custom build tool from various configuration files: I would like the makefile to be able to re-make itself when it is out of date. To do this, I have the following rule:
<absolute path to makefile>: <list> <of> <configuration> <files>
@echo "Rebuilding top-level makefile"
@<invoke my build tool>
I'm using GNU Make 4.3 which claims to support this, as detailed here, where it claims that "after all makefiles have been checked, if any have actually been changed, make starts with a clean slate and reads all the makefiles over again."
The problem I have is that although this rule is invoked correctly (but not implicitly, I actually need another PHONY default goal which has the makefile as a prerequesite), it seems that make does not reload the makefile even after it has been changed. I note that make does correctly reload included makefiles when they have a recipe and are out of date: it's only this top-level makefile which has the problem.
The effect of this is that the other rules in the file are out of date, and changes are only reflected in the subsequent invocation of make.
My current solution is to have the makefile recipe return a non-zero exit code and echo a warning asking the user to re-run make: I tried using ($error _)
, but this didn't have the intended effect.
It seems GNU Make claims to support this use-case, so I presume I must be doing something wrong here?