version.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/bin/sh
  2. # check for git short hash
  3. if ! test "$revision"; then
  4. if (cd "$1" && grep git RELEASE 2> /dev/null >/dev/null) ; then
  5. revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
  6. else
  7. revision=$(cd "$1" && git describe --tags --always 2> /dev/null)
  8. fi
  9. fi
  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. # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
  15. # ffmpeg-HEAD-hhhhhhh.
  16. if [ -z "$revision" ]; then
  17. srcdir=$(cd "$1" && pwd)
  18. case "$srcdir" in
  19. */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  20. git_hash="${srcdir##*-}";;
  21. */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  22. git_hash="${srcdir##*-}";;
  23. esac
  24. fi
  25. # no revision number found
  26. test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
  27. # Append the Git hash if we have one
  28. test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
  29. # releases extract the version number from the VERSION file
  30. version=$(cd "$1" && cat VERSION 2> /dev/null)
  31. test "$version" || version=$revision
  32. test -n "$3" && version=$version-$3
  33. if [ -z "$2" ]; then
  34. echo "$version"
  35. exit
  36. fi
  37. NEW_REVISION="#define FFMPEG_VERSION \"$version\""
  38. OLD_REVISION=$(cat version.h 2> /dev/null)
  39. # Update version.h only on revision changes to avoid spurious rebuilds
  40. if test "$NEW_REVISION" != "$OLD_REVISION"; then
  41. echo "$NEW_REVISION" > "$2"
  42. fi