Skip to content

Instantly share code, notes, and snippets.

@emaxerrno
Forked from lindenb/Makefile
Last active August 29, 2015 14:13
Show Gist options
  • Save emaxerrno/fac1ecdd0fb2fea7d87e to your computer and use it in GitHub Desktop.
Save emaxerrno/fac1ecdd0fb2fea7d87e to your computer and use it in GitHub Desktop.
#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