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. |
| 11 | |
Simon Kelley | 98d76a0 | 2012-02-10 22:16:45 +0000 | [diff] [blame^] | 12 | # we're called with pwd == TLD |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 13 | cd .. |
| 14 | |
Simon Kelley | 98d76a0 | 2012-02-10 22:16:45 +0000 | [diff] [blame^] | 15 | if which git >/dev/null 2>&1 && [ -d .git ]; then |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 16 | git describe |
Simon Kelley | 98d76a0 | 2012-02-10 22:16:45 +0000 | [diff] [blame^] | 17 | elif grep '\$Format:%d\$' VERSION >/dev/null 2>&1; then |
| 18 | # unsubstituted VERSION, but no git available. |
| 19 | echo UNKNOWN |
Simon Kelley | a4f04ed | 2012-01-06 11:47:02 +0000 | [diff] [blame] | 20 | else |
| 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 |
| 28 | fi |
| 29 | |
| 30 | exit 0 |
| 31 | |