blob: 6086136d79b6fb6af140fa7159fd19eb01dd43c9 [file] [log] [blame]
Ron2f2f9d62013-05-11 02:05:24 +09301#!/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
21SRCDIR=$(dirname $0)
22
23if [ -e "$SRCDIR/package_version" ]; then
24 . "$SRCDIR/package_version"
25fi
26
27if [ "$AUTO_UPDATE" = no ]; then
28 [ "$1" = release ] || exit 1
29else
30 AUTO_UPDATE=yes
31fi
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.
36GIT_VERSION=$(cd "$SRCDIR" && git status > /dev/null 2>&1 \
Ralph Gilesc435f062013-10-01 13:05:33 -070037 && git describe --tags --match 'v*' \
38 --always --dirty 2> /dev/null)
Ron2f2f9d62013-05-11 02:05:24 +093039GIT_VERSION=${GIT_VERSION#v}
40
41if [ -n "$GIT_VERSION" ]; then
42
43 [ "$GIT_VERSION" != "$PACKAGE_VERSION" ] || exit 1
44 PACKAGE_VERSION="$GIT_VERSION"
45
46elif [ -z "$PACKAGE_VERSION" ]; then
47 # No current package_version and no git ...
48 # We really shouldn't ever get here, because this script should only be
49 # included in the git repository, and should usually be export-ignored.
50 PACKAGE_VERSION="unknown"
51else
52 exit 1
53fi
54
55cat > "$SRCDIR/package_version" <<-EOF
56 # Automatically generated by update_version.
57 # This file may be sourced into a shell script or makefile.
58
59 # Set this to 'no' if you do not wish the version information
60 # to be checked and updated for every build. Most people will
61 # never want to change this, it is an option for developers
62 # making frequent changes that they know will not be released.
63 AUTO_UPDATE=$AUTO_UPDATE
64
65 PACKAGE_VERSION="$PACKAGE_VERSION"
66EOF