#!/usr/pkg/bin/perl

package PilotMgr;
our $BASEDIR;
our $CONDUITDIR;

# This begin block tracks down the actual location of the
# PilotManager code and puts it into @INC
#
BEGIN
{
    use Config;
    use File::Basename;
    use Cwd;

    my ($full);
    my ($cwd);

    $cwd = Cwd::cwd();
    $full = $0;
    while (-l $full)
    {
	$BASEDIR = dirname($full);
	$full = readlink $full;
	($full !~ m|^/|) and $full = $BASEDIR . "/" . $full;
    }
    $BASEDIR = dirname($full);

    $BASEDIR = "$cwd"
	if (!$BASEDIR || $BASEDIR eq "./" || $BASEDIR eq ".");

    $BASEDIR = "$cwd/$BASEDIR"
	unless ($BASEDIR =~ m|^/|);

    # I'd like to do: 'use lib $BASEDIR' but for some reason 
    # 'use lib' doesn't grok variables.
    #
    unshift(@INC, $BASEDIR . "/lib/perl5/$Config::Config{archname}/$]");
    unshift(@INC, $BASEDIR . "/lib/perl5/$Config::Config{archname}");
    unshift(@INC, $BASEDIR . "/lib/perl5");
    unshift(@INC, $BASEDIR);
    unshift(@INC, $CONDUITDIR) if defined $CONDUITDIR;
}

use PilotMgr;

PilotMgr::main();
