#!/bin/sh
# The contents of this file are subject to the Netscape Public License
# Version 1.1 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
# 
# Software distributed under the License is distributed on an "AS IS"
# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
# the License for the specific language governing rights and limitations
# under the License.
# 
# The Original Code was released August, 1999.  The Initial Developer
# of the Original Code is Netscape Communications Corporation.  Portions
# created by Netscape are Copyright (C) 1999, 2000 Netscape Communications
# Corporation.  All Rights Reserved.
# 
# Contributor(s): John Kristian <kristian@netscape.com>
#                 Richard Megginson <richm@netscape.com>
# --------------------------------------------------------------------

# $1 must be a fully-qualified pathname to the current working directory.
# Create `nsperl` executables named $2, $3, ...

# Find the full pathnames of the directories into which to install:
PKG=`dirname "$0"`
if [ "$PKG" = "" ]; then
    echo >&2 "$0 can't tell what directory contains it."
    exit 1
fi
case "$PKG" in
   /* ) ;;
    * ) PKG="$1"/"$PKG" ;;
esac
shift
ARCHLIB=`dirname "$PKG"`
PRIVLIB=`dirname "$ARCHLIB"`
PREFIX=`dirname "$PRIVLIB"`

# Create a program that runs standard Perl with added environment variables.
# Don't beautify the following script, much; the code that parses it
# <src/interpreter.cpp> is dumber than you might guess.  In particular,
# {} are not special.  Don't insert whitespace where there is none,
# nor remove any whitespace entirely.
for FILE in "$@"; do
    echo 'source: '"$PKG"/`basename $0`'
ifdef $PERL5LIB { addPath $PERL5LIB : '"$PRIVLIB:$PREFIX/lib/site:."'
}else{            addPath $PERLLIB  : '"$ARCHLIB:$PRIVLIB:$PREFIX/lib/site/i86pc-solaris:$PREFIX/lib/site:."'
}                 addPath '"$PREFIX/lib/i86pc-solaris/CORE"' : $LD_LIBRARY_PATH
exec '"$PREFIX/bin/perl"'
# exec failed.  Maybe this will suggest why:
echoError LD_LIBRARY_PATH is $LD_LIBRARY_PATH
ifdef       $PERL5LIB { echoError PERL5LIB is $PERL5LIB
}else{ ifdef $PERLLIB { echoError PERLLIB is $PERLLIB
} }' | "$PKG"/executor "$FILE" || exit $?
done
