@@ -78,10 +78,21 @@ endif
7878
7979# define rule prereq when target need to be rebuilt when git repository change
8080ifeq ($(wildcard .git) ,.git)
81- GIT_DIR := $(shell git rev-parse --git-dir)
82- GIT_REFRESH_PREREQ := $(GIT_DIR ) /index
81+ GIT_REFRESH_PREREQ := .git/objects
82+
83+ # determine if version.inc needs to get updated as git repository has changed
84+ ifeq ($(wildcard version.inc) , version.inc)
85+ MTIME_VERSION := $(shell date +% s -r version.inc)
86+ MTIME_GIT_REPO := $(shell date +% s -r $(GIT_REFRESH_PREREQ ) )
87+ REFRESH_VERSION_INC := $(shell if [ $(MTIME_GIT_REPO ) -gt $(MTIME_VERSION ) ]; \
88+ then echo y; else echo n; fi)
8389else
84- GIT_REFRESH_PREREQ :=
90+ REFRESH_VERSION_INC := y
91+ endif
92+
93+ else
94+ GIT_REFRESH_PREREQ :=
95+ REFRESH_VERSION_INC := n
8596endif
8697
8798# setup summary echo rules unless silent mode set
@@ -109,6 +120,11 @@ pkgdoc: version.inc
109120doc : version.inc
110121 $(MAKE ) --no-print-directory -C doc all
111122
123+ # source version definitions if built and no need to get refreshed
124+ # skip calls to git command if this file is available
125+ ifeq ($(wildcard version.inc) $(REFRESH_VERSION_INC ) , version.inc n)
126+ -include version.inc
127+ else
112128# build version.inc shared definitions from git repository info
113129ifeq ($(wildcard .git) $(wildcard version.inc.in) ,.git version.inc.in)
114130GIT_CURRENT_TAG := $(shell git describe --tags --abbrev=0)
@@ -155,6 +171,9 @@ MODULES_BUILD := +$(notdir $(lastword $(MODULES_BUILD_REFS)))-XX-g$(MODULES_BUIL
155171endif
156172endif
157173endif
174+ # no need to include generated version.inc file as the MODULES_* variables
175+ # have just been computed
176+ endif
158177
159178# determine RPM release
160179# use last release if we currently sat on tag, append build number to it elsewhere
@@ -349,11 +368,6 @@ Makefile.inc: ;
349368version.inc : version.inc.in $(GIT_REFRESH_PREREQ )
350369 $(translate-in-script )
351370
352- # source version definitions shared across the Makefiles of this project
353- ifeq ($(findstring clean,$(MAKECMDGOALS ) ) ,)
354- -include version.inc
355- endif
356-
357371contrib/rpm/environment-modules.spec : contrib/rpm/environment-modules.spec.in $(GIT_REFRESH_PREREQ )
358372 $(translate-in-script )
359373
0 commit comments