#!/usr/bin/perl
require "../miscperl.pl";

GetVersion('../');

$r=cat('../include/tv.h');
if ($r!~/$Version/)
  {
   die "Error! inconsistent version in tv.h\n";
  }

# Adjust Debian version
$r=cat('../debian/changelog');
if ($r!~/$Version/)
  {
   chdir('../../debian');
   system("dch -v$version"."-0.1 \"Personal use unofficial version\"");
   chdir('../makes/linux');
  }

$doBinary=0;
foreach $i (@ARGV)
  {
   if ($i eq '--binary')
     {
      $doBinary=1;
     }
   else
     {
      print "Unknown command line option: $i\n";
      print "Usage: compres.pl [--binary]\n\n";
     }
  }

#  Update the makefile if needed
print 'Makefile: ';
if (-M 'Makefile' > -M 'librhtv.gpr')
  {
   system('gpr2mak librhtv.gpr');
   system('mv librhtv.mak Makefile');
   print "updated\n";
  }
else
  {
   print "uptodate\n";
  }

# Patch the version number in the readme.txt
print "Processing readme file\n";
$r=cat('../readme.in');
$r=~s/\@version\@/$Version/g;
replace('../readme.txt',$r);

# Patch Debian control file
print "Processing debian/control file\n";
$r=cat('../debian/control.in');
$r=~s/\@version\@/$Version/g;
replace('../debian/control',$r);

# Generate the tar files
$bindist="rhtvision-$Version.bin.i386.elf.static.linux.tar.gz";
$binddist="rhtvision-$Version.bin.i386.elf.dynamic.linux.tar.gz";
$srcdist="rhtvision-$Version.src.tar.gz";
chdir('../..');
unlink($srcdist,$bindist,$binddist);
system("tar -X tvision/linux/exclude.txt -zcvf $srcdist tvision");
system("tar -zcvf $bindist --exclude=*CVS `cat tvision/linux/inclubin.txt`") if $doBinary;
system("tar -zcvf $binddist --exclude=*CVS `cat tvision/linux/includbi.txt`") if $doBinary;

# Generate the lsm distribution file (Linux Software Map entry).
$lsm=
"Begin3
Title:          Turbo Vision (Robert Hoehne port)
Version:        $Version
Entered-date:   !3
Description:    Turbo Vision port to Linux. C++ Text UI. Not 100% Borland compatible.
Keywords:       c++ cui tui framework interface tv tvision
Author:         robert.hoehne\@gmx.net.de (Robert Hoehne)
                salvador\@inti.gov.ar (Salvador E. Tropea)
Maintained-by:  salvador\@inti.gov.ar (Salvador E. Tropea)
Primary-site:   www.geocities.com /SiliconValley/Vista/6552/tvision.html
                !1
                !2
                !4
Original-site:  ftp.borland.com /pub/borlandcpp/devsupport/archive/turbovision
                232k tv.zip
Platforms:      Linux, GNU g++, gpm, ncurses
Copying-policy: GPL
End";

$r= int((-s $srcdist)/1024+0.5)."k $srcdist";
$lsm =~ s/\!1/$r/g;
$r='';
$r= int((-s $bindist)/1024+0.5)."k $bindist" if $doBinary;
$lsm =~ s/\!2/$r/g;
$r= int((-s $binddist)/1024+0.5)."k $binddist" if $doBinary;
$lsm =~ s/\!4/$r/g;
@t=localtime(time());
@mes=('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
$r=$t[3].$mes[$t[4]].$t[5];
$r='0'.$r if length($r)<7;
$lsm =~ s/\!3/$r/g;
replace('rhtvision.lsm',$lsm);
replace('rhtvision.txt',$lsm);


