[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [avr-gcc-list] Adding date/version information to project??
From: |
Matt.VanDeWerken |
Subject: |
RE: [avr-gcc-list] Adding date/version information to project?? |
Date: |
Wed, 30 Nov 2005 09:13:29 +1000 |
I tried exactly this, however I now get a linker error:
c:\apps\WinAVR\bin\..\lib\gcc\avr\3.4.3\..\..\..\..\avr\bin\ld.exe:main.
o: file format not recognized; treating as linker script
c:\apps\WinAVR\bin\..\lib\gcc\avr\3.4.3\..\..\..\..\avr\bin\ld.exe:main.
o:1: parse error
make: *** [main.elf] Error 1
I change the makefile back (ie, removing the reference to buildtime) and
it compiles again.
Any ideas on this one??
The relevent section in my makefile is:
=====8><----------------------------------------------------------------
-
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) -c $(ALL_CFLAGS) buildtime.c --output buildtime.o
$(CC) $(ALL_CFLAGS) $(OBJ) buildtime.o --output $@ $(LDFLAGS)
=====8><----------------------------------------------------------------
-
To make it work, I change the last two lines above back to this line:
$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
I have no idea why it doesn't work; the contents of buildtime.c is as
follows:
=====8><----------------------------------------------------------------
-
#include <avr/pgmspace.h>
#include "buildtime.h"
const char BUILDTIME[] PROGMEM = (__DATE__ " " __TIME__);
=====8><----------------------------------------------------------------
-
Buildtime.h is as follows:
=====8><----------------------------------------------------------------
-
#ifndef __BUILDTIME_H
#define __BUILDTIME_H
#include <avr/pgmspace.h>
extern const char BUILDTIME[] PROGMEM;
#endif
=====8><----------------------------------------------------------------
-
I'm at a total loss as to why it will work without the file being linked
but not with.
Cheers,
Matthew van de Werken - Electronics Engineer
CSIRO E&M - Rock Mass Characterisation - 1 Technology Court - Pullenvale
- 4069
p: (07) 3327 4142 * f: (07) 3327 4455 * e: address@hidden
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb
> -----Original Message-----
> From:
> address@hidden
> [mailto:address@hidden
> org] On Behalf Of Bruce D. Lightner
> Sent: Wednesday, 30 November 2005 8:23 AM
> To: address@hidden
> Subject: Re: [avr-gcc-list] Adding date/version information
> to project??
>
>
> 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
> > the linker; 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/
>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
- [avr-gcc-list] Adding date/version information to project??, Matt.VanDeWerken, 2005/11/28
- Re: [avr-gcc-list] Adding date/version information to project??, Russell Shaw, 2005/11/28
- Re: [avr-gcc-list] Adding date/version information to project??, John Altstadt, 2005/11/28
- Re: [avr-gcc-list] Adding date/version information to project??, David Kelly, 2005/11/29
- Re: [avr-gcc-list] Adding date/version information to project??, Anton Erasmus, 2005/11/29
- Re: [avr-gcc-list] Adding date/version information to project??, Bruce D. Lightner, 2005/11/29
- Re: [avr-gcc-list] Adding date/version information to project??, Bruce D. Lightner, 2005/11/29