Thread (4 messages) flat view 4 messages, 4 authors, 2016-06-15

Re: ident hash usage question

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:35

Eugene Sajine [off-list ref] writes:
quoted
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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help