version.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/sh
  2. # Usage: version.sh <ffmpeg-root-dir> <output-version.h> <extra-version>
  3. # check for git short hash
  4. if ! test "$revision"; then
  5. if (cd "$1" && grep git RELEASE 2> /dev/null >/dev/null) ; then
  6. revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
  7. else
  8. revision=$(cd "$1" && git describe --tags --always 2> /dev/null)
  9. fi
  10. fi
  11. # Shallow Git clones (--depth) do not have the N tag:
  12. # use 'git-YYYY-MM-DD-hhhhhhh'.
  13. test "$revision" || revision=$(cd "$1" &&
  14. git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
  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. # no revision number found
  27. test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
  28. # Append the Git hash if we have one
  29. test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
  30. # releases extract the version number from the VERSION file
  31. version=$(cd "$1" && cat VERSION 2> /dev/null)
  32. test "$version" || version=$revision
  33. test -n "$3" && version=$version-$3
  34. if [ -z "$2" ]; then
  35. echo "$version"
  36. exit
  37. fi
  38. NEW_REVISION="#define FFMPEG_VERSION \"$version\""
  39. OLD_REVISION=$(cat "$2" 2> /dev/null | head -4 | tail -1)
  40. # String used for preprocessor guard
  41. GUARD=$(echo "$2" | sed 's/\//_/' | sed 's/\./_/' | tr '[:lower:]' '[:upper:]' | sed 's/LIB//')
  42. # Update version header only on revision changes to avoid spurious rebuilds
  43. if test "$NEW_REVISION" != "$OLD_REVISION"; then
  44. cat << EOF > "$2"
  45. /* Automatically generated by version.sh, do not manually edit! */
  46. #ifndef $GUARD
  47. #define $GUARD
  48. $NEW_REVISION
  49. #endif /* $GUARD */
  50. EOF
  51. fi