Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Determine the version string to build into a binary. |
| 4 | # When building in the git repository, we can use the output |
| 5 | # of "git describe" which gives an unequivocal answer. |
| 6 | # |
| 7 | # Failing that, we use the contents of the VERSION file |
| 8 | # which has a set of references substituted into it by git. |
| 9 | # If we can find one which matches $v[0-9].* then we assume it's |
| 10 | # a version-number tag, else we just use the whole string. |
Simon Kelley | 00acd06 | 2012-08-17 14:18:50 +0100 | [diff] [blame] | 11 | # If there is more than one v[0-9].* tag, sort them and use the |
Simon Kelley | f1204a8 | 2021-01-29 23:20:06 +0000 | [diff] [blame] | 12 | # first. The insane arguments to the sort command are to ensure |
| 13 | # that, eg v2.64 comes before v2.63, but v2.63 comes before v2.63rc1 |
| 14 | # and v2.63rc1 comes before v2.63test1 |
| 15 | |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 16 | |
Bert Gijsbers | 16f03e7 | 2017-03-06 23:07:32 +0000 | [diff] [blame] | 17 | # Change directory to the toplevel source directory. |
| 18 | if test -z "$1" || ! test -d "$1" || ! cd "$1"; then |
| 19 | echo "$0: First argument $1 must be toplevel dir." >&2 |
| 20 | exit 1 |
| 21 | fi |
| 22 | |
Johnny S. Lee | 8efd731 | 2015-04-26 22:23:57 +0100 | [diff] [blame] | 23 | if which git >/dev/null 2>&1 && \ |
Bert Gijsbers | 16f03e7 | 2017-03-06 23:07:32 +0000 | [diff] [blame] | 24 | ([ -d .git ] || grep '^gitdir:' .git >/dev/null 2>&1) && \ |
| 25 | git describe >/dev/null 2>&1; then |
| 26 | git describe | sed 's/^v//' |
Simon Kelley | fdacfb0 | 2012-02-28 15:20:25 +0000 | [diff] [blame] | 27 | elif grep '\$Format:%d\$' $1/VERSION >/dev/null 2>&1; then |
Bert Gijsbers | 16f03e7 | 2017-03-06 23:07:32 +0000 | [diff] [blame] | 28 | # unsubstituted VERSION, but no git available. |
Simon Kelley | 98d76a0 | 2012-02-10 22:16:45 +0000 | [diff] [blame] | 29 | echo UNKNOWN |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 30 | else |
Simon Kelley | 990123a | 2012-12-14 11:56:15 +0000 | [diff] [blame] | 31 | vers=`cat $1/VERSION | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep ^v[0-9]` |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 32 | |
| 33 | if [ $? -eq 0 ]; then |
Simon Kelley | cfcafdd | 2021-02-01 23:46:43 +0000 | [diff] [blame] | 34 | echo "${vers}" | sort -k1.2,1.5Vr -k1.6,1.6 -k1.8,1.9Vr -k1.10,1.11Vr | head -n 1 | sed 's/^v//' |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 35 | else |
Simon Kelley | fdacfb0 | 2012-02-28 15:20:25 +0000 | [diff] [blame] | 36 | cat $1/VERSION |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 37 | fi |
| 38 | fi |
| 39 | |
| 40 | exit 0 |
| 41 | |