From 4205e73c9aa6c74ebd793a2fe6ee45e8abdecd30 Mon Sep 17 00:00:00 2001 From: Hugo Hromic Date: Tue, 21 Jul 2020 23:08:43 +0100 Subject: [PATCH] (Makefiles) Re-implement Git version handling Better (more fine-grained) logic for version_git.o regeneration. --- .gitignore | 1 + Makefile.common | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ebb953d4a9..1751df64bf 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.dol *.map *.swp +*.cache .tmp .tmp.c .tmp.cxx diff --git a/Makefile.common b/Makefile.common index a3d8930e52..4262472e37 100644 --- a/Makefile.common +++ b/Makefile.common @@ -158,15 +158,28 @@ ifeq ($(TARGET), retroarch_3ds) endif # 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 ($(GIT_VERSION),) - _CACHEDIR = $(if $(OBJDIR),$(OBJDIR),$(CURDIR)) - _LAST_GIT_VERSION := $(shell cat "$(_CACHEDIR)"/last-git-version 2>/dev/null) - ifneq ($(GIT_VERSION),$(_LAST_GIT_VERSION)) +ifneq (,$(wildcard .git/index)) # Building inside a Git repository? + GIT_VERSION := $(shell git rev-parse --short HEAD 2>/dev/null) +endif + +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 \ - mkdir -p "$(_CACHEDIR)"; \ - echo "$(GIT_VERSION)" > "$(_CACHEDIR)"/last-git-version; \ + mkdir -p "$(GIT_VERSION_CACHEDIR)" && \ + echo "$(GIT_VERSION)" > "$(GIT_VERSION_CACHEFILE)" && \ touch version_git.c) endif DEFINES += -DHAVE_GIT_VERSION -DGIT_VERSION=$(GIT_VERSION)