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