help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: print project compile date


From: Mike Shal
Subject: Re: print project compile date
Date: Tue, 1 Sep 2009 00:29:27 -0400

On 9/1/09, John Calcote <address@hidden> wrote:
>  Basically, you're telling us that you want a.c to compile every time you
> build your project, so that you get the latest date/time stamp from the
> latest build. I guess the exception to this might be that you only want to
> "update" a.c if the program needs to be rebuilt for any other reason,
> otherwise, you want make to act as it always does if everything is already
> up to date - that is, do nothing.
>
>  Try adding this line to the *end* of your Makefile (untested):
>
>  a.c: $(APP)

Wouldn't that cause a circular dependency? After all, the file with
the date stamp must ultimately be linked into the application.

Another alternative is to just generate the a.c file and compile it as
part of the link step. Instead of:
$(APP): $(OBJS) ; $(CC) $^ -o $@
You would have something like:
$(APP): $(OBJS) ; echo 'const char *build_date(void) {return
__DATE__;}' > a.c; $(CC) $^ a.c -o $@

That way the timestamp file is only regenerated if you need to re-link
(ie: some other build file changed), and is always done right before
linking (so it's not stale). Note the a.c compilation is done in-line
with the linking (so there's no separate a.o file in my example, but
you could add that if you want). Then elsewhere in your source you
stick a prototype for build_date, and you can do 'printf("%s\n",
build_date())' or whatever.

I would also suggest that it might be more useful to use a revision
control version instead of the date (like something from 'svn info',
or 'git describe'). This way you can look at the version string in the
binary and easily go back and look at the corresponding source. It's
much harder to do that with just a date string, and you can't exactly
reproduce the build bit-for-bit. Unless, of course, you have a time
machine.

-Mike
PS. If you have time machine technology, I am interested.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]