Skip to content

Commit c4f290d

Browse files
committed
install: call git cmds in Makefile only if needed
Update Makefile to call git command only if the version.inc file needs to get rebuilt (if it does not exist or if the git repository has been updated after version.inc built). Include version.inc file in main Makefile only if its variables have not been just generated within Makefile flow.
1 parent b921574 commit c4f290d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

Makefile

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,21 @@ endif
7878

7979
# define rule prereq when target need to be rebuilt when git repository change
8080
ifeq ($(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)
8389
else
84-
GIT_REFRESH_PREREQ :=
90+
REFRESH_VERSION_INC := y
91+
endif
92+
93+
else
94+
GIT_REFRESH_PREREQ :=
95+
REFRESH_VERSION_INC := n
8596
endif
8697

8798
# setup summary echo rules unless silent mode set
@@ -109,6 +120,11 @@ pkgdoc: version.inc
109120
doc: 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
113129
ifeq ($(wildcard .git) $(wildcard version.inc.in),.git version.inc.in)
114130
GIT_CURRENT_TAG := $(shell git describe --tags --abbrev=0)
@@ -155,6 +171,9 @@ MODULES_BUILD := +$(notdir $(lastword $(MODULES_BUILD_REFS)))-XX-g$(MODULES_BUIL
155171
endif
156172
endif
157173
endif
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: ;
349368
version.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-
357371
contrib/rpm/environment-modules.spec: contrib/rpm/environment-modules.spec.in $(GIT_REFRESH_PREREQ)
358372
$(translate-in-script)
359373

NEWS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Modules 5.1.1 (not yet released)
3030
(fix issue #460)
3131
* Install: include the ``lib/config.guess`` and ``lib/config.sub`` scripts in
3232
distribution tarball if generated by :command:`autoreconf`.
33+
* Install: call ``git`` command in ``Makefile`` only if the definitions of
34+
``version.inc`` need to get built or refreshed.
3335

3436

3537
Modules 5.1.0 (2022-04-30)

0 commit comments

Comments
 (0)