Skip to content

Instantly share code, notes, and snippets.

@lindenb
Created July 29, 2014 17:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lindenb/3c7f0cc391749802a120 to your computer and use it in GitHub Desktop.
Save lindenb/3c7f0cc391749802a120 to your computer and use it in GitHub Desktop.
including git-hash in a C program.
#ifndef GIT_HASH
#define GIT_HASH "f2607d7e246549d9ea54922a87001459c0235486"
#endif
a.out: test.c githash.h
gcc $<
githash.h:
echo -n '#ifndef GIT_HASH\n#define GIT_HASH "' > $@ && \
git rev-parse HEAD | tr -d "\n" >> $@ && \
echo '"\n#endif' >> $@
#!/bin/sh
rm -f githash.h
#include <stdio.h>
#include "githash.h"
int main(int argc,char** argv)
{
return fputs("Git-Version:" GIT_HASH "\n",stdout)==0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment