|
From: | Bruce D. Lightner |
Subject: | Re: [avr-gcc-list] Adding date/version information to project?? |
Date: | Tue, 29 Nov 2005 10:04:30 -0800 |
User-agent: | Mozilla Thunderbird 1.0.2 (Windows/20050317) |
address@hidden wrote:
Hi all: I am looking for an automated way to update a static string in program space when my project is built. Is there an easy way to do this, either by adding an extra target to the makefile, or some other way? I'd prefer not to manually have to change the information, and I'd also prefer for it to NOT change when none of the other source files change. That is, the requirement is as follows: 1. The date/other information is changed when a build occurs, ie "make" or "make all" or "make target" - basically anything which calls thelinker; maybe the clue is there. 2. The date/other info is NOT changed when a build does not occur. Eg,"make program" causes no change in the string if the linker is not called, nor does it change if the target is up to date already. 3. I know all this can be done using CVS/SVN $Id$ tags, but I don't have a cvs/svn server here at work, and I don't want to go through the hassle of setting one up in this windows-only shop. I also know that I should be using version control here... Any ideas??
I *too* like having a "build time" timestamp string somewhere in my executable programs. It seems to me that this is especially important for embedded firmware.
One way to do this is to add "Makefile" logic to force the update of a timestamp string in a separate source file whenever the project is re-linked. One can force this "update" by unconditionally re-compiling a source code module containing an automatically updating timestamp string just before the "link" step in the "Makefile". The built-in C macros __DATE__ and __TIME__ make this straightforward.
Here's what I usually do...(1) Create a separate compilation module with a date/time string (two files: "version.c" and "version.h")...
// version.h extern const char build_time[]; // version.c #include "version.h" const char build_time[] = __DATE__" "__TIME__;In the case of "avr-gcc", you'll probably want to add "PROGMEM" after "build_time[]" in both of the above source files to force the string into program memory instead of SRAM.
(2) Reference the "build_time" string as required in your other project source file(s) by using the include file "version.h". The string will end up containing something like this...
"Nov 29 2005 17:01:41"(3) Add logic to your "Makefile" just before the "link" command to unconditionally re-compile "version.c". Also, be sure to include "version.o" in the list of object files being linked.
For example: %.elf: $(OBJ) @echo $(MSG_LINKING) $@ $(CC) $(ALL_CFLAGS) version.c --output version.o $(CC) $(ALL_CFLAGS) $^ version.o --output $@ $(LDFLAGS)Note that you don't absolutely have to include "version.o" in the $(OBJ) list. If you do, then remove the reference to "version.o" from the above "link" $(CC) command.
Anyway, this "make" logic causes the "build_time" string to be updated *only* when the program is actually linked.
Best regards, Bruce -- Bruce D. Lightner Lightner Engineering La Jolla, California Voice: +1-858-551-4011 FAX: +1-858-551-0777 Email: address@hidden URL: http://www.lightner.net/lightner/bruce/
[Prev in Thread] | Current Thread | [Next in Thread] |