The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/local/bin/perl -w
use strict;

use ExtUtils::Manifest "/mani/";
use POSIX qw(getcwd);

use vars qw($opt_dev $opt_man $opt_lax $opt_sfx $version);

use Getopt::Long;

GetOptions('dev=s','man','lax','sfx=s');

sub System
{
 print STDERR join(' ',@_),"\n" if (@_ < 8);
 die "Cannot " . join(' ',@_) if (system(@_));
}


open(MF,"<Tk.pm") || die "Cannot open Tk.pm:$!";
while (<MF>)
 {
  if (/\$Tk::VERSION\s*=\s*'([^']+)'/)
   {
    $version = $1;
    last;
   }
 }
close(MF);

die "Cannot find version\n" unless defined $version;

System("perl","Makefile.PL") unless (-r "Makefile");

System("make","manifest") if ($opt_man);

my $path  = getcwd();
my $dir   = $path;
my $files = maniread();
$dir      = 'Tk';

$opt_sfx = '_'.$opt_sfx if (length($opt_sfx) && $opt_sfx !~ /^_/);

system(p4 => edit => 'Tk.pm', 'Change.log');
system("p4 changes -l ./... > Change.log");
open(my $fh,"|p4 submit -i") || die;
print $fh <<"END";
Change:	new

Client:	llama

User:	nick

Status:	new

Description:
	$dir-$version$opt_sfx Release Preparation

Files:
	//depot/Tkutf8/Change.log	# edit
	//depot/Tkutf8/Tk.pm	# edit
END
close($fh);

my $snag = 0;

foreach my $file (keys %$files)
 {
  unless (-f $file)
   {
    $snag++;
    warn "$file not found\n";
   }
  if (-z $file)
   {
    $snag++;
    warn "$file is zero sized\n";
   }
 }

exit(1) if $snag && !$opt_lax;


my @files = map("$dir-$version$opt_sfx/$_",sort(keys %$files));
chdir("..");

unlink("$dir-$version$opt_sfx") if (-l "$dir-$version$opt_sfx");
symlink($path,"$dir-$version$opt_sfx") || die "Cannot link $dir $dir-$version$opt_sfx:$!";

$dir .= "-$version$opt_sfx";

system("mv","$dir.tar.gz","$dir.tar.gz%") if (-e "$dir.tar.gz");

if (defined $opt_dev)
 {
  System("tar","-cf",$opt_dev,@files);
  System("tar","-tvf",$opt_dev);
 }
else
 {
  warn "Writing $dir.tar\n";
  System("tar","-cf","$dir.tar",@files);
  warn "gzip'ing $dir.tar\n";
  System("gzip",'-9',"$dir.tar");
 }