#!/usr/bin/perl
# This script creates a shell script to initialize environment for
# GLED to '.' directory and ROOT to first argument.
# It will not set environment for external packages; see binenv.(c)sh for that
# use as: . `./mkenv <root-sys>`

if($#ARGV != 0) {
  print "usage: . `./mkenv <root-sys>`\n";
  exit 1;
}
unless(-d $ARGV[0]) {
  print "mkenv: directory $ARGV[0] does not exist\n";
  exit 1;
}


chomp ($tmp = `mktemp /tmp/mkenv.XXXXXX`);
open TMP, ">$tmp";

print TMP<<"FNORD";
export ROOTSYS=$ARGV[0]
export PATH=\$ROOTSYS/bin:\$PATH
export LD_LIBRARY_PATH=.:\$ROOTSYS/lib:\$LD_LIBRARY_PATH
FNORD

# gled in current directory
# note that `pwd` can yield weird pathnames for auto-mounted directories
print TMP<<"FNORD";
export GLEDSYS=`pwd`
export PATH=\$GLEDSYS/bin:\$PATH
export LD_LIBRARY_PATH=\$GLEDSYS/lib:\$LD_LIBRARY_PATH
FNORD

print TMP "\nrm $tmp\n";
close TMP;
print $tmp;
