Last active
January 24, 2021 11:04
-
-
Save DanielG/d12035ea90eefd87d6ba1aad2ed2477f to your computer and use it in GitHub Desktop.
Example of automatically embedding git commit info into source tarballs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/git.mk export-subst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SPDX-License-Identifier: MIT OR FSFAP OR CC0-1.0 | |
F:=$$F | |
dollar := $$ | |
# This stuff gets expanded at git-archive(1) time due to the export-subst | |
# setting for this file in .gitattributes. See gitattributes(5) | |
GIT_COMMIT := $Format:%H$ | |
GIT_DATE := $Format:%cD$ | |
GIT_TIMESTAMP := $Format:%ct$ | |
GIT_SUBJ := $Format:%s$ | |
GIT_DIRTY := | |
# If the above wasn't expanded get version info straight from git | |
ifeq ($(GIT_COMMIT),$(dollar)Format:%H$(dollar)) | |
GIT_COMMIT := $(shell git rev-parse HEAD) | |
GIT_DATE := $(shell git show -s --pretty=format:%cD) | |
GIT_TIMESTAMP := $(shell git show -s --pretty=format:%ct) | |
GIT_SUBJ := $(shell git show -s --pretty=format:%s) | |
GIT_DIRTY := -dirty | |
endif | |
.PHONY: FORCE | |
git.h: FORCE | |
@printf ' GIT\t$@\n' | |
@echo '#pragma once' > $@ | |
@echo '#define GIT_COMMIT "commit $(GIT_COMMIT)$(GIT_DIRTY)"' >> $@ | |
@echo '#define GIT_SUBJ "$(GIT_SUBJ)"' >> $@ | |
@echo '#define GIT_DATE "$(GIT_DATE)"' >> $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment