Generic way to do version number or build dates 
Author Message
 Generic way to do version number or build dates

Hello,

I am looking for a "generic" and automatic way of doing version number
or build date of an executable.

Under Windows, I have a function that I found that lets you retrieve the
build date of an executable.  This this function is specific to Windows,
there is no way I could get this function to work under let's say...
Linux.

Does anyone have a great function or idea of how to implement this?
Ideas.... anyone?

Thanks.

--
Jeff Lanzarotta
Software Engineer
QC Software
http://www.*-*-*.com/
--



Sun, 09 Feb 2003 08:41:24 GMT  
 Generic way to do version number or build dates

Quote:

> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.

Embed __DATE__ as a string into the executable, then cause a
particular command line argument to print that to the console.
--
"This is a wonderful answer.
 It's off-topic, it's incorrect, and it doesn't answer the question."
--Richard Heathfield
--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates

Quote:
> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.

What are your requirements with regard to build tools.  Using any capable
scripting language, you can add a pre-build step that substitutes the
current date and increments the build number in a header file with #define
statements.  I do this in all large projects I work with, Windows or UNIX.
I also do other stuff, like have the script log the build number and date
into a build history file so it's easier to track down a bug later by asking
for the build number and looking it up in a table.

Does that solve your problem?

Chris Smith
--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates

Quote:
> Hello,

> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.
[snip

> Does anyone have a great function or idea of how to implement this?
> Ideas.... anyone?

Here are prototypes of what I use:

float ver_version(int first_year,const char *date);
float ver_major(int first_year,const char *date);
float ver_minor(const char *date);

You supply the first year of compilation for the first_year argument.  For
the date argument, you simply supply __DATE__.  One drawback is that you
need to make sure the module containing the caller is touched every time you
recompile the program.  Also, this won't work if you distribute your code as
source, because when the program is built it gets a different version
number.

This works great for me because I "rebuild all" frequently and don't usually
distribute source.

A better way would be to write a small program X that used the runtime date
to generate the version number, and spit it out into a header file.  As part
of your build process, execute program X before building anything else.  You
need to make sure that the header is only re-written on your box.  You could
do this by having X check for a file with a wierd extension, say xxx.  When
you package your source code for distribution, make sure that any files with
the xxx extension are excluded from the tarball, or whatever packaging
system you use.  That way, end users can rebuild from source without
changing the version number.

--Steve
--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates

Quote:
> Hello,
> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.

Easy: use the predefined macros __DATE__ and/or __TIME__ I.e. to
output a message that says when the program was compiled:

        printf("Program compilation time: %s, %s\n", __DATE__, __TIME__);

--

Even if all the snow were burnt, ashes would remain.
--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates


Jeff> I am looking for a "generic" and automatic way of doing version
Jeff> number or build date of an executable.

I'm pretty sure there can't be such a thing, unless you embed the
information at build-time, eg by passing in a formatted date as a
preprocessor macro in your makefile (and of course, that's still not
very portable, unless you have compatible tools - make, cc, date,
etc. - everywhere).

Or, if the reason you're interested in build time is to determine
which sources were used to create it, get your revision control system
to update version strings in your source files.

Jeff> Under Windows, I have a function that I found that lets you
Jeff> retrieve the build date of an executable.  This this function is
Jeff> specific to Windows, there is no way I could get this function
Jeff> to work under let's say...  Linux.

For a Linux-specific half-solution, you could stat /proc/self/exe
to find when the program file was last modified.  Note that many
operations (touch, cp, etc.) will cause this to be different from the
build time.
--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates
C has macros __DATE__ and __TIME__, which are resolved at compile
time.  They get you close.

I create a source file which is very short, basically just a function
which puts these macros into a get'able variable.  Then I hack the
makefile so this source file depends on every other source file.

Thus, whenever any source file changes, this file gets compiled, and
the compiled-in date changes.

I don't know if it's a "great" idea, but it's portable.

Quote:

> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.

> Under Windows, I have a function that I found that lets you retrieve the
> build date of an executable.  This this function is specific to Windows,
> there is no way I could get this function to work under let's say...
> Linux.

> Does anyone have a great function or idea of how to implement this?
> Ideas.... anyone?

--

--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates
Yupe use
static const char rcscid[] = "$Id$" or "$Revision$"
in you source somewhere, then check it in

then just

ident ./executable

Later
FB

On 23 Aug 2000 00:41:24 GMT, Jeff Lanzarotta

Quote:

> Hello,

> I am looking for a "generic" and automatic way of doing version
number
> or build date of an executable.

> Under Windows, I have a function that I found that lets you
retrieve the
> build date of an executable.  This this function is specific to
Windows,
> there is no way I could get this function to work under let's
say...
> Linux.

> Does anyone have a great function or idea of how to implement
this?
> Ideas.... anyone?

> Thanks.

> --
> Jeff Lanzarotta
> Software Engineer
> QC Software
> http://www.qcsoftware.com
> --


--



Sun, 09 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates

Quote:

> C has macros __DATE__ and __TIME__, which are resolved at compile
> time.  They get you close.

> I create a source file which is very short, basically just a function
> which puts these macros into a get'able variable.  Then I hack the
> makefile so this source file depends on every other source file.

> Thus, whenever any source file changes, this file gets compiled, and
> the compiled-in date changes.


> > I am looking for a "generic" and automatic way of doing version number
> > or build date of an executable.

This is not a complete solution, as this file gets updated whenever
_anything_ changes, so the timestamp in it does not correspond to the
actual compilation of your sources, only of those that were copiled
last. __DATE__ and __TIME__ can get you closer than that.

One idea (UNTESTED) is adding to each file a function like

void filename_check_timestamp(void)
{
    printf(timestamp,"File %s was compiled on %s at %s",
                      __FILE__,__DATE__,__TIME__);

Quote:
}

and make a special driver that will call all these guys. Then
running a task with the driver and your library linked in, you'll
get all the info.

For me it is usually important to know which versions of my sources
were used in a particular build, rather than when exactly they were
compiled. If you use CVS or RCS for revision control, then putting

static const char rcsid[] = "$Id$";

is enough to be able to run ident or strings|grep to get all the
version numbers and last modification timestamps.

--

"... We work by wit, and not by witchcraft;
 And wit depends on dilatory time." [Shakespeare]
--



Mon, 10 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates

Quote:

> I am looking for a "generic" and automatic way of doing version number
> or build date of an executable.

Further to other answers...

If you have multiple source code files, controlled my make, the
idea of using __DATE__ etc will only work for that one file
that uses the macros.

Save this as a separate C code file with this one line only.

char built[] = __TIME__ " " __DATE__;

(Okay, you can add comments.)

Each time you run make, force this code to be compiled every
time, and link it in with the other object code files.

(Using GNU make, you can force an action to be taken everytime it's
invoked by giving it a .PHONY dependency, which has no attached
action itself.)

Elsewhere, access this data by declaring an extren for it, and
reading it in as a normal string. The reading in code will not
have to be compiled every time.

If you need help with the makefile, mail me. I don't know where it is
on topic, but it isn't here.

Bill, made for dancing.
--



Mon, 10 Feb 2003 03:00:00 GMT  
 Generic way to do version number or build dates
Yes, we had a similar scheme (using PVCS).  Every header file was of the
form:
    /* file.h */
    #ifndef FILE_H_INCLUDED
        #define FILE_H_INCLUDED
        static char FILE_H_VCSID[] = "$Header: $";
        /* rest of file */
    #endif

Every code file contained:
    static char VCSID[] = "$Header: $";

In every link that we did, we included a version.o which was compiled from:
    static char RELEASE[] = "4.27";

PVCS automagically expanded the $Header stanzas when checking files out so
we could always tell which version of each of our source files was in an
executable.  The inclusion of our version.o allowed us to track the overall
release number.  The reason we used such an anal-retentive scheme was due to
the huge troubles we had in the early stage of the programme
(proof-of-concept to pilot transition).

Regards,
AllanC.



Quote:
> Yupe use
> static const char rcscid[] = "$Id$" or "$Revision$"
> in you source somewhere, then check it in

> then just

> ident ./executable

> Later
> FB

> On 23 Aug 2000 00:41:24 GMT, Jeff Lanzarotta

>> Hello,

>> I am looking for a "generic" and automatic way of doing version
> number
>> or build date of an executable.

>> Under Windows, I have a function that I found that lets you
> retrieve the
>> build date of an executable.  This this function is specific to
> Windows,
>> there is no way I could get this function to work under let's
> say...
>> Linux.

>> Does anyone have a great function or idea of how to implement
> this?
>> Ideas.... anyone?

>> Thanks.

>> --
>> Jeff Lanzarotta
>> Software Engineer
>> QC Software
>> http://www.qcsoftware.com
>> --


--



Thu, 13 Feb 2003 03:00:00 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. Generic way to do version number or build dates

2. Build number, build date

3. Difference between two different ways of doing things

4. Automatically Updating Build Version Number

5. Build number (version control)

6. Auto-incrementing version numbers for build?

7. File Version (Build number) auto increment.

8. Project Version/Build numbers

9. Looking for fast ways to build binary tree

10. complex numbers - most common ways?

11. Unable to build ReleaseMinSize - Debug version builds fine.

12. Automatically Increment Build Number every time I build?

 

 
Powered by phpBB® Forum Software