update_version 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # Creates and updates the package_version information used by configure.ac
  3. # (or other makefiles). When run inside a git repository it will use the
  4. # version information that can be queried from it unless AUTO_UPDATE is set
  5. # to 'no'. If no version is currently known it will be set to 'unknown'.
  6. #
  7. # If called with the argument 'release', the PACKAGE_VERSION will be updated
  8. # even if AUTO_UPDATE=no, but the value of AUTO_UPDATE shall be preserved.
  9. # This is used to force a version update whenever `make dist` is run.
  10. #
  11. # The exit status is 1 if package_version is not modified, else 0 is returned.
  12. #
  13. # This script should NOT be included in distributed tarballs, because if a
  14. # parent directory contains a git repository we do not want to accidentally
  15. # retrieve the version information from it instead. Tarballs should ship
  16. # with only the package_version file.
  17. #
  18. # Ron <ron@debian.org>, 2012.
  19. SRCDIR=$(dirname $0)
  20. if [ -e "$SRCDIR/package_version" ]; then
  21. . "$SRCDIR/package_version"
  22. fi
  23. if [ "$AUTO_UPDATE" = no ]; then
  24. [ "$1" = release ] || exit 1
  25. else
  26. AUTO_UPDATE=yes
  27. fi
  28. # We run `git status` before describe here to ensure that we don't get a false
  29. # -dirty from files that have been touched but are not actually altered in the
  30. # working dir.
  31. GIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \
  32. && git describe --tags --match 'v*' --dirty 2> /dev/null)
  33. GIT_VERSION=${GIT_VERSION#v}
  34. if [ -n "$GIT_VERSION" ]; then
  35. [ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1
  36. PACKAGE_VERSION="$GIT_VERSION"
  37. elif [ -z "$PACKAGE_VERSION" ]; then
  38. # No current package_version and no git ...
  39. # We really shouldn't ever get here, because this script should only be
  40. # included in the git repository, and should usually be export-ignored.
  41. PACKAGE_VERSION="unknown"
  42. else
  43. exit 1
  44. fi
  45. cat > "$SRCDIR/package_version" <<-EOF
  46. # Automatically generated by update_version.
  47. # This file may be sourced into a shell script or makefile.
  48. # Set this to 'no' if you do not wish the version information
  49. # to be checked and updated for every build. Most people will
  50. # never want to change this, it is an option for developers
  51. # making frequent changes that they know will not be released.
  52. AUTO_UPDATE=$AUTO_UPDATE
  53. PACKAGE_VERSION="$PACKAGE_VERSION"
  54. EOF