I meant "a header or a Makefile", it was a typo.
Sorry I didn't explain clearly.
The solution I proposed was to create a template, so in your header file, you'd have:
Code:
#define VERSION "${VERSION}"
And in your Makefile, you'd have
Code:
VERSION = ${VERSION}
And that would be it in your source repository.
When it came time to compile, you'd have either a script, or another Makefile go through all your files, and convert any occurence of ${VERSION} (you can use another format to recognise it as a templated token if you want) to the actual version number that is stored in one place. This system can be expanded to things other than ${VERSION} should you want to perform other substitutions, such as build date and time. Once all the substitions have occured, you'd build from the resulting source+Makefile. When the build has finished, the source+Makefile is just temporary, and is deleted. The original source/Makefile is retained, with just the ${VERSION} token present.
This method has the advantage that if you use a source code repository, only code changes are committed between revision changes, you don't have a bunch of revisions to a header file that is just updating the version value. Metadata like version numbers can be maintained separately, or automatically incremented on demand.
If you really want to use your method of extracting the version number from a .h, you could do something like this. Assume myheader.h contains:
Code:
#define VERSION "1.2.3"
In the Makefile, you could have:
Code:
VERSION=`grep VERSION myversion.h | cut -d \" -f2`
This would find the string VERSION, and get the value between the quotation marks. This is quite a dirty and ugly thing to do, IMHO.