To expand the JesperE solution a bit.
Let the object file depend on all the goals on which the executable depends (excluding itself).
So, if all executables are object dependent, then JesperE is completely correct.
Otherwise, you can restore the executable file without updating the timestamp if one of the other dependencies changes, but none of your object files do. So the two things mentioned in the question: “has the latest build time / date” and “rebuilt if any of the sources were compiled” are not really the same thing, so it depends on what you want .
Examples may include a library with which you are statically linking, or some script that is used to create links and that change a lot, so for the convenience of developers, a dependency was made.
It still won’t update the timestamp if you simply delete the executable and rebuild it (perhaps because something has changed, which matters but is not a dependency, for example, because you grabbed the latest version of the linker or you " something has changed in an environment that affects the linker and / or make file "). Therefore, it is best to compile the object as part of the rule to create the executable, for example:
blah.exe : whatever rm -f version.o $(CC) $(CFLAGS) -c version.c $(CC) $(CFLAGS) $(OBJFILES) version.o -o blah.exe
or something else (maybe not .exe if you use make, but you never know). In fact, error handling is a bit dodgy there, since version.o will not be deleted if the last line failed.
I will also add that if you are going to release something to users (by which I mean, basically, someone more than 10 feet from your table), you may have the idea to build from scratch anyway, and not just run make to update and submit. It’s quite easy, otherwise you’ll spoil the make file so that you skip the dependency, accidentally create a “mixed version” and fail to reproduce what you sent.
I had jiggered make files before the version number was intentionally sabotaged (set to "0.0 private build"), if it was created by the developer - only the build server installed the option used to enable the correct version number. For this project, it simply did not make sense to put a number on something that was not verified from the source control with tags and built from there.