I'm trying to embed my Subversion revision number in a C++ project and am having problems setting up GNU make to do so. My makefile currently looks something like this:
check-svnversion:
../shared/update-svnversion-h.pl
../shared/svnversion.h: check-svnversion
shared/svnversion.o: ../shared/svnversion.h
.PHONY: check-svnversion
svnversion.o depends on svnversion.cpp (via a pattern rule) and svnversion.h (listed explicitly because dependency checking isn't picking it up for some reason). svnversion.h is created and maintained by the update-svnversion-h.pl script (which basically just runs svnversion and munges the output into a C++ file).
Currently, I have to run make twice to get the file up to date. The first time, make runs update-svnversion-h.pl (since it's listed as a prerequisite) but does not check the timestamp of svnversion.h afterwards to see that it was changed by update-svnversion-h.pl, so it does not remake svnversion.o. The second time, it does check the timestamp, runs update-svnversion-h.pl anyway (which doesn't do anything this time, since svnversion.h is up to date), then recompiles svnversion.cpp to make svnversion.o.
Is there a way to tell GNU make to evaluate a single prerequisite twice or to delay checking the timestamp on a prerequisite until after that prerequisite's commands are finished?
Alternatively, is there a better way to embed a revision number in my source code? (For the sake of speed, I'm trying to avoid solutions that would require recompilation on every build.)