#!/bin/sh
#
# Change the definition of CCL_DEFAULT_DIRECTORY below to refer to
# your Clozure CL installation directory.  
# Any definition of CCL_DEFAULT_DIRECTORY already present in the environment 
# takes precedence over definitions made below.

probe()
{
    if [ -e "$1"  -a  -e "$1/scripts/ccl" ]; then
        CCL_DEFAULT_DIRECTORY="$1"
    fi
}

if [ -z "$CCL_DEFAULT_DIRECTORY"  -a  -n "`which readlink`" ]; then
    dir="`readlink $0`"
    probe "${dir%/scripts/ccl}"
fi

if [ -z "$CCL_DEFAULT_DIRECTORY" ]; then
    probe "`pwd`"
fi

if [ -z "$CCL_DEFAULT_DIRECTORY" ]; then
    probe "/usr/local/src/ccl"
fi

if [ -z "$CCL_DEFAULT_DIRECTORY" ]; then
    echo "Can't find CCL directory.  Please edit $0 or"
    echo "set the environment variable CCL_DEFAULT_DIRECTORY"
    echo "and try again."
    exit 1
fi

export CCL_DEFAULT_DIRECTORY

# This is shorter (& easier to type), making the invocation below
# a little easier to read.

DD=${CCL_DEFAULT_DIRECTORY}

# If you don't want to guess the name of the Clozure CL kernel on
# every invocation (or if you want to use a kernel with a
# non-default name), you might want to uncomment and change
# the following line:
#OPENMCL_KERNEL=some_name

# Set the CCL_DEFAULT_DIRECTORY  environment variable; 
# the lisp will use this to setup translations for the CCL: logical host.

if [ -z "$OPENMCL_KERNEL" ]; then
  case `uname -s` in
    Darwin) case `arch` in
              ppc*) OPENMCL_KERNEL=dppccl ;;
              i386) OPENMCL_KERNEL=dx86cl ;;
            esac ;;
    Linux) case `uname -m` in
              ppc*) OPENMCL_KERNEL=ppccl ;;
              *86*) OPENMCL_KERNEL=lx86cl ;;
           esac ;;
    CYGWIN*)
       OPENMCL_KERNEL=wx86cl.exe
       CCL_DEFAULT_DIRECTORY="C:/cygwin$CCL_DEFAULT_DIRECTORY"
    ;;
    SunOS) OPENMCL_KERNEL=sx86cl
    ;;
    FreeBSD) OPENMCL_KERNEL=fx86cl
    ;;
    *)
    echo "Can't determine host OS.  Fix this."
    exit 1
    ;;
  esac
fi

exec ${DD}/${OPENMCL_KERNEL} "$@"

