Unix Programming - Application version - how to store it in executable file?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2006 > Application version - how to store it in executable file?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Application version - how to store it in executable file?
eoo

2006-10-30, 1:19 pm

Hello,

MS Windows executable files can contain version information stored in
application's resources (version number, manufacturer etc.). There is
special API for reading it programmatically (for example
GetFileVersionInfo() function). I'm moving my console application to
FreeBSD and here is my question: is there something similar on Unix
platform?

I would like to set version number and optionally some other info on
compile time and be able to read all of them on runtime. Is it possible? If
not ¡V how can I store at least version number permanently in the executable
file? I think that storing it in file name is not the good choice, because
I'd like to be able to check the version even if the user changes the file
name.

Thanks in advance!
Best regards,
eoo
Lew Pitcher

2006-10-30, 1:19 pm


eoo wrote:
> Hello,
>
> MS Windows executable files can contain version information stored in
> application's resources (version number, manufacturer etc.). There is
> special API for reading it programmatically (for example
> GetFileVersionInfo() function). I'm moving my console application to
> FreeBSD and here is my question: is there something similar on Unix
> platform?


The accepted practice for reporting version information is to give your
application the code necessary to handle a special commandline argument
(typically the --version or -V argument). The code reports the program
version when it sees the -V argument, and the invoker (shell, program,
human) reads this version information.

Eg:
lpitcher@merlin:~$ grep --version
grep (GNU grep) 2.5
[snip]
lpitcher@merlin:~$ du --version
du (coreutils) 5.2.1
Written by Torbjorn Granlund, David MacKenzie, Paul Eggert, and Jim
Meyering.
[snip]

> I would like to set version number and optionally some other info on
> compile time and be able to read all of them on runtime. Is it possible?


Certainly. You can do anything that you wish, at compile time.

FWIW, many source management systems provide special macros that expand
into source code version numbers. The programmer has the option of
ignoring these macros, but /can/ imbed the macros into string constants
or even program logic.

When realized into the program executable or data code, these macros
carry forward into the compiled binary. This macro typically prefixes
the version string with the characters "@(#)"

For example:

lpitcher@merlin:/bin$ strings ed | grep '@(#)'
@(#)$Id: buf.c,v 1.11 1994/11/13 04:25:44 alm Exp $
@(#)$Id: glbl.c,v 1.7 1994/11/13 04:25:44 alm Exp $
@(#)$Id: io.c,v 1.11 1994/11/13 04:25:44 alm Exp $
@(#) Copyright (c) 1993, 1994 Andrew Moore, Talke Studio.
@(#)$Id: main.c,v 1.16 1994/11/13 04:25:44 alm Exp $
@(#)$Id: re.c,v 1.7 1994/11/13 04:25:44 alm Exp $
@(#)$Id: signal.c,v 1.9 1994/11/13 04:25:44 alm Exp $
@(#)$Id: sub.c,v 1.6 1994/11/13 04:25:44 alm Exp $
@(#)$Id: undo.c,v 1.7 1994/11/13 04:25:44 alm Exp $
@(#)$Id: version.c,v 1.6 1994/11/13 05:45:09 alm Exp alm $



> If
> not - how can I store at least version number permanently in the executable
> file? I think that storing it in file name is not the good choice, because
> I'd like to be able to check the version even if the user changes the file
> name.


HTH
--
Lew Pitcher

Torgny Lyon

2006-10-31, 7:26 pm

"Lew Pitcher" <lpitcher@sympatico.ca> wrote:
> lpitcher@merlin:/bin$ strings ed | grep '@(#)'


Or use the SCCS what utility which does exactly the same thing.

--
Torgny Lyon
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com