# process arguments
if ($1 == '-v') then
    set gluex_env_verbose=1
else
    set gluex_env_verbose=0
endif
# general stuff
if (! $?GLUEX_TOP) setenv GLUEX_TOP /usr/local/gluex
if (! $?BUILD_SCRIPTS) setenv BUILD_SCRIPTS $GLUEX_TOP/build_scripts
if (! $?LD_LIBRARY_PATH) setenv LD_LIBRARY_PATH ''
set machine_type=`uname -m`
#
# xerces-c++
#
if (! $?XERCESCROOT) then
    if ($?XERCESC_VERSION) then
	setenv XERCESCROOT $GLUEX_TOP/xerces-c/xerces-c-$XERCESC_VERSION
    else
	setenv XERCESCROOT $GLUEX_TOP/xerces-c/prod
    endif
endif
setenv XERCES_INCLUDE $XERCESCROOT/include
echo $LD_LIBRARY_PATH | grep $XERCESCROOT/lib > /dev/null
if ($status) setenv LD_LIBRARY_PATH  $XERCESCROOT/lib:$LD_LIBRARY_PATH
#
# root
#
if (! $?ROOTSYS) then
    if ($?ROOT_VERSION) then
	setenv ROOTSYS $GLUEX_TOP/root/root_$ROOT_VERSION
    else
	setenv ROOTSYS $GLUEX_TOP/root/prod
    endif
endif
echo $PATH | grep $ROOTSYS/bin > /dev/null
if ($status) setenv PATH $ROOTSYS/bin:$PATH
echo $LD_LIBRARY_PATH | grep $ROOTSYS/lib > /dev/null
if ($status) setenv LD_LIBRARY_PATH  $ROOTSYS/lib:$LD_LIBRARY_PATH
#
# cernlib
#
if (! $?CERN ) setenv CERN $GLUEX_TOP/cernlib
if (! $?CERN_LEVEL) then
    if ($machine_type == 'x86_64') then
        setenv CERN_LEVEL 2005
    else
	if ($?CERNLIB_VERSION) then
	    setenv CERN_LEVEL $CERNLIB_VERSION
	else
	    setenv CERN_LEVEL 2006
	endif
    endif
endif
setenv CERN_ROOT $CERN/$CERN_LEVEL
echo $PATH | grep $CERN_ROOT/bin > /dev/null
if ($status) setenv PATH $CERN_ROOT/bin:$PATH
#
# clhep
#
if (! $?CLHEP) then
    if ($?CLHEP_VERSION) then
	setenv CLHEP $GLUEX_TOP/clhep/$CLHEP_VERSION
    else
	setenv CLHEP $GLUEX_TOP/clhep/prod
    endif
endif
setenv CLHEP_INCLUDE $CLHEP/include
setenv CLHEP_LIB $CLHEP/lib
echo $LD_LIBRARY_PATH | grep $CLHEP_LIB > /dev/null
if ($status) setenv LD_LIBRARY_PATH ${CLHEP_LIB}:${LD_LIBRARY_PATH}
#
# hdds
#
if (! $?HDDS_HOME) then
    if ($?HDDS_VERSION) then
	setenv HDDS_HOME $GLUEX_TOP/hdds/hdds-$HDDS_VERSION
    else
	setenv HDDS_HOME $GLUEX_TOP/hdds/prod
    endif
endif
#
# sim-recon
#
if ($?HALLD_HOME) then
    setenv SIM_RECON_HOME $HALLD_HOME
endif
if ($?HALLD_MY) then
    setenv SIM_RECON_MY $HALLD_MY
endif
if (! $?SIM_RECON_HOME) then
    if ($?SIM_RECON_VERSION) then
	setenv SIM_RECON_HOME $GLUEX_TOP/sim-recon/sim-recon-$SIM_RECON_VERSION
    else
	setenv SIM_RECON_HOME $GLUEX_TOP/sim-recon/prod
    endif
endif
if (! $?SIM_RECON_MY) setenv SIM_RECON_MY $HOME/sim-recon_my
setenv HALLD_HOME $SIM_RECON_HOME # for backward compatibility
setenv HALLD_MY $SIM_RECON_MY # same
setenv BMS_OSNAME `$BUILD_SCRIPTS/osrelease.pl`
echo $PATH | grep $SIM_RECON_HOME/bin/$BMS_OSNAME > /dev/null
if ($status) setenv PATH $SIM_RECON_HOME/bin/${BMS_OSNAME}:$PATH
echo $PATH | grep $SIM_RECON_MY/bin/$BMS_OSNAME > /dev/null
if ($status) setenv PATH $SIM_RECON_MY/bin/${BMS_OSNAME}:$PATH
#
# ccdb
#
if (! $?CCDB_HOME) then
    if ($?CCDB_VERSION) then
	setenv CCDB_HOME $GLUEX_TOP/ccdb/ccdb_$CCDB_VERSION
    else
	setenv CCDB_HOME $GLUEX_TOP/ccdb/prod
    endif
endif
source $BUILD_SCRIPTS/ccdb_env.csh
if (! $?CCDB_CONNECTION) setenv CCDB_CONNECTION mysql://ccdb_user@hallddb.jlab.org/ccdb
#
# jana (JANA_GEOMETRY_URL depends on HDDS_HOME)
#
if (! $?JANA_HOME) then
    if ($?JANA_VERSION) then
	setenv JANA_HOME $GLUEX_TOP/jana/jana_$JANA_VERSION
    else
	setenv JANA_HOME $GLUEX_TOP/jana/prod
    endif
endif
if (! $?JANA_CALIB_URL) setenv JANA_CALIB_URL $CCDB_CONNECTION
if (! $?JANA_GEOMETRY_URL) setenv JANA_GEOMETRY_URL \
    xmlfile://$HDDS_HOME/main_HDDS.xml
#
# refresh the list of items in the path
#
rehash
#
# report environment if requested
#
if ($gluex_env_verbose) then
    echo ===gluex_env.csh report===
    echo BMS_OSNAME =  $BMS_OSNAME
    echo BUILD_SCRIPTS = $BUILD_SCRIPTS
    echo CERN_ROOT =  $CERN_ROOT
    echo CLHEP = $CLHEP
    echo GLUEX_TOP = $GLUEX_TOP
    echo SIM_RECON_HOME =  $SIM_RECON_HOME
    echo SIM_RECON_MY = $SIM_RECON_MY
    echo HALLD_HOME =  $SIM_RECON_HOME
    echo HALLD_MY = $SIM_RECON_MY
    echo HDDS_HOME = $HDDS_HOME
    echo JANA_CALIB_URL = $JANA_CALIB_URL
    echo JANA_GEOMETRY_URL = $JANA_GEOMETRY_URL
    echo JANA_HOME =  $JANA_HOME
    echo LD_LIBRARY_PATH = $LD_LIBRARY_PATH
    echo PATH = $PATH
    echo ROOTSYS =  $ROOTSYS
    echo XERCESCROOT =  $XERCESCROOT
    echo CCDB_HOME = $CCDB_HOME
endif
#
# end of script
#
