![]() ![]() I have a static version.h file that looks like this: /*version.h*/ $(GIT) rev-parse HEAD | awk ' BEGIN ' > $(MyLibs)/version.cĮverytime I compile my code, the awk command generates a version.c file that looks like this: /* version.c */Ĭonst char * build_git_sha = "ac5bffc90f0034df9e091a7b3aa12d150df26a0e" Ĭonst char * build_git_time = "Thu Dec 3 18:03:" My makefile has a line in it that invokes git, date, and awk to create a c file: $(MyLibs)/version.c: FORCE This is useful if your stuck on windows machines which have awk installed by nature of mingw, but not perl. I ended up using something very similar to answer, but I used awk instead of perl. I'm not that knowledgeable about git, so I'd welcome comments if there is a better way to do this. Static void _program_id_stamp (FILE * output) In the main program, I have a routine #include "version.h"Ĭonst char * program_name = "magikruiser" Here hash_to_c_file does all the work of creating version.c and version.h and make_date_time makes a string as shown. ![]() Hash_to_c_file ("version.c", \%build, "build_") There is also a header file, which looks like this: #ifndef VERSION_HĮxtern const char * build_date /* 11:09 */Įxtern const char * build_git_sha /* 6b54ea36e92d4907aba8b3fade7f2d58a921b6cd */īoth the header file and the C file are generated by a Perl script which looks like this: my $git_sha = `git rev-parse HEAD` In my program, I hold the git version number and the date of the build in a separate file, called version.c, which looks like this: #include "version.h"Ĭonst char * build_git_sha = "6b54ea36e92d4907aba8b3fade7f2d58a921b6cd" I have used this approach with GNU automake and with Android NDK builds. The advantages are that it is simple and doesn't require any extra build dependencies like perl or awk. There is no dependency scanning so you have to do an explicit make clean to force the version to be updated. If there are uncommitted changes in your tree, it will append "-dirty". Which means, 2 commits past v1.1, with a git commit id beginning with "766d". Then it will print out: Version: v1.1-2-g766d Then you can just reference the version directly in the program as though it was a #define: printf("Version: %s\n", VERSION) īy default this just prints an abbreviated git commit id, but optionally you can tag particular releases with something like: git tag -a v1.1 -m "Release v1.1" Then add this to your CFLAGS: -DVERSION=\"$(GIT_VERSION)\" ![]() (See man git describe for what the switches do) If you are using a make-based build, you can put this in the Makefile: GIT_VERSION := "$(shell git describe -abbrev=4 -dirty -always -tags)" ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |