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

3 4
# Usage: version.sh <ffmpeg-root-dir> <output-version.h> <extra-version>

5
# check for git short hash
Mans Rullgard's avatar
Mans Rullgard committed
6
if ! test "$revision"; then
7 8 9 10 11
    if (cd "$1" && grep git RELEASE 2> /dev/null >/dev/null) ; then
        revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
    else
        revision=$(cd "$1" && git describe --tags --always 2> /dev/null)
    fi
12 13
fi

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 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

31
# no revision number found
32
test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
33

34 35 36
# Append the Git hash if we have one
test "$revision" && test "$git_hash" && revision="$revision-$git_hash"

37
# releases extract the version number from the VERSION file
38
version=$(cd "$1" && cat VERSION 2> /dev/null)
Mans Rullgard's avatar
Mans Rullgard committed
39
test "$version" || version=$revision
40

41 42
test -n "$3" && version=$version-$3

43 44 45 46 47
if [ -z "$2" ]; then
    echo "$version"
    exit
fi

48
NEW_REVISION="#define FFMPEG_VERSION \"$version\""
49 50 51 52
OLD_REVISION=$(cat "$2" 2> /dev/null | head -3 | tail -1)

# String used for preprocessor guard
GUARD=$(echo "$2" | sed 's/\//_/' | sed 's/\./_/' | tr '[:lower:]' '[:upper:]' | sed 's/LIB//')
53

54
# Update version header only on revision changes to avoid spurious rebuilds
55
if test "$NEW_REVISION" != "$OLD_REVISION"; then
56 57 58 59 60 61
    cat << EOF > "$2"
#ifndef $GUARD
#define $GUARD
$NEW_REVISION
#endif /* $GUARD */
EOF
62
fi