blob: e472aabc1398054df5e77968cfa99d16c0663545 [file] [log] [blame]
Simon Kelleya4f04ed2012-01-06 11:47:02 +00001#!/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 Kelley00acd062012-08-17 14:18:50 +010011# If there is more than one v[0-9].* tag, sort them and use the
12# first. This favours, eg v2.63 over 2.63rc6.
Simon Kelleya4f04ed2012-01-06 11:47:02 +000013
Bert Gijsbers16f03e72017-03-06 23:07:32 +000014# Change directory to the toplevel source directory.
15if test -z "$1" || ! test -d "$1" || ! cd "$1"; then
16 echo "$0: First argument $1 must be toplevel dir." >&2
17 exit 1
18fi
19
Johnny S. Lee8efd7312015-04-26 22:23:57 +010020if which git >/dev/null 2>&1 && \
Bert Gijsbers16f03e72017-03-06 23:07:32 +000021 ([ -d .git ] || grep '^gitdir:' .git >/dev/null 2>&1) && \
22 git describe >/dev/null 2>&1; then
23 git describe | sed 's/^v//'
Simon Kelleyfdacfb02012-02-28 15:20:25 +000024elif grep '\$Format:%d\$' $1/VERSION >/dev/null 2>&1; then
Bert Gijsbers16f03e72017-03-06 23:07:32 +000025 # unsubstituted VERSION, but no git available.
Simon Kelley98d76a02012-02-10 22:16:45 +000026 echo UNKNOWN
Simon Kelleya4f04ed2012-01-06 11:47:02 +000027else
Simon Kelley990123a2012-12-14 11:56:15 +000028 vers=`cat $1/VERSION | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep ^v[0-9]`
Simon Kelleya4f04ed2012-01-06 11:47:02 +000029
30 if [ $? -eq 0 ]; then
Shantanu Gadgilf4f40072015-02-11 20:16:59 +000031 echo "${vers}" | sort -r | head -n 1 | sed 's/^v//'
Simon Kelleya4f04ed2012-01-06 11:47:02 +000032 else
Simon Kelleyfdacfb02012-02-28 15:20:25 +000033 cat $1/VERSION
Simon Kelleya4f04ed2012-01-06 11:47:02 +000034 fi
35fi
36
37exit 0
38