use File::Path qw(make_path remove_tree);
use File::Basename;
use Cwd 'abs_path';
use File::Copy;
use File::Find;
use Cwd;
$tarfile = "";
$outdir = "";
$tmpdir = "";
$version = "";
$revision = "";
$rhel = osrel( );
foreach ( @ARGV ) {
m|^out=(.+)$| && ($outdir=$1,next);
m|^tar=(.+)$| && ($tarfile=$1,next);
m|^tmp=(.+)$| && ($tmpdir=$1,next);
m|^ver=(\d+\.\d+\.\d+)-(\d+)$| && ($version = $1, $revision = $2, next);
}
die "please specify the tar file containing a CASA workspace with 'tar=<FILE>'" unless -f $tarfile;
die "please specify an output directory with 'out=<DIR>'" unless -d $outdir;
die "please specify a temporary directory with 'tmp=<DIR>'" unless -d $tmpdir;
die "please specify the version number, e.g. 'ver=4.6.0-47'" unless $version && $revision;
die "failed to find os version" unless $rhel;
$outdir = abs_path($outdir);
$tmpdir = abs_path($tmpdir);
copy($tarfile,$tmpdir) or die "could not copy workspace tar file to temporary directory";
my $name = basename($tarfile);
$tarfile = "$tmpdir/$name";
print "------- unpacking workspace --------------------------------------------\n";
if ( `file $tarfile` =~ m|gzip compressed data| ) {
my $output = `gunzip -v $tarfile 2>&1`;
if ( $output =~ m|replaced with (\S+)| ) {
$tarfile = abs_path($1);
die "unzipping of tar file ($tarfile) failed" unless -f $tarfile;
} else {
print "$output\n";
die "gunzip difficulties...";
}
}
die "$tarfile is not a tar file" unless `file $tarfile` =~ m|tar archive|;
$topdir = $tmpdir;
$builddir = "$topdir/BUILD";
make_path($builddir);
open(UNTAR,"tar -C $builddir -vxf $tarfile 2>&1 |");
my %roots = ( );
while ( <UNTAR> ) {
my @seg = split("/");
$roots{$seg[0]} = 1;
}
close(UNTAR);
my @roots = keys %roots;
die "found no roots" if scalar(@roots) == 0;
die "found multiple roots: @roots" if scalar(@roots) != 1;
$wsroot = $roots[0];
$wsdir = "$builddir/$wsroot";
die "could not extract workspace" unless -d $wsdir;
print "------------------------------------------------------------------------\n";
$destroot = "$topdir/BUILD/$wsroot/_preinstall_";
die "could not create build root" unless make_path($destroot);
$orig = getcwd( );
chdir($wsdir);
@cruft = ("code/include/pgxwin.h","code/include/wcsconfig_f77.h");
foreach ( @cruft ) { unlink($_) }
$optdir = "/opt/casa/versions/${version}R";
$optpydir = "$optdir/lib/python2.7";
$rootdir = "$destroot$optdir";
$bindir = "$rootdir/bin";
$libdir = "$rootdir/lib";
$plibdir = "$destroot$optpydir";
$incdir = "$rootdir/include";
$pgplotdir = "$rootdir/pgplot";
$usrbindir = "$destroot/usr/bin";
$usrbindir = "$destroot/usr/bin";
$optbindir = "$destroot/opt/casa/bin";
$python = "/opt/casa/02/bin/python";
$thirdparty_path = "/opt/casa/02";
$rpath = "$optdir/lib:$thirdparty_path/lib:$thirdparty_path/lib/libsakura/default/lib";
$rpath_min = "$optdir/lib:$thirdparty_path/lib";