blob: 72bd3498facb249eaa9b1fc27f91a073d11133d3 [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.
11
Simon Kelley98d76a02012-02-10 22:16:45 +000012# we're called with pwd == TLD
Simon Kelleya4f04ed2012-01-06 11:47:02 +000013cd ..
14
Simon Kelley98d76a02012-02-10 22:16:45 +000015if which git >/dev/null 2>&1 && [ -d .git ]; then
Simon Kelleya4f04ed2012-01-06 11:47:02 +000016 git describe
Simon Kelley98d76a02012-02-10 22:16:45 +000017elif grep '\$Format:%d\$' VERSION >/dev/null 2>&1; then
18# unsubstituted VERSION, but no git available.
19 echo UNKNOWN
Simon Kelleya4f04ed2012-01-06 11:47:02 +000020else
21 vers=`cat VERSION | sed 's/[(), ]/\n/ g' | grep -m 1 $v[0-9]`
22
23 if [ $? -eq 0 ]; then
24 echo ${vers#v}
25 else
26 cat VERSION
27 fi
28fi
29
30exit 0
31