#!/bin/sh

#
# $Id: svn-revision 12303 2006-11-11 08:11:46Z cbiere $
#
# Copyright (c) 2006, Raphael Manfredi
#
# Computes SVN current revision number, if possible, emitting it in
# the form of a #define for C perusal.
#
#----------------------------------------------------------------------
# This file is part of gtk-gnutella.
#
#  gtk-gnutella 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.
#
#  gtk-gnutella is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with gtk-gnutella; if not, write to the Free Software
#  Foundation, Inc.:
#      59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#----------------------------------------------------------------------
#

LC_ALL=C
export LC_ALL

TOP="$1"
FILE="$2"

if [ "x$FILE" = x ]; then
	FILE="&1"
	oldrev=''
else
	oldrev=`grep Revision "$FILE" 2>/dev/null | head -n1 | cut -d' ' -f4`
fi

if test -d "$TOP/.svn"; then
  revnum=`svn info "$TOP" 2>/dev/null | grep '^Revision' | head -n1 | cut -d' ' -f2`
else
  revnum="$oldrev" # keep as is
fi

if [ "x$revnum" = "x$oldrev" ]; then
	exit 0
fi

{
stamp=`date +"%Y-%m-%d %H:%M:%d %z"`
cat <<EOF
/*
 * THIS FILE IS AUTOMATICALLY GENERATED -- DO NOT EDIT
 *
 * Generated by $0.
 */

EOF

if [ "x$revnum" = x ]; then
	echo '/* Subversion information not available */'
else
	XRev='$Revision'
	cat <<EOF
#undef GTA_BUILD
#define GTA_BUILD "$XRev: $revnum \$"
EOF
fi

} > "$FILE"

