Finding a way to store binary versions compiled from git repo

I am looking for some implementation tips binary --versionthat would provide good information about the version from which it was compiled.

The project uses the build system autotoolsand is stored in the git repository, which acts as the SVN interface.

What I would like to have inside the binary:

  • compilation time
  • SVN transmission that acts as a base
  • last git commit id and time
  • if possible, the last commit that affects this particular binary
+3
source share
2 answers

, , #defined constant version. -DMY_VERSION=.... , #ifndef, !

#ifndef MY_VERSION
#define MY_VERSION 0.0.1-alpha
#endif

print_version() {
    printf("my product: %s\n", MY_VERSION);
}

, , makefile, MY_VERSION = "...". , , SCM.

, , :

echo -n 'MY_VERSION = "' > VERSION_FILE
git describe >> VERSION_FILE
echo "Compiled on $(date)" >> VERSION_FILE
...
echo '"' >> VERSION_FILE

make -DMY_VERSION='"$(MY_VERSION)"' .

: , make .

git, , . git describe - , . , , , , commit.

+3

VERSION_FILE (. ) BUILT_SOURCES Makefile.am , myprog_SOURCES, automake.

0

Source: https://habr.com/ru/post/1775224/


All Articles