avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Code version timestamp


From: John Altstadt
Subject: Re: [avr-gcc-list] Code version timestamp
Date: Wed, 14 Sep 2005 06:21:52 -0700
User-agent: Mozilla Thunderbird 1.0.6 (X11/20050723)

address@hidden wrote:
Dear All,

I would like to display a "code version" (date/time or incremental number)
during init on an LCD display.
Does anybody know if there is any information in the executable (ROM file) that
I can use at runtime (updated by the linker for example) ?

If no, does anybody know how to implement this ?
I was thinking to generate an asm code using a script in the make, but seems to
be complicated.

Thanks for your suggestions.
Eric.

Look at the __DATE__ and __TIME__ predefined macros. Since they are already string constants, you can use the compiler to concatenate them with the string you want to display, such as:

char *version =
"Compiled on " __DATE__ " at " __TIME__;

Put this line by itself in a file called version.c, and then change the appropriate Makefile target to remove version.o as the last step, e.g.:

%.elf: $(OBJ)
        @echo
        @echo $(MSG_LINKING) $@
        $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
        rm version.o

This way, every time you build the target, version.c will be compiled, giving you a new version string corresponding to the time you built the project. Make sure that version.c is the last file compiled by putting it last in the source file list in the Makefile.

There are other predefined macros that may prove helpful for identification and debugging. I sometimes use __FILE__ and __LINE__ for debug and error messages. Check out section 3.7 Predefined Macros in the cpp docs.

To get a list of some of the predefined macros (not all of them, unlike what it says in the cpp man page), run the command:

touch foo.h; avr-cpp -dM foo.h

assuming that foo.h doesn't exist before you start.

John




reply via email to

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