#!/bin/sh
# Update a source version file using arch version info if available
# Usage: update-version SRCDIR VERSION_FILE
#
#  Copyright (C) 2003, 2004  Miles Bader <miles@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Written by Miles Bader <miles@gnu.org>

srcdir="$1"
version_file="$2"

# Version used previously
if test -r "$version_file"; then
 old_version=`cat "$version_file"`
else
 old_version=NONE
fi

# Calculate current version
if test -d "$srcdir"/{arch}; then
  # Try to get arch version
  new_version=`$TLA logs -f --dir "$srcdir" 2>/dev/null | $SED -n '$p'`

  # If that failed, the tla program is probably missing
  if test x"$new_version" = x; then
    new_version=unknown-version
  fi
elif test -r "$srcdir/DIST-VERSION"; then
  # Use dist version
  new_version=`cat "$srcdir/DIST-VERSION"`
else
  new_version="unknown-version"
fi

# Update $version_file if they're different
if test x"$old_version" != x"$new_version"; then
  echo "$new_version" > "$version_file"
fi

# arch-tag: 35f533d5-3070-4bd0-9ff6-b95fea3c126a
