You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7KB

  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. revision=$(cd "$1" && git describe --tags --match N 2> /dev/null)
  6. fi
  7. # Shallow Git clones (--depth) do not have the N tag:
  8. # use 'git-YYYY-MM-DD-hhhhhhh'.
  9. test "$revision" || revision=$(cd "$1" &&
  10. git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null)
  11. # Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or
  12. # ffmpeg-HEAD-hhhhhhh.
  13. if [ -z "$revision" ]; then
  14. srcdir=$(cd "$1" && pwd)
  15. case "$srcdir" in
  16. */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  17. git_hash="${srcdir##*-}";;
  18. */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])
  19. git_hash="${srcdir##*-}";;
  20. esac
  21. fi
  22. # no revision number found
  23. test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null)
  24. # Append the Git hash if we have one
  25. test "$revision" && test "$git_hash" && revision="$revision-$git_hash"
  26. # releases extract the version number from the VERSION file
  27. version=$(cd "$1" && cat VERSION 2> /dev/null)
  28. test "$version" || version=$revision
  29. test -n "$3" && version=$version-$3
  30. if [ -z "$2" ]; then
  31. echo "$version"
  32. exit
  33. fi
  34. NEW_REVISION="#define FFMPEG_VERSION \"$version\""
  35. OLD_REVISION=$(cat "$2" 2> /dev/null | head -3 | tail -1)
  36. # String used for preprocessor guard
  37. GUARD=$(echo "$2" | sed 's/\//_/' | sed 's/\./_/' | tr '[:lower:]' '[:upper:]' | sed 's/LIB//')
  38. # Update version header only on revision changes to avoid spurious rebuilds
  39. if test "$NEW_REVISION" != "$OLD_REVISION"; then
  40. cat << EOF > "$2"
  41. #ifndef $GUARD
  42. #define $GUARD
  43. $NEW_REVISION
  44. #endif /* $GUARD */
  45. EOF
  46. fi