blob: 9bea11786d107ff5e2e4f1d8b02288e4656e22d5 (
plain)
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
|
#!/bin/bash
#
# Reads version from file and sets variables accordingly
# The first non-commented line in the file is expected to be the version string.
# Arguments:
# filename
# STR_VERSION_VARIABLE_NAME
# [ HEX_VERSION_VARIABLE_NAME ]
#
# Example: Set string version in variable named "MYVERSION_STR" and
# the hex representation in "MYVERSION"
# mkl_require VERSION.txt MYVERSION_STR MYVERSION
if [[ -z "$2" ]]; then
mkl_fail "fileversion" "none" "fail" "Missing argument(s), expected: FILENAME STR_VER HEX_VER"
return 0
fi
fileversion_file="$1"
fileversion_strvar="$2"
fileversion_hexvar="$3"
function checks {
mkl_check_begin "fileversion" "" "no-cache" "version from file $fileversion_file"
if [[ ! -s $fileversion_file ]]; then
mkl_check_failed "fileversion" "" "fail" \
"Version file $fileversion_file is not readable"
return 1
fi
local orig=$(grep -v ^\# "$fileversion_file" | grep -v '^$' | head -1)
# Strip v prefix if any
orig=${orig#v}
# Try to decode version string into hex
# Supported format is "[v]NN.NN.NN[.NN]"
if [[ ! -z $fileversion_hexvar ]]; then
local hex=""
local s=${orig#v} # Strip v prefix, if any.
local ncnt=0
local n=
for n in ${s//./ } ; do
if [[ ! ( "$n" =~ ^[0-9][0-9]?$ ) ]]; then
mkl_check_failed "fileversion" "" "fail" \
"$fileversion_file: Could not decode '$orig' into hex version, expecting format 'NN.NN.NN[.NN]'"
return 1
fi
hex="$hex$(printf %02x $n)"
ncnt=$(expr $ncnt + 1)
done
if [[ ! -z $hex ]]; then
# Finish all four bytess
for n in {$ncnt..4} ; do
hex="$hex$(printf %02x 0)"
done
mkl_allvar_set "fileversion" "$fileversion_hexvar" "0x$hex"
fi
fi
mkl_allvar_set "fileversion" "$fileversion_strvar" "$orig"
mkl_check_done "fileversion" "" "cont" "ok" "${!fileversion_strvar}"
}
|