
BEGIN {
    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
}

use Cwd;
require util;    

my $env_ext  = "GEXTVIDEO";
my $ext_desc = "the Video and Audio Extension";

if (!defined $ENV{$env_ext}) {
    
    my $ext_home = cwd();
    my $ext_os = $ENV{'GSDLOS'};

    my ($ext_dir,$_prefix_dir) = File::Basename::fileparse($ext_home);

    print STDERR "*** ext_dir = $ext_dir\n\n\n";


    my $ext_installed = $env_ext."_INSTALLED";

    $ENV{$env_ext} = $ext_home;
    
    $ENV{$ext_installed} = &util::filename_cat($ext_home,$ext_os);

    my $ext_bin = &util::filename_cat($ENV{$ext_installed},"bin");
    my $ext_lib = &util::filename_cat($ENV{$ext_installed},"lib");

    &util::envvar_append("PATH",$ext_bin);

    if ($ext_os =~ m/darwin/i) {
	&util::envvar_append("DYLD_LIBRARY_PATH",$ext_lib);
    }
    else {
	&util::envvar_append("LD_LIBRARY_PATH",$ext_lib);
    }

    # GSDLEXTS always uses : as a separator
    if (defined $ENV{'GSDLEXTS'}) {
	$ENV{'GSDLEXTS'} .= ":$ext_dir";
    }
    else {
	$ENV{'GSDLEXTS'} = $ext_dir;
    }
    
    print STDERR "+Your environment is now setup for $ext_desc\n";
}
else {    
    print STDERR "+Your environment is already setup for $ext_desc\n";
}

if (scalar(@ARGV>0)) {

    print STDERR "\n";

    my $cmd = join(" ",map {$_ = "\"$_\""} @ARGV);

    if (system($cmd)!=0) {
	print STDERR "\nError: Failed to run '$cmd'\n";
	print STDERR "$!\n";
    }
}

1;
