package GSDLHOME;

BEGIN {

    if (!defined $ENV{'GSDLHOME'}) {
	# read gsdlhome from gsdlsite.cfg
	open (GSDLSITE, "gsdlsite.cfg") || die 
	    "GSDLHOME.pm: unable to open gsdlsite.cfg\n";
	my $line = "";
	while (defined ($line = <GSDLSITE>)) {
	    if ($line =~ /^gsdlhome\s+(.*?)\s*$/) {
		$ENV{'GSDLHOME'} = $1;
		last;
	    }
	}
	die "GSDLHOME.pm: couldn't find gsdlhome field in gsdlsite.cfg\n"
	    unless defined $ENV{'GSDLHOME'};
    }

    # just in case GSDLHOME has a slash on the end which would cause
    # double slashes below
    $ENV{'GSDLHOME'} =~ s/[\/\\]+$//;

    $ENV{'GSDLOS'} = $^O;

    if ($ENV{'GSDLOS'} =~ /(win|dos)/i) {
	$ENV{'GSDLOS'} = 'windows';
    }
    
    $ENV{'PATH'} .= ":$ENV{'GSDLHOME'}/bin/script";
    $ENV{'PATH'} .= ":$ENV{'GSDLHOME'}/bin/$ENV{'GSDLOS'}";
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
}

1;
