Skip to content

Commit 9b88fce

Browse files
author
Junio C Hamano
committed
Makefile: use git-describe to mark the git version.
Note: with this commit, the GIT maintainer workflow must change. GIT-VERSION-GEN is now the file to munge when the default version needs to be changed, not Makefile. The tag needs to be pushed into the repository to build the official tarball and binary package beforehand. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent c06818e commit 9b88fce

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
GIT-VERSION-FILE
12
git
23
git-add
34
git-am

GIT-VERSION-GEN

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
GVF=GIT-VERSION-FILE
4+
5+
VN=$(git describe --abbrev=4 HEAD 2>/dev/null) || VN=v1.0.GIT
6+
VN=$(expr "$VN" : v'\(.*\)')
7+
if test -r $GVF
8+
then
9+
VC=$(sed -e 's/^GIT_VERSION = //' <$GVF)
10+
else
11+
VC=unset
12+
fi
13+
test "$VN" = "$VC" || {
14+
echo >&2 "GIT_VERSION = $VN"
15+
echo "GIT_VERSION = $VN" >$GVF
16+
}
17+
18+

Makefile

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ all:
5555
# Define USE_STDEV below if you want git to care about the underlying device
5656
# change being considered an inode change from the update-cache perspective.
5757

58-
GIT_VERSION = 1.0.GIT
58+
GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE
59+
@sh ./GIT-VERSION-GEN
60+
-include GIT-VERSION-FILE
5961

6062
# CFLAGS and LDFLAGS are for the users to override from the command line.
6163

@@ -369,7 +371,7 @@ all: $(ALL_PROGRAMS)
369371
all:
370372
$(MAKE) -C templates
371373

372-
git$X: git.c $(LIB_FILE) Makefile
374+
git$X: git.c $(LIB_FILE)
373375
$(CC) -DGIT_EXEC_PATH='"$(bindir)"' -DGIT_VERSION='"$(GIT_VERSION)"' \
374376
$(CFLAGS) $(COMPAT_CFLAGS) -o $@ $(filter %.c,$^) $(LIB_FILE)
375377

@@ -398,8 +400,12 @@ $(patsubst %.py,%,$(SCRIPT_PYTHON)) : % : %.py
398400
git-cherry-pick: git-revert
399401
cp $< $@
400402

401-
# format-patch records GIT_VERSION
402-
git-format-patch: Makefile
403+
# These can record GIT_VERSION
404+
git$X git.spec \
405+
$(patsubst %.sh,%,$(SCRIPT_SH)) \
406+
$(patsubst %.perl,%,$(SCRIPT_PERL)) \
407+
$(patsubst %.py,%,$(SCRIPT_PYTHON)) \
408+
: GIT-VERSION-FILE
403409

404410
%.o: %.c
405411
$(CC) -o $*.o -c $(ALL_CFLAGS) $<
@@ -475,7 +481,7 @@ install-doc:
475481

476482
### Maintainer's dist rules
477483

478-
git.spec: git.spec.in Makefile
484+
git.spec: git.spec.in
479485
sed -e 's/@@VERSION@@/$(GIT_VERSION)/g' < $< > $@
480486

481487
GIT_TARNAME=git-$(GIT_VERSION)
@@ -510,4 +516,8 @@ clean:
510516
$(MAKE) -C Documentation/ clean
511517
$(MAKE) -C templates clean
512518
$(MAKE) -C t/ clean
519+
rm -f GIT-VERSION-FILE
520+
521+
.PHONY: all install clean
522+
.PHONY: .FORCE-GIT-VERSION-FILE
513523

0 commit comments

Comments
 (0)