-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_version.sh
executable file
·86 lines (68 loc) · 2.45 KB
/
get_version.sh
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
#!/bin/sh
############################### VERSIONING DATA ################################
# The project itself is versioned according to semantic versioning scheme
# (please see https://semver.org/)
major=0
minor=1
patch=0
prerelease=''
build_metadata=''
# The shared library should be versioned independently of
# project in order to establish backward compatibility on both
# semantical and _binary_ levels.
# Libtool's versioning system is used for that (please see
# https://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning).
# The shared library version comprises three components separated by a colon
# as follows: `current:revision:age`.
# However, the library file gets suffix `(current - age).revision.age`
# (please see https://github.com/pvanhoof/dir-examples),
# where value `(curent - age)` is a shared object version (aka soversion).
current=0
revision=0
age=0
############################### VERSIONING LOGIC ###############################
project_version="$major.$minor.$patch"
if [ ! -z "$prerelease" ]; then
project_version="$project_version-$prerelease"
fi
if [ ! -z "$build_metadata" ]; then
project_version="$project_version+$build_metadata"
fi
library_version="$current:$revision:$age"
soversion=$((current-age))
library_suffix="$soversion.$revision.$age"
############################# SCRIPT INPUT HANDLING ############################
prog="get_version.sh"
help_msg="\
Description:
Print version of a specified entity.
Usage:
$prog (--project|--library|--shared_object|--library_suffix)
Options:
--project Print project version.
--library Print shared library version in Libtool's format.
--shared_object Print shared object version (aka soversion).
--library_suffix Print library file suffix.
-h, --help Print this help message.
See also:
Semantic Versioning:
https://semver.org
Libtool's versioning system:
https://www.gnu.org/software/libtool/manual/libtool.html#Libtool-versioning"
print_error() {
echo "Error: $1\n$help_msg" >&2
}
if [ "$#" -ne 1 ]; then
print_error "$prog must be provided with exactly one option."
exit 1
fi
case "$1" in
-h|--help) echo "$help_msg"; exit 0;;
--project) echo "$project_version"; exit 0;;
--library) echo "$library_version"; exit 0;;
--shared_object) echo "$soversion"; exit 0;;
--library_suffix) echo "$library_suffix"; exit 0;;
*) print_error "unrecongnized input."; exit 1;;
esac
print_error "no option is specified"
exit 1