IMHO, the only solution to this is to consider this file always deprecated with a fake dependency. Every time you compile, it must be restored. A slightly more elegant solution is to always generate gitref.c.tmp and then copy it to gitref.c only if the files are different (for example, in * NIX, as a system, you can use cmp to compare them byte-by-bye). If they match, just delete the temporary file.
EDIT : the following Makefile snippet works for me
PHONY: gitref_dummy gitref_dummy: gitref.c: gitref_dummy @echo "const char *gitref = \"$$(git describe --tags --dirty --long)\";" > \ gitref.c.tmp @cmp -s gitref.c.tmp gitref.c || \ (echo "Updating gitref.c"; mv gitref.c.tmp gitref.c) @rm -f gitref.c.tmp
source share