#! perl -lw
use RISCOS;
use File::Copy;

# Swap the files in the perl library from Name/pm to pm.Name

die "$0 <from> <to>" unless( @ARGV == 2 );

$from = shift;
$to = shift;

sub ensuredir ($) {
    my ($path);
    foreach (split /\./, $_[0])
    {
	if( defined $path )
	{
	    $path .= ".$_";
	}
	else
	{
	    $path = $_
	}
	mkdir $path, 0777 or warn $! unless -d $path;
    }
}

foreach (qw(Fcntl IO.File IO.Handle Opcode POSIX Socket SDBM_File))
{
    $lib = "$_/pm";
    if (/(.*)\./)
    {
        # IO
        $destdir = "$to.$1.lib.$1";
        $dest = "$to.$1.lib.$lib";
    }
    else
    {
        $destdir = "$to.$_";
        $dest = "$to.$_.$lib";
    }
    ensuredir $destdir;
    rename "$from.$lib", "$dest",  or warn "$from.$lib	$dest $!"
      if -f "$from.$lib";
}


