OSDN Git Service

doc: fix two spelling errors
[android-x86/external-ffmpeg.git] / 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     revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
8 fi
9
10 # Shallow Git clones (--depth) do not have the N tag:
11 # use 'git-YYYY-MM-DD-hhhhhhh'.
12 test "$revision" || revision=$(cd "$1" &&
13   git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
14
15 # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
16 # ffmpeg-HEAD-hhhhhhh.
17 if [ -z "$revision" ]; then
18   srcdir=$(cd "$1" && pwd)
19   case "$srcdir" in
20     */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
21       git_hash="${srcdir##*-}";;
22     */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
23       git_hash="${srcdir##*-}";;
24   esac
25 fi
26
27 # no revision number found
28 test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
29
30 # Append the Git hash if we have one
31 test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
32
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 test -n "$3" && version=$version-$3
38
39 if [ -z "$2" ]; then
40     echo "$version"
41     exit
42 fi
43
44 NEW_REVISION="#define FFMPEG_VERSION \"$version\""
45 OLD_REVISION=$(cat "$2" 2> /dev/null | head -3 | tail -1)
46
47 # String used for preprocessor guard
48 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     cat << EOF > "$2"
53 #ifndef $GUARD
54 #define $GUARD
55 $NEW_REVISION
56 #endif /* $GUARD */
57 EOF
58 fi