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

Re: ident hash usage question

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 20, 2009, 22:30 UTC
Message-ID
<7vbpk1lmvl.fsf@alter.siamese.dyndns.org>
In-Reply-To
<76c5b8580910201514sc44f1cag222cf8a3710c875@mail.gmail.com>
Eugene Sajine <euguess@gmail.com> writes:
Show 22 quoted lines
>> If the project is already arranged to be compiled with decent automation,
>> I do not think you need any change to the workflow.
>>
>> You would have a version.cc file with
>>
>>        static char program_version[] = "My Program " VERSION_STRING;
>>
>> in it, and teach the build procedure how to compile and link this file.
>> Something like:
>>
>>    version.o: version.cc
>>        $(CXX) -o $@ -DVERSION_STRING=\""$(git describe HEAD)"\" $?
>>
>
> Please, correct me if I'm mistaken and forgive me if I'm not correct
> in using C++ terms.
>
> Your solution proposes to have a version file which will carry the
> info about last state the program was built from.
> But as I understand in case of static linking the executable will get
> only obj files from a library, which are necessary and everything
> irrelevant will be thrown away by linker.

I am not sure what you mean by "static linking" anymore. Usually the word means that everything you tell the linker to link to the executable is linked, together with objects from libraries. The resulting executable is usable on its own and it does not change behaviour regardless of which version of dynamic libraries you depend on happen to be installed on the target system (because by definition a statically linked executable does not depend on dynamic libraries---that is the whole point of static linking).

So as long as you make sure version.o is linked to the final executable, you will be fine. One way to do so might be to have

	printf("Program version: %s", program_version);
at the beginning of main() ;-)

If your product ships as one main executable _dynamically_ linked with two dynamic libraries, and all three components are built from the source material under your source control, obviously you would need to make sure that the above version.o or some equivalent of what embeds output from "git describe HEAD" are linked to the main executable and to the two libraries, but the idea is the same.

Previous: Eugene SajineNext: Eugene Sajine
Message 11 of 18 in “ident hash usage question”
  1. Eugene SajineOct 20, 2009
  2. Alex RiesenOct 20, 2009
  3. Alex RiesenOct 20, 2009
  4. Eugene SajineOct 20, 2009
  5. Alex RiesenOct 20, 2009
  6. Johannes SixtOct 20, 2009
  7. Alex RiesenOct 20, 2009
  8. Eugene SajineOct 20, 2009
  9. Junio C HamanoOct 20, 2009
  10. Eugene SajineOct 20, 2009
  11. Junio C HamanoOct 20, 2009
  12. Eugene SajineOct 20, 2009
  13. Daniel BarkalowOct 21, 2009
  14. Nanako ShiraishiOct 21, 2009
  15. Alex RiesenOct 20, 2009
  16. Eugene SajineOct 20, 2009
  17. Alex RiesenOct 21, 2009
  18. Eugene SajineOct 21, 2009

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.