version.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/bin/sh
  2. # check for git short hash
  3. if ! test "$revision"; then
  4. revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
  5. fi
  6. # Shallow Git clones (--depth) do not have the N tag:
  7. # use 'git-YYYY-MM-DD-hhhhhhh'.
  8. test "$revision" || revision=$(cd "$1" &&
  9. git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
  10. # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
  11. # ffmpeg-HEAD-hhhhhhh.
  12. if [ -z "$revision" ]; then
  13. srcdir=$(cd "$1" && pwd)
  14. case "$srcdir" in
  15. */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  16. git_hash="${srcdir##*-}";;
  17. */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  18. git_hash="${srcdir##*-}";;
  19. esac
  20. fi
  21. # no revision number found
  22. test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
  23. # Append the Git hash if we have one
  24. test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
  25. # releases extract the version number from the VERSION file
  26. version=$(cd "$1" && cat VERSION 2> /dev/null)
  27. test "$version" || version=$revision
  28. test -n "$3" && version=$version-$3
  29. if [ -z "$2" ]; then
  30. echo "$version"
  31. exit
  32. fi
  33. NEW_REVISION="#define FFMPEG_VERSION \"$version\""
  34. OLD_REVISION=$(cat version.h 2> /dev/null)
  35. # Update version.h only on revision changes to avoid spurious rebuilds
  36. if test "$NEW_REVISION" != "$OLD_REVISION"; then
  37. echo "$NEW_REVISION" > "$2"
  38. fi