Merge pull request #11071 from hhromic/reimpl-git-version

(Makefiles) Re-implement Git version handling
This commit is contained in:
Autechre 2020-07-24 00:21:52 +02:00 committed by GitHub
commit 75a764c668
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

1
.gitignore vendored
View File

@ -8,6 +8,7 @@
*.dol *.dol
*.map *.map
*.swp *.swp
*.cache
.tmp .tmp
.tmp.c .tmp.c
.tmp.cxx .tmp.cxx

View File

@ -158,15 +158,28 @@ ifeq ($(TARGET), retroarch_3ds)
endif endif
# Git Version # Git Version
GIT_VERSION_CACHEDIR = $(if $(OBJDIR),$(OBJDIR),$(CURDIR))
GIT_VERSION_CACHEFILE = $(GIT_VERSION_CACHEDIR)/git-version.cache
GIT_VERSION := $(shell git rev-parse --short HEAD 2>/dev/null) ifneq (,$(wildcard .git/index)) # Building inside a Git repository?
ifneq ($(GIT_VERSION),) GIT_VERSION := $(shell git rev-parse --short HEAD 2>/dev/null)
_CACHEDIR = $(if $(OBJDIR),$(OBJDIR),$(CURDIR)) endif
_LAST_GIT_VERSION := $(shell cat "$(_CACHEDIR)"/last-git-version 2>/dev/null)
ifneq ($(GIT_VERSION),$(_LAST_GIT_VERSION)) ifneq (,$(wildcard $(GIT_VERSION_CACHEFILE))) # Cached Git version?
GIT_VERSION_CACHE = $(shell cat "$(GIT_VERSION_CACHEFILE)" 2>/dev/null)
endif
ifeq ($(GIT_VERSION),)
ifneq ($(GIT_VERSION_CACHE),) # If no Git version, use cached if found
GIT_VERSION = $(GIT_VERSION_CACHE)
endif
endif
ifneq ($(GIT_VERSION),) # Enable version_git.o?
ifneq ($(GIT_VERSION),$(GIT_VERSION_CACHE)) # Update version_git.o?
$(shell \ $(shell \
mkdir -p "$(_CACHEDIR)"; \ mkdir -p "$(GIT_VERSION_CACHEDIR)" && \
echo "$(GIT_VERSION)" > "$(_CACHEDIR)"/last-git-version; \ echo "$(GIT_VERSION)" > "$(GIT_VERSION_CACHEFILE)" && \
touch version_git.c) touch version_git.c)
endif endif
DEFINES += -DHAVE_GIT_VERSION -DGIT_VERSION=$(GIT_VERSION) DEFINES += -DHAVE_GIT_VERSION -DGIT_VERSION=$(GIT_VERSION)