-
Notifications
You must be signed in to change notification settings - Fork 6
/
version.make
48 lines (39 loc) · 1.41 KB
/
version.make
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
########################################################################
# Create VERSION variable from git repository, unless already set #
########################################################################
# make sure there is a git repository
HAS_REPOSITORY = $(shell $(GIT) rev-parse --git-dir 2>/dev/null)
GIT_WITH_REPO = $(if $(HAS_REPOSITORY),$(GIT),$(error "Not a git repository - call 'git init'!"))
ifndef VERSION
# get latest version tag (possibly empty) or exit if no git repository
VERSION := $(shell $(GIT_WITH_REPO) describe --abbrev=0 --tags 2>/dev/null | sed '/^[^v][0-9]/d; s/^v//' | head -1)
ifneq ($(REVHASH),)
VERSION_HASH = $(if $(VERSION),$(shell $(GIT) rev-list v${VERSION} | head -1))
FILES_CHANGED = $(shell $(GIT) status --porcelain 2>/dev/null | sed '/^??/d' )
ifneq ($(VERSION_HASH),$(REVHASH))
ifeq ($(VERSION_HASH),)
COMMITS_SINCE_VERSION=$(shell $(GIT) rev-list --all | wc -l)
else
COMMITS_SINCE_VERSION=$(shell $(GIT) rev-list v$(VERSION).. | wc -l)
endif
ifneq ($(FILES_CHANGED),)
VERSION := $(VERSION)+$(COMMITS_SINCE_VERSION)-dirty
else
VERSION := $(VERSION)+$(COMMITS_SINCE_VERSION)
endif
else
ifneq ($(FILES_CHANGED),)
VERSION := $(VERSION)+dirty
endif
endif
else # not commited yet
VERSION := 0.0.0
endif
else
ifeq ($(VERSION),none)
VERSION :=
endif
endif
ifneq ($(VERSION),)
ABOUT_VERSION=" - version $(VERSION)"
endif