I’m currently in a process of creating a new C project and I have encountered a need to stamp each compilation with some data (including time & date).
The standard and trivial way to do it is to either:
-
Generate a .c file through a simple script, adding the needed information. With this solution the project will always generate a new artifact (.o for example), even when no changes occurred in the project itself (none of the files were changed).
-
Have a .c file ready already, with time , date and other stuff if needed, compiling it only after cleaning the project. Changes to source or header files in the project will not cause the stamp to be changed (unless we clean the project first).
What I am looking for is something in between:
When the project files change, and only then, make sure to add the compilation stamp.
I am not sure about eclipse, but if you use
makeand makefiles, you can use the idea in the following example (works in the cygwin environment).When
makeexecutes the command to link (the final one), it also compiles the file with the time embedded in it. When the executable is up to date, link is not invoked, so timestamp is not changed. In order for this to work, you should not informmakethat the file with the timestamp is a prerequisite for anything.