Imported Debian version 2.4.3~trusty1
[deb_ffmpeg.git] / ffmpeg / version.sh
1 #!/bin/sh
2
3 # Usage: version.sh <ffmpeg-root-dir> <output-version.h> <extra-version>
4
5 # check for git short hash
6 if ! test "$revision"; then
7 if (cd "$1" && grep git RELEASE 2> /dev/null >/dev/null) ; then
8 revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
9 else
10 revision=$(cd "$1" && git describe --tags --always 2> /dev/null)
11 fi
12 fi
13
14 # Shallow Git clones (--depth) do not have the N tag:
15 # use 'git-YYYY-MM-DD-hhhhhhh'.
16 test "$revision" || revision=$(cd "$1" &&
17 git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
18
19 # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
20 # ffmpeg-HEAD-hhhhhhh.
21 if [ -z "$revision" ]; then
22 srcdir=$(cd "$1" && pwd)
23 case "$srcdir" in
24 */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
25 git_hash="${srcdir##*-}";;
26 */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
27 git_hash="${srcdir##*-}";;
28 esac
29 fi
30
31 # no revision number found
32 test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
33
34 # Append the Git hash if we have one
35 test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
36
37 # releases extract the version number from the VERSION file
38 version=$(cd "$1" && cat VERSION 2> /dev/null)
39 test "$version" || version=$revision
40
41 test -n "$3" && version=$version-$3
42
43 if [ -z "$2" ]; then
44 echo "$version"
45 exit
46 fi
47
48 NEW_REVISION="#define FFMPEG_VERSION \"$version\""
49 OLD_REVISION=$(cat "$2" 2> /dev/null | head -3 | tail -1)
50
51 # String used for preprocessor guard
52 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 cat << EOF > "$2"
57 #ifndef $GUARD
58 #define $GUARD
59 $NEW_REVISION
60 #endif /* $GUARD */
61 EOF
62 fi