#!/usr/local/bin/perl -w

# look in "./rapp" for the versions of MDComm that have already been
# configured
$rapp = './rapp';
$mdcomm = "$rapp/apps/mdcomm";

# Assume that looking at the binaries directories is sufficient

opendir(DIR, "$mdcomm/bin/");
@bin_files = grep(-d "$mdcomm/bin/$_", readdir(DIR));
print "$mdcomm/bin --> @bin_files <--\n";
closedir(DIR);

# There are the machine mappings I can handle

$map{'SGI5'} = 'IRIX5';
$map{'HPPA'} = 'HPUX9';

# make the sym link
&setup_include;

# get the architecture name off each directory
foreach $file (@bin_files) {
    next if ($file eq '.' || $file eq '..');
    print "Found $file\n";
    if (defined($map{$file})) {
	&setup_arch($file, $map{$file});
    } else {
	print STDERR "Cannot setup rapp/mdcomm for the $file OS\n";
    }
}

sub setup_include {
    if (! -x 'include') {
	symlink("$rapp/include", 'include');
    }
}

sub setup_arch {
    local($rapp_arch, $arch) = @_;
    print "Setting up for $arch\n";
    symlink("$mdcomm/lib/$rapp_arch", "lib_$arch");
    symlink("$mdcomm/bin/$rapp_arch", "bin_$arch");
}
