git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Including git-describe info as version strings for generic "-v" output

From
DSDirk Süsserott <newsletter@dirk.my1.cc>
Date
Jan 22, 2012, 16:03 UTC
Message-ID
<4F1C335D.7020802@dirk.my1.cc>
In-Reply-To
<7vd3acbtn3.fsf@alter.siamese.dyndns.org>
Am 21.01.2012 23:03 schrieb Junio C Hamano:
Show 5 quoted lines
> Harry portobello <harryportobello@gmail.com> writes:
> 
>> I hope the subject makes sense -- I'll explain what I'm trying to do.
> 
> Perhaps take a look at GIT-VERSION-GEN that is part of the Git source?
At work, we have the same "problem". I solved it like so:

version.h: ---------------------------------------------- #ifndef __version_h__ #define __version_h__

#ifdef __cplusplus extern "C" { #endif

/*
 * Returns a version string as defined with the -D compiler switch.
 */
char const * software_version();

#ifdef __cplusplus } #endif

#endif ----------------------------------------------

version.c: ---------------------------------------------- #include "version.h"

char const * software_version()
{
    return SW_VERSION;
}
----------------------------------------------
And then make sure that ONLY version.c gets compiled like this:
gcc -DSW_VERSION=\"$(git describe --dirty)\" \
    [other options] \
    -c version.c -o version.o

Actually I use Scons to build my software (not Make). Scons automatically keeps track of dependencies and changed compiler switches between its runs. Thus it will re-compile version.c if the output of git-describe changes. That's why Scons users must make sure that the -D-switch is given only to version.c (else Scons would re-compile ALL files because of the different argument to -D).

If you are using Make then make sure that version.c gets compiled always. The drawback is that your app will be re-linked with every single Make run.

That's why I prefer Scons: it calculates the dependencies on a checksum basis. If the *contents* of version.c together with the compiler options didn't change, it won't re-compile it. Furtermore: if the *contents* of version.o didn't change, it won't re-link. Timestamps don't matter to Scons. But that's another topic :-)

HTH
    Dirk
Previous: Junio C HamanoNext: demerphq
Message 3 of 4 in “Including git-describe info as version strings for generic "-v" output”
  1. Harry portobelloJan 21, 2012
  2. Junio C HamanoJan 21, 2012
  3. Dirk SüsserottJan 22, 2012
  4. demerphqJan 23, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.