-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathver.mk
executable file
·89 lines (76 loc) · 2.7 KB
/
ver.mk
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
###############################################################################
# Description: Linux Makefile Version Control extension for C-Compass Library
# Author: Hugo Saporetti Junior
# Create Date: Jan, 23 2012
# Version: 1.0
# -----------------------------------------------------------------------------
# Developed by Hugo Saporetti Junior
# Access: https://github.com/yorevs/ccompass
# Copyright (C) 2018 Hugo Saporetti Junior
# -----------------------------------------------------------------------------
# Targets:
#
# [version]
# Increment if any object file changes.
#
# [major]
# Increment the Major number.
#
# [minor]
# Increment the Minor number.
#
# [revision]
# Increment the Revision number.
#
# [buildnum]
# Increment the build number.
# Version control file.
VERSION_FILE := VERSION
# If the version file does not exist. Create it and assign version 0.0.1 .
ifneq "$(wildcard $(VERSION_FILE) )" ""
VERSION ?= $(MAJOR).$(MINOR).$(REVISION).$(BUILDNUM)
else
VERSION ?= 0.1.0.001
endif
# Version parts.
MAJOR ?= $(shell head -1 $(VERSION_FILE) | cut -d '.' -f 1)
MINOR ?= $(shell head -1 $(VERSION_FILE) | cut -d '.' -f 2)
REVISION ?= $(shell head -1 $(VERSION_FILE) | cut -d '.' -f 3)
BUILDNUM ?= $(shell head -1 $(VERSION_FILE) | cut -d '.' -f 4)
BUILD_DATE := $(shell date +'%d-%m-%Y')
# Create the initial VERSION_FILE.
$(VERSION_FILE): $(C_OBJS)
$(VERBOSE)if [ ! -f $(VERSION_FILE) ]; then \
echo "0.1.0.000" > $(VERSION_FILE); \
fi;
# Version. Increment if any object file changes.
version: $(VERSION_FILE)
@make buildnum
@echo "### Last modified: $(BUILD_DATE)" >> $(VERSION_FILE)
@echo "### Automatically generated. Do not edit !" >>$(VERSION_FILE)
# Increment the Major number.
major: $(VERSION_FILE)
@echo '[$@] Incrementing major number'
@echo "$$(($(MAJOR) + 1)).0.0.000" > $(VERSION_FILE)
@make ver
# Increment the Minor number.
minor: $(VERSION_FILE)
@echo '[$@] Incrementing minor number'
@echo "$(MAJOR).$$(($(MINOR) + 1)).0.000" > $(VERSION_FILE)
@make ver
# Increment the Revision number.
revision: $(VERSION_FILE)
@echo '[$@] Incrementing revision number'
@echo "$(MAJOR).$(MINOR).$$(($(REVISION) + 1)).000" > $(VERSION_FILE)
@make ver
# Increment the build number.
buildnum: $(VERSION_FILE)
@echo '[$@] Incrementing build number'
@echo "$(MAJOR).$(MINOR).$(REVISION).$(shell printf '%03d' $$(($(BUILDNUM) + 1)))" > $(VERSION_FILE)
@make ver
# Check the current version.
ver: $(VERSION_FILE)
@echo '[$@] Current version is: $(shell head -1 $(VERSION_FILE))'
# ----------------------------------------------------------------------------
### PHONY targets.
.PHONY: version major minor revision buildnum ver