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