[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 10:25:38 +1000 |
Having solved all that, I wanted to add an auto-incrementing build
number to the build process, which lives in program memory. Here's how I
did it:
I made a buildnumber file, as follows:
buildnumber:
=====8><--------------------------------------------------------------
# This is the current build number of the latest build
# DO NOT EDIT THIS FILE - it is updated automagically
# by the build process.
6
=====8><--------------------------------------------------------------
Note the only important thing in that file is the last number that
contains the a digit as the first character is the build number.
Then, I created a shell script to increment the number, and add it to
the buildtime.c file:
=====8><--------------------------------------------------------------
#!/bin/sh
BUILDNUMFILE="buildnumber"
i=$(cat $BUILDNUMFILE | grep ^[0-9])
newi=$( expr $i + 1 )
sed -i -e s/$i/$newi/g $BUILDNUMFILE
sed -e s/BUILDNUMBER/$newi/g buildtime.c
=====8><--------------------------------------------------------------
Note that the string BUILDNUMBER is substituted for the current build
number in the source file buildtime.c, so put that string inside your
BUILDNUM string variable.
I couldn't make this file executable since it lives on a SMB network
share, so I have to call it using sh in make.
Here's the relevent bits of my makefile:
=====8><--------------------------------------------------------------
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
sh buildtime.sh > tmpbuildtime.c
$(CC) -c $(ALL_CFLAGS) --output buildtime.o tmpbuildtime.c
rm tmpbuildtime.c
$(CC) $(ALL_CFLAGS) $(OBJ) buildtime.o --output $@ $(LDFLAGS)
=====8><--------------------------------------------------------------
And it all works fine. It's an ugly hack to make the interim
tmpbuildtime.c file, but avr-gcc won't compile from stdin (at least as
far as I could determine).
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 Van De Werken, Matt (E&M, QCAT)
> Sent: Wednesday, 30 November 2005 9:40 AM
> To: address@hidden
> Subject: RE: [avr-gcc-list] Adding date/version information
> to project??
>
>
> Hi all:
>
> I found the error; it was a line in the CFLAGS as follows:
> -Wa,-adhlns=$(<:.c=.lst)
>
> So, it was substituting the main.o filename into the above,
> thus my linkage would fail (since main.o was now a list file).
>
> I just removed the reference the this from the buildtime.c
> compile, and all was well.
>
> 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 Van De Werken, Matt (E&M, QCAT)
> > Sent: Wednesday, 30 November 2005 9:13 AM
> > To: address@hidden
> > Subject: RE: [avr-gcc-list] Adding date/version information
> > to project??
> >
> >
> > 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 mailing list
> > address@hidden
> > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> >
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>
- Re: [avr-gcc-list] Adding date/version information to project??, (continued)
- 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
- RE: [avr-gcc-list] Adding date/version information to project??, Matt.VanDeWerken, 2005/11/29
- RE: [avr-gcc-list] Adding date/version information to project??, Matt.VanDeWerken, 2005/11/29
- RE: [avr-gcc-list] Adding date/version information to project??, Matt.VanDeWerken, 2005/11/29
- RE: [avr-gcc-list] Adding date/version information to project??,
Matt.VanDeWerken <=
- RE: [avr-gcc-list] Adding date/version information to project??, Matt.VanDeWerken, 2005/11/30