#!/bin/sh
# -*-shell-script-*-
# coot wrapper script 
# Copyright 2004, 2005, 2006 Paul Emsley, University of York
# Copyright 2016 by Medical Research Council

# Dear Coot-packager: there is nothing here of use for you - just 
# exec /usr/libexec/density-score-by-residue-bin $*

#
current_exe_dir=`dirname $0`
echo current_exe_dir is $current_exe_dir

if [ $current_exe_dir = . ] ; then 
  COOT_PREFIX=`dirname $PWD`
else 
  COOT_PREFIX=`dirname "$current_exe_dir"`
fi

echo COOT_PREFIX is $COOT_PREFIX
coot_real=$current_exe_dir/coot-real
# echo coot-real is at $coot_real




# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# If the COOT_PREFIX is correct, then these should not need modification
# i.e.  nothing below here need be changed.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# 
prefix=$COOT_PREFIX
PATH=$COOT_PREFIX/bin:$PATH

SYMINFO=$COOT_PREFIX/share/coot/syminfo.lib
COOT_SCHEME_DIR=$COOT_PREFIX/share/coot/scheme
# COOT_REFMAC_LIB_DIR=$COOT_PREFIX/share/coot/lib
COOT_STANDARD_RESIDUES=$COOT_PREFIX/share/coot/standard-residues.pdb
COOT_PIXMAPS_DIR=$COOT_PREFIX/share/coot/pixmaps
COOT_DATA_DIR=$COOT_PREFIX/share/coot
COOT_RESOURCES_FILE=$COOT_PREFIX/share/coot/cootrc
COOT_REF_STRUCTS=$COOT_PREFIX/share/coot/reference-structures
PYTHONPATH=$COOT_PREFIX/share/coot/python
if [ -z "$PYTHONPATH" ] ; then
    PYTHONPATH=$COOT_PREFIX/share/coot/python
else
    PYTHONPATH=${PYTHONPATH}:$COOT_PREFIX/share/coot/python
fi

systype=`uname`

if [ $systype = Linux ] ; then 
   if [ -z "$LD_LIBRARY_PATH" ] ;  then
	LD_LIBRARY_PATH=$COOT_PREFIX/lib
   else 
	LD_LIBRARY_PATH=$COOT_PREFIX/lib:${LD_LIBRARY_PATH}
   fi
fi

# some (Intel, I supose) Mac users may need to change
# DYLD_LIBRARY_PATH to DYLD_FALLBACK_LIBRARY_PATH, if running into
#  problems with Framwork jpeg libraries (don't forget the export 
# at the end too).
#
if [ $systype = Darwin ] ; then 
   if [ -z "$DYLD_LIBRARY_PATH" ] ;  then
	DYLD_LIBRARY_PATH=$COOT_PREFIX/lib
   else 
	DYLD_LIBRARY_PATH=$COOT_PREFIX/lib:${DYLD_LIBRARY_PATH}
   fi
fi
if [ $systype = IRIX ] ; then 
   if [ -z "$LD_LIBRARYN32_PATH" ] ;  then
	LD_LIBRARYN32_PATH=$COOT_PREFIX/lib
   else 
	LD_LIBRARYN32_PATH=$COOT_PREFIX/lib:${LD_LIBRARYN32_PATH}
   fi
fi
if [ $systype = IRIX64 ] ; then 
   if [ -z "$LD_LIBRARYN32_PATH" ] ;  then
	LD_LIBRARYN32_PATH=$COOT_PREFIX/lib
   else 
	LD_LIBRARYN32_PATH=$COOT_PREFIX/lib:${LD_LIBRARYN32_PATH}
   fi
fi


export SYMINFO
export COOT_PREFIX
export COOT_STANDARD_RESIDUES
# export COOT_REFMAC_LIB_DIR
export PYTHONPATH
export COOT_SCHEME_DIR
export COOT_REF_STRUCTS
export COOT_RESOURCES_FILE
export COOT_PIXMAPS_DIR
export COOT_DATA_DIR
export DYLD_LIBRARY_PATH
export LD_LIBRARY_PATH
export LD_LIBRARYN32_PATH

if [[ $systype == MINGW* ]] ; then 
  exec $COOT_PREFIX/bin/coot-density-score-by-residue-bin $*
else
  exec $COOT_PREFIX/libexec/coot-density-score-by-residue-bin $*
fi
