Debian Codegraph @

mklove/modules/configure.fileversion

raw
1 #!/bin/bash
2 #
3 # Reads version from file and sets variables accordingly
4 # The first non-commented line in the file is expected to be the version string.
5 # Arguments:
6 # filename
7 # STR_VERSION_VARIABLE_NAME
8 # [ HEX_VERSION_VARIABLE_NAME ]
9 #
10 # Example: Set string version in variable named "MYVERSION_STR" and
11 # the hex representation in "MYVERSION"
12 # mkl_require VERSION.txt MYVERSION_STR MYVERSION
13
14 if [[ -z "$2" ]]; then
15 mkl_fail "fileversion" "none" "fail" "Missing argument(s), expected: FILENAME STR_VER HEX_VER"
16 return 0
17 fi
18
19 fileversion_file="$1"
20 fileversion_strvar="$2"
21 fileversion_hexvar="$3"
22
23 function checks {
24 mkl_check_begin "fileversion" "" "no-cache" "version from file $fileversion_file"
25
26 if [[ ! -s $fileversion_file ]]; then
27 mkl_check_failed "fileversion" "" "fail" \
28 "Version file $fileversion_file is not readable"
29 return 1
30 fi
31
32 local orig=$(grep -v ^\# "$fileversion_file" | grep -v '^$' | head -1)
33 # Strip v prefix if any
34 orig=${orig#v}
35
36 # Try to decode version string into hex
37 # Supported format is "[v]NN.NN.NN[.NN]"
38 if [[ ! -z $fileversion_hexvar ]]; then
39 local hex=""
40 local s=${orig#v} # Strip v prefix, if any.
41 local ncnt=0
42 local n=
43 for n in ${s//./ } ; do
44 if [[ ! ( "$n" =~ ^[0-9][0-9]?$ ) ]]; then
45 mkl_check_failed "fileversion" "" "fail" \
46 "$fileversion_file: Could not decode '$orig' into hex version, expecting format 'NN.NN.NN[.NN]'"
47 return 1
48 fi
49 hex="$hex$(printf %02x $n)"
50 ncnt=$(expr $ncnt + 1)
51 done
52
53 if [[ ! -z $hex ]]; then
54 # Finish all four bytess
55 for n in {$ncnt..4} ; do
56 hex="$hex$(printf %02x 0)"
57 done
58 mkl_allvar_set "fileversion" "$fileversion_hexvar" "0x$hex"
59 fi
60 fi
61
62 mkl_allvar_set "fileversion" "$fileversion_strvar" "$orig"
63
64 mkl_check_done "fileversion" "" "cont" "ok" "${!fileversion_strvar}"
65 }