1#!/bin/sh 2 3# Usage: version.sh <ffmpeg-root-dir> <output-version.h> <extra-version> 4 5# check for git short hash 6if ! 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 12fi 13 14# Shallow Git clones (--depth) do not have the N tag: 15# use 'git-YYYY-MM-DD-hhhhhhh'. 16test "$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. 21if [ -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 29fi 30 31# no revision number found 32test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null) 33 34# Append the Git hash if we have one 35test "$revision" && test "$git_hash" && revision="$revision-$git_hash" 36 37# releases extract the version number from the VERSION file 38version=$(cd "$1" && cat VERSION 2> /dev/null) 39test "$version" || version=$revision 40 41test -n "$3" && version=$version-$3 42 43if [ -z "$2" ]; then 44 echo "$version" 45 exit 46fi 47 48NEW_REVISION="#define FFMPEG_VERSION \"$version\"" 49OLD_REVISION=$(cat "$2" 2> /dev/null | head -4 | tail -1) 50 51# String used for preprocessor guard 52GUARD=$(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 55if test "$NEW_REVISION" != "$OLD_REVISION"; then 56 cat << EOF > "$2" 57/* Automatically generated by version.sh, do not manually edit! */ 58#ifndef $GUARD 59#define $GUARD 60$NEW_REVISION 61#endif /* $GUARD */ 62EOF 63fi 64