version.sh 1.39 KB
Newer Older
1 2
#!/bin/sh

3
# check for git short hash
4
if ! test "$revision"; then
5
    revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
6 7
fi

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Shallow Git clones (--depth) do not have the N tag:
# use 'git-YYYY-MM-DD-hhhhhhh'.
test "$revision" || revision=$(cd "$1" &&
  git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)

# Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
# ffmpeg-HEAD-hhhhhhh.
if [ -z "$revision" ]; then
  srcdir=$(cd "$1" && pwd)
  case "$srcdir" in
    */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
      git_hash="${srcdir##*-}";;
    */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
      git_hash="${srcdir##*-}";;
  esac
fi

25
# no revision number found
26
test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
27

28 29 30
# Append the Git hash if we have one
test "$revision" && test "$git_hash" && revision="$revision-$git_hash"

31
# releases extract the version number from the VERSION file
32
version=$(cd "$1" && cat VERSION 2> /dev/null)
33
test "$version" || version=$revision
34

35 36
test -n "$3" && version=$version-$3

37 38 39 40 41
if [ -z "$2" ]; then
    echo "$version"
    exit
fi

42
NEW_REVISION="#define FFMPEG_VERSION \"$version\""
43
OLD_REVISION=$(cat version.h 2> /dev/null)
44 45 46

# Update version.h only on revision changes to avoid spurious rebuilds
if test "$NEW_REVISION" != "$OLD_REVISION"; then
47
    echo "$NEW_REVISION" > "$2"
48
fi