Skip to content

Instantly share code, notes, and snippets.

@larytet
Last active June 5, 2018 08:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larytet/898ec8814dd6b3ceee65532a9916d406 to your computer and use it in GitHub Desktop.
Save larytet/898ec8814dd6b3ceee65532a9916d406 to your computer and use it in GitHub Desktop.
Makefile rule generating a C file with GIT commit
GIT_COMMIT_FILE=git_commit_filename.h
$(GIT_COMMIT_FILE): phony
$(eval GIT_COMMIT_SHA=$(shell git describe --abbrev=6 --always 2>/dev/null || echo 'Error'))
@echo SHA=$(GIT_COMMIT_SHA)
echo -n "static const char *GIT_COMMIT_SHA = \"$(GIT_COMMIT_SHA)\";" > $(GIT_COMMIT_FILE)
@larytet
Copy link
Author

larytet commented Jun 29, 2017

File git_commit_filename.h will end up with a single line
static const char *GIT_COMMIT_SHA="";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment