version.sh 1.67 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
6
if ! test "$revision"; then
7
    revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
8 9
fi

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# 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

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

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

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

37 38
test -n "$3" && version=$version-$3

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

44
NEW_REVISION="#define FFMPEG_VERSION \"$version\""
45 46 47 48
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//')
49

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