#!/usr/bin/perl
# Script run to update version number in all relevant files
require "getopts.pl";
&Getopts('hv:');
sub get_current_version_number() 
{
    $version = `awk '(/VERSION =/) {print \$3}' Makefile.in`;
    chop($version);
}
sub usage ()
{
    get_current_version_number();
    print 
	"UpdateVersion:  Script run to update version number in all relevant files

USAGE: For example, to update all files to Version 2.6.0:

     ./UpdateVersion -v 2.6.0

 Then erase all .bak after looking at diffs.
 Eventually, I'll trust it and will remove the .bak file creation.

Options: 
      -v VERSION
      -h :  display this message.

ToDo: Handle release date in version.cc
      Put prior version in comments in version.cc.

NOTE: present version number is $version\n";
}

die "This script is disabled, pending updates.  (For example, some
files are moved, and others are not manually updated anymore.)";

exit usage() if ($opt_h || ! $opt_v || ($opt_v == ""));

die "CVSROOT not defined" if (! defined($ENV{'CVSROOT'}));
die "CVSROOT not pointing to cvs.gri.sourceforge.net" 
    if (! $ENV{'CVSROOT'} =~ /cvs.gri.sourceforge.net/);

$CVSmsg = " is read-only.
Are you sure the file is checked out for edit?  Do:
# cvs edit Makefile.in gri.spec gri.cmd version.cc doc/gri.texim
";

die "Makefile.in $CVSmsg" if (! -w "Makefile.in");
die "gri.cmd $CVSmsg" if (! -w "gri.cmd");
die "version.cc $CVSmsg" if (! -w "version.cc");
die "doc/gri.texim $CVSmsg" if (! -w "doc/gri.texim");

# Get current version number
get_current_version_number();

die "Version is up-to-date" if ($opt_v eq $version);

$regexp = $version;
$regexp =~ s/\./\\./g;

`perl -pi.bak -e 's/(version $regexp)$/(version $opt_v)/' gri.cmd`
`perl -pi.bak -e 's/VERSION = $regexp/VERSION = $opt_v/' Makefile.in`
`perl -pi.bak -e 's/%define griversion $regexp/%define griversion $opt_v/g' gri.spec`
`perl -pi.bak -e 's/\@set GRI-VERSION $regexp/\@set GRI-VERSION $opt_v/`;
`perl -pi.bak -e 's/_gri_number\\[\\] = "$regexp"/_gri_number[] = "$opt_v"/' version.cc`;
print "CAUTION: Dan modified this script 2002-nov-23 because it was
too aggressive (doing global changes in the files), but it has NOT
been tested yet !!\n";
