#!/bin/bash

if [ "$0" = "$BASH_SOURCE" ] ; then echo "Usage : source ${BASH_SOURCE[0]}" ; exit 1 ; fi

version="ooRexx sandbox-jlf"
echo Setting environment for running $version

# add to front of path
prepend_path()
{
  if eval test -z "\"\$$1\"" || ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z "\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
    eval "$1=\"$2\":\$$1"
  fi
}

# Under macos, readlink doesn't support the option -f
#me=$(readlink -f ${BASH_SOURCE[0]})
#export OOREXX_HOME=`dirname "$me"`

me="${BASH_SOURCE[0]}"
export OOREXX_HOME="$( cd -P "$(dirname "$me")" && pwd )"

echo -n -e "\033]0;$version\007"

export PATH
export DYLD_LIBRARY_PATH
export DYLD_FALLBACK_LIBRARY_PATH
export NLSPATH
export CPLUS_INCLUDE_PATH
export LIBRARY_PATH

prepend_path PATH $OOREXX_HOME/bin
prepend_path PATH $OOREXX_HOME/packages
prepend_path DYLD_LIBRARY_PATH $OOREXX_HOME/lib
prepend_path DYLD_FALLBACK_LIBRARY_PATH $OOREXX_HOME/lib
prepend_path NLSPATH $OOREXX_HOME/bin/rexx.cat
prepend_path CPLUS_INCLUDE_PATH $OOREXX_HOME/include
prepend_path LIBRARY_PATH $OOREXX_HOME/lib

source $OOREXX_HOME/bsf4oorexx/install/setEnvironment4BSF.sh
