blob: a68b96ba5b37a09b40f48f78b0945db682fda74f [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
Simon Kelley96f69792012-02-25 11:31:15 +000021 vers=`cat VERSION | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep $v[0-9]`
Simon Kelleya4f04ed2012-01-06 11:47:02 +000022
23 if [ $? -eq 0 ]; then
Simon Kelley96f69792012-02-25 11:31:15 +000024 echo "${vers}" | head -n 1 | tail -c +2
Simon Kelleya4f04ed2012-01-06 11:47:02 +000025 else
26 cat VERSION
27 fi
28fi
29
30exit 0
31