Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Adding date/version information to project?? [RSS Feed]

#1 Nov. 29, 2005 04:21:36

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


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??

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:
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Nov. 29, 2005 04:35:35

Russell S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


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??In the makefile rule that calls the linker, a shell command could get
the current date and then edit the resulting binary to replace a special
marker string with the current date. There might be a way to edit the
linker script to edit a string before the linker is run too.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Nov. 29, 2005 04:39:06

John A.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


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.Check out this thread in the archives:http://lists.gnu.org/archive/html/avr-gcc-list/2005-09/msg00220.htmlEspecially the sub thread from me, Anton Erasmus, and Dave Hansen. Ishow a method to create a version string and Anton and Dave show how toproperly compile the version string instead of using the ugly make hackI came up with.John


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Nov. 29, 2005 05:01:17

David K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


On Nov 28, 2005, at 10:20 PM, <> wrote:Hi all:

I am looking for an automated way to update a static string in programspace when my project is built. Is there an easy way to do this,eitherby adding an extra target to the makefile, or some other way? I'dprefernot to manually have to change the information, and I'd also preferforit to NOT change when none of the other source files change. That is,
the requirement is as follows:Incomplete, but this could get you started:Research the ability to run a script or executable from withinWindows gmake. Copy stdout into a Make variable something like this:CFLAGS += -DThe_Date_Is=`date`Create a project file named something like makedate.c and tweak theMake rules so that makedate.c must be built for the situations youwish the date to be updated.makedate.c would look something like:

const char My_Build_Date = "The_Date_Is";gcc already has a bluzillion predefined environment variables. Iwouldn't be surprised that one contains date and time stamp, lets check:% touch foo.h ; avr-cpp -dM foo.h

Nope, didn't see a timestamp.

--
David Kelly N4HHE,
========================================================================
Whom computers would destroy, they must first drive mad.





_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#5 Nov. 29, 2005 05:15:54

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


Hi David/avr-gcc list:

The __DATE__ and __TIME__ macros as mentioned by others in this thread
are useful for timestamps.

However, I'm having a problem getting my head around the following:

Suppose I create a version.c file, that contains those macros as progmem
strings, like this:

const progmem char BUILDDATE = "__DATE__ __TIME__"; /* or similar,
forget exact syntax */

Then, as suggested, I delete the version.o file (or, equivalently, touch
version.c) as the last step in the build process.

Next I program my micro with the command "make program", and it has to
compile and link version.o; not just this time, but every time I program
the micro. Not necessarily a bad thing, except I now want another board
to have the same version of the software, so I "make program" that board
- same thing happens, and a different version.o file is created (with a
new date/time), which is NOT what I want, since I'd like to verify if
two different boards are running the same software.

There are a couple of possible solutions:

1. don't use "make program" to program the micro. I'd rather not have to
memorise the procedure for programming the micro, though.
2. Maybe there's something in the linker script that I can use. I'll
have to research linker scripts anyway (see "use specifin RAM location"
thread), so I think this is where I'll try to find a solution.

I'll let the list know of any results I come up 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:
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb

> -----Original Message-----
> From: David Kelly
> Sent: Tuesday, 29 November 2005 3:01 PM
> To: Van De Werken, Matt (E&M, QCAT)
> Cc: avr-gcc-l***@*ongnu.org
> Subject: Re: Adding date/version information
> to project??
>
>
>
> On Nov 28, 2005, at 10:20 PM, <> 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:
>
> Incomplete, but this could get you started:
>
> Research the ability to run a script or executable from within
> Windows gmake. Copy stdout into a Make variable something like this:
>
> CFLAGS += -DThe_Date_Is=`date`
>
> Create a project file named something like makedate.c and tweak the
> Make rules so that makedate.c must be built for the situations you
> wish the date to be updated.
>
> makedate.c would look something like:
>
> const char My_Build_Date = "The_Date_Is";
>
> gcc already has a bluzillion predefined environment variables. I
> wouldn't be surprised that one contains date and time stamp,
> lets check:
>
> % touch foo.h ; avr-cpp -dM foo.h
>
> Nope, didn't see a timestamp.
>
> --
> David Kelly N4HHE,
> ==============================================================
> ==========
> Whom computers would destroy, they must first drive mad.
>
>
>


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#6 Nov. 29, 2005 05:24:54

Galen S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


Here's a snippet from my Makefile. I think this is probably close to
meeting your needs. I probably lifted this from somewhere off the net
but I don't recall where. For all I know, it came from this mailing
list.

galen


OBJS= ${ASRCS:$(S)=$(O)} ${SRCS:.c=$(O)}
EXTRA_OBJS = date.o

.PHONY: all clean distclean
all: $(PROG)$(HEX)

clean:
rm -f $(OBJS) $(EXTRA_OBJS) *.lst *.map *.elf *.hex

distclean: clean
rm -f .*.d

date.c: $(OBJS)
echo const char build_date = \"`date +'%F %R'`\"\; > date.c



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#7 Nov. 29, 2005 05:26:33

Erik C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


On Tue, Nov 29, 2005 at 03:35:19PM +1100, Russell Shaw wrote:
> In the makefile rule that calls the linker, a shell command could get
> the current date and then edit the resulting binary to replace a special
> marker string with the current date. There might be a way to edit the
> linker script to edit a string before the linker is run too.

The linker command language supports insertion of byte|short|long|quad
values, defined by a linker expression. AFAIK, section data expressions
don't support strings.

Your makefile rule alternative seems to provide the greatest scope. A
few lines of awk could maybe spit out a source file with a literal
string that is explicitly compiled in the same rule. This would then
pop up in .rodata. (Once the .o file is in the link list in the
makefile. ;-)

Erik


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#8 Nov. 29, 2005 15:49:42

Anton E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


On 29 Nov 2005 at 14:20, 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...
>

One can check the arguments to make within make. You can have version.c
be a phony target only when the argument to make was not "program"

(warning: untested)
i.e. try something like

ifneq ($(MAKECMDGOALS),program)
.PHONY version.c
endif

This should cause version.c to be compiled every time except when
you do a make program. version.c will be recompiled even if no other
file needed to be recompiled.

Regards
Anton Erasmus--
A J Erasmus



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#9 Nov. 29, 2005 22:23:33

Bruce D.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[avr-gcc-list] Adding date/version information to project??


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:
URL:http://www.lightner.net/lightner/bruce/_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#10 Nov. 29, 2005 23:13:44

M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[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: *** 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:
"We do not inherit the earth from our ancestors, we borrow it from our
children."
-- Native American Proverb

> -----Original Message-----
> From:
>
>
> org] On Behalf Of Bruce D. Lightner
> Sent: Wednesday, 30 November 2005 8:23 AM
> To: avr-gcc-l***@*ongnu.org
> Subject: Re: Adding date/version information
> to project??
>
>
> 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:
> URL:http://www.lightner.net/lightner/bruce/>
>
>
> _______________________________________________
> AVR-GCC-list mailing list
> AVR-GCC-l***@*ongnu.org
>http://lists.nongnu.org/mailman/listinfo/avr-gcc-list>


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] Adding date/version information to project?? [RSS Feed]

Board footer

Moderator control

Enjoy the 27th of April
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support