1#!/bin/sh
2
3# check for git short hash
4revision=$(cd "$1" && git describe --always 2> /dev/null)
5
6# no revision number found
7test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
8
9# releases extract the version number from the VERSION file
10version=$(cd "$1" && cat VERSION 2> /dev/null)
11test "$version" || version=$revision
12
13test -n "$3" && version=$version-$3
14
15if [ -z "$2" ]; then
16    echo "$version"
17    exit
18fi
19
20NEW_REVISION="#define LIBAV_VERSION \"$version\""
21OLD_REVISION=$(cat version.h 2> /dev/null)
22
23# Update version.h only on revision changes to avoid spurious rebuilds
24if test "$NEW_REVISION" != "$OLD_REVISION"; then
25    echo "$NEW_REVISION" > "$2"
26fi
27