######################################
#
# Clean all G4 envs
unsetenv  CLHEP_BASE_DIR
unsetenv  CLHEP_INCLUDE_DIR
unsetenv  CLHEP_LIB
unsetenv  CLHEP_LIB_DIR

unsetenv  G4ANALYSIS_USE
unsetenv  G4DEBUG
unsetenv  G4INCLUDE
unsetenv  G4INSTALL

unsetenv  G4LEDATA
unsetenv  G4LEVELGAMMADATA
unsetenv  G4NEUTRONHPDATA
unsetenv  G4RADIOACTIVEDATA
unsetenv  G4ABLADATA

unsetenv  G4LIB
unsetenv  G4LIB_BUILD_G3TOG4
unsetenv  G4LIB_BUILD_SHARED
unsetenv  G4LIB_BUILD_STATIC
unsetenv  G4LIB_BUILD_ZLIB
unsetenv  G4LIB_BUILD_GDML
unsetenv  G4LIB_USE_G3TOG4
unsetenv  G4LIB_USE_GRANULAR
unsetenv  G4LIB_USE_ZLIB

unsetenv  G4VERSION

unsetenv  G4SYSTEM

unsetenv  G4UI_BUILD_WIN32_SESSION
unsetenv  G4UI_BUILD_XAW_SESSION
unsetenv  G4UI_BUILD_XM_SESSION
unsetenv  G4UI_USE_TCSH
unsetenv  G4UI_USE_WIN32
unsetenv  G4UI_USE_XAW
unsetenv  G4UI_USE_XM
unsetenv  G4UI_USE_QT

unsetenv  G4VIS_BUILD_DAWN_DRIVER
unsetenv  G4VIS_BUILD_OIWIN32_DRIVER
unsetenv  G4VIS_BUILD_OIX_DRIVER
unsetenv  G4VIS_BUILD_OPENGLWIN32_DRIVER
unsetenv  G4VIS_BUILD_OPENGLXM_DRIVER
unsetenv  G4VIS_BUILD_OPENGLX_DRIVER
unsetenv  G4VIS_BUILD_RAYTRACERX_DRIVER
unsetenv  G4VIS_BUILD_VRML_DRIVER
unsetenv  G4VIS_BUILD_OPENGLQT_DRIVER

unsetenv  G4VIS_USE_DAWN
unsetenv  G4VIS_USE_OIWIN32
unsetenv  G4VIS_USE_OIX
unsetenv  G4VIS_USE_OPENGLWIN32
unsetenv  G4VIS_USE_OPENGLX
unsetenv  G4VIS_USE_OPENGLXM
unsetenv  G4VIS_USE_RAYTRACERX
unsetenv  G4VIS_USE_VRML
unsetenv  G4VIS_USE_OPENGLQT

######################################

setenv G4VERSION "9.1"
echo "On this machine the G4VERSION=$G4VERSION"

#
# g4system.U
#
#+
setenv G4SYSTEM "Linux-g++"
echo "On this machine the G4SYSTEM=$G4SYSTEM"

#
# g4dirs.U
#
#+
if ( X/usr/local/geant4.9.1.p02 != X/usr/local/geant4.9.1.p02 ) then
setenv G4INSTLL "/usr/local/geant4.9.1.p02/src/geant4"
echo "On this machine the G4INSTALL=$G4INSTALL"
else
setenv G4INSTALL "/usr/local/geant4.9.1.p02"
echo "On this machine the G4INSTALL=$G4INSTALL"
endif

#+
if ( Xn != Xn ) then
if ( X/usr/local/geant4.9.1.p02 != X/usr/local/geant4.9.1.p02 ) then
setenv G4INCLUDE "/usr/local/geant4.9.1.p02/include/geant4"
else
setenv G4INCLUDE "/usr/local/geant4.9.1.p02/include"
endif
echo "On this machine the G4INCLUDE=$G4INCLUDE"
#else
#setenv G4BASE "/usr/local/geant4.9.1.p02/include/geant4/source"
#echo "On this machine the G4BASE=$G4BASE"
endif

#+
if ( X/usr/local/geant4.9.1.p02/lib != X ) then
if ( X/usr/local/geant4.9.1.p02 != X/usr/local/geant4.9.1.p02 ) then
setenv G4LIB "/usr/local/geant4.9.1.p02/lib/geant4"
else
setenv G4LIB "/usr/local/geant4.9.1.p02/lib"
endif
echo "On this machine the G4LIB=$G4LIB"
endif

#+
if ( X/usr/local/geant4.9.1.p02/data/PhotonEvaporation2.0 != X ) then
setenv G4LEVELGAMMADATA "/usr/local/geant4.9.1.p02/data/PhotonEvaporation2.0"
echo "On this machine the G4LEVELGAMMADATA=$G4LEVELGAMMADATA"
endif

#+
if ( X/usr/local/geant4.9.1.p02/data/RadioactiveDecay3.2 != X ) then
setenv G4RADIOACTIVEDATA "/usr/local/geant4.9.1.p02/data/RadioactiveDecay3.2"
echo "On this machine the G4RADIOACTIVEDATA=$G4RADIOACTIVEDATA"
endif

#+
if ( X/usr/local/geant4.9.1.p02/data/G4EMLOW5.1 != X ) then
setenv G4LEDATA "/usr/local/geant4.9.1.p02/data/G4EMLOW5.1"
echo "On this machine the G4LEDATA=$G4LEDATA"
endif

#+
if ( X/usr/local/geant4.9.1.p02/data/G4NDL3.12 != X ) then
setenv G4NEUTRONHPDATA "/usr/local/geant4.9.1.p02/data/G4NDL3.12"
echo "On this machine the G4NEUTRONHPDATA=$G4NEUTRONHPDATA"
endif

#+
if ( X/usr/local/geant4.9.1.p02/data/G4ABLA3.0 != X ) then
setenv G4ABLADATA "/usr/local/geant4.9.1.p02/data/G4ABLA3.0"
echo "On this machine the G4ABLADATA=$G4ABLADATA"
endif


#+
#if ( X != X ) then
#setenv G4ELASTICDATA ""
#echo "On this machine the G4ELASTICDATA=$G4ELASTICDATA"
#endif

#
# g4clhep.U
#
if ( X/usr/local/clhep2.0.3.2 != X ) then
setenv CLHEP_BASE_DIR "/usr/local/clhep2.0.3.2"
echo "On this machine the CLHEP_BASE_DIR=$CLHEP_BASE_DIR"
endif

#+
if ( X/usr/local/clhep2.0.3.2/include != X ) then
setenv CLHEP_INCLUDE_DIR "/usr/local/clhep2.0.3.2/include"
echo "On this machine the CLHEP_INCLUDE_DIR=$CLHEP_INCLUDE_DIR"
endif

#+
if ( X/usr/local/clhep2.0.3.2/lib != X ) then
setenv CLHEP_LIB_DIR "/usr/local/clhep2.0.3.2/lib"
echo "On this machine the CLHEP_LIB_DIR=$CLHEP_LIB_DIR"
endif

#+
if ( XCLHEP != X ) then
setenv CLHEP_LIB "CLHEP"
echo "On this machine the CLHEP_LIB=$CLHEP_LIB"
endif

#+
#
# g4debug
#
if ( Xn == Xy ) then
setenv G4DEBUG 1
echo "On this machine the G4DEBUG=$G4DEBUG"
endif

#
# g4analysis
#
#+
if ( Xn == Xy ) then
setenv G4ANALYSIS_USE 1
echo "On this machine the G4ANALYSIS_USE=$G4ANALYSIS_USE"
endif

#
# g4ui
#
#+
if ( Xy == Xy ) then
setenv G4UI_BUILD_XAW_SESSION 1
echo "On this machine the G4UI_BUILD_XAW_SESSION=$G4UI_BUILD_XAW_SESSION"
endif

#+
if ( Xy == Xy ) then
setenv G4UI_USE_XAW 1
echo "On this machine the G4UI_USE_XAW=$G4UI_USE_XAW"
endif

#+
if ( Xy == Xy ) then
setenv G4UI_BUILD_XM_SESSION 1
echo "On this machine the G4UI_BUILD_XM_SESSION=$G4UI_BUILD_XM_SESSION"
endif

#+
if ( Xy == Xy ) then
setenv G4UI_USE_XM 1
echo "On this machine the G4UI_USE_XM=$G4UI_USE_XM"
endif

#+
if ( Xn == Xy ) then
setenv G4UI_BUILD_WIN32_SESSION 1
echo "On this machine the G4UI_BUILD_WIN32_SESSION=$G4UI_BUILD_WIN32_SESSION"
endif

#+
if ( Xn == Xy ) then
setenv G4UI_USE_WIN32 1
echo "On this machine the G4UI_USE_WIN32=$G4UI_USE_WIN32"
endif

#+
if ( Xn == Xy ) then
setenv G4UI_BUILD_QT_SESSION 1
echo "On this machine the G4UI_BUILD_QT_SESSION=$G4UI_BUILD_QT_SESSION"
endif 

#+
if ( Xn == Xy ) then
setenv G4UI_USE_QT 1
echo "On this machine the G4UI_USE_QT=$G4UI_USE_QT"
endif 



#
# g4vis
#
#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_DAWN_DRIVER 1
echo "On this machine the G4VIS_BUILD_DAWN_DRIVER=$G4VIS_BUILD_DAWN_DRIVER"
endif

#+
if ( Xy == Xy ) then
setenv G4VIS_BUILD_OPENGLX_DRIVER 1
echo "On this machine the G4VIS_BUILD_OPENGLX_DRIVER=$G4VIS_BUILD_OPENGLX_DRIVER"
endif

#+
if ( Xy == Xy ) then
setenv G4VIS_BUILD_OPENGLXM_DRIVER 1
echo "On this machine the G4VIS_BUILD_OPENGLXM_DRIVER=$G4VIS_BUILD_OPENGLXM_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_OPENGLWIN32_DRIVER 1
echo "On this machine the G4VIS_BUILD_OPENGLWIN32_DRIVER=$G4VIS_BUILD_OPENGLWIN32_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_OIX_DRIVER 1
echo "On this machine the G4VIS_BUILD_OIX_DRIVER=$G4VIS_BUILD_OIX_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_RAYTRACERX_DRIVER 1
echo "On this machine the G4VIS_BUILD_RAYTRACERX_DRIVER=$G4VIS_BUILD_RAYTRACERX_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_OIWIN32_DRIVER 1
echo "On this machine the G4VIS_BUILD_OIWIN32_DRIVER=$G4VIS_BUILD_OIWIN32_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_VRML_DRIVER 1
echo "On this machine the G4VIS_BUILD_VRML_DRIVER=$G4VIS_BUILD_VRML_DRIVER"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_BUILD_OPENGLQT_DRIVER 1
echo "On this machine the G4VIS_BUILD_OPENGLQT_DRIVER=$G4VIS_BUILD_OPENGLQT_DRIVER"
endif 


#+
if ( Xn == Xy ) then
setenv G4VIS_USE_DAWN 1
echo "On this machine the G4VIS_USE_DAWN=$G4VIS_USE_DAWN"
endif

#+
if ( Xy == Xy ) then
setenv G4VIS_USE_OPENGLX 1
echo "On this machine the G4VIS_USE_OPENGLX=$G4VIS_USE_OPENGLX"
endif

#+
if ( Xy == Xy ) then
setenv G4VIS_USE_OPENGLXM 1
echo "On this machine the G4VIS_USE_OPENGLXM=$G4VIS_USE_OPENGLXM"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_OPENGLWIN32 1
echo "On this machine the G4VIS_USE_OPENGLWIN32=$G4VIS_USE_OPENGLWIN32"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_OIX 1
echo "On this machine the G4VIS_USE_OIX=$G4VIS_USE_OIX"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_RAYTRACERX 1
echo "On this machine the G4VIS_USE_RAYTRACERX=$G4VIS_USE_RAYTRACERX"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_OIWIN32 1
echo "On this machine the G4VIS_USE_OIWIN32=$G4VIS_USE_OIWIN32"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_VRML 1
echo "On this machine the G4VIS_USE_VRML=$G4VIS_USE_VRML"
endif

#+
if ( Xn == Xy ) then
setenv G4VIS_USE_OPENGLQT 1
echo "On this machine the G4VIS_USE_OPENGLQT=$G4VIS_USE_OPENGLQT"
endif

#+
if ( X != X )  then
setenv OGLHOME ""
echo "On this machine the OGLHOME=$OGLHOME"
endif 

#+
if ( X != X )  then
setenv OIVHOME ""
echo "On this machine the OIVHOME=$OIVHOME"
endif 

#+
if ( X != X ) then
setenv QTHOME ""
echo "On this machine the QTHOME=$QTHOME"
endif



#+
if ( Xy != X )  then
setenv XMFLAGS " -I/include "
echo "On this machine the XMFLAGS=$XMFLAGS"
endif 

#+
if ( Xy != X )  then
setenv XMLIBS " -L/lib -lXm -lXpm "
echo "On this machine the XMLIBS=$XMLIBS"
endif 

#+
if ( Xy != X )  then
setenv XMFLAGS " -I/include "
echo "On this machine the XMFLAGS=$XMFLAGS"
endif 

#+
if ( Xy != X )  then
setenv XMLIBS " -L/lib -lXm -lXpm "
echo "On this machine the XMLIBS=$XMLIBS"
endif 

#+
if ( Xy != X )  then
setenv XAWFLAGS " -I/include "
echo "On this machine the XAWFLAGS=$XAWFLAGS"
endif 

#+
if ( Xy != X )  then
setenv XAWLIBS " -L/lib -lXaw "
echo "On this machine the XAWLIBS=$XAWLIBS"
endif 



#
# Use GDML module
#
#+
if ( Xn == Xy ) then
setenv G4LIB_BUILD_GDML 1
echo "On this machine the G4LIB_BUILD_GDML=$G4LIB_BUILD_GDML"
endif 

if ( Xn == Xy ) then
setenv XERCESCROOT ""
echo "On this machine the XERCESCROOT=$XERCESCROOT"
endif




#
# Use G3TOG4 module
#
#+
if ( Xn == Xy )  then
setenv G4LIB_BUILD_G3TOG4 1
echo "On this machine the G4LIB_BUILD_G3TOG4=$G4LIB_BUILD_G3TOG4"
endif 

if ( Xn == Xy )  then
setenv G4LIB_USE_G3TOG4 1
echo "On this machine the G4LIB_USE_G3TOG4=$G4LIB_USE_G3TOG4"
endif 


#
# Use ZLIB module
#
#+
if ( Xn == Xy )  then
setenv G4LIB_BUILD_ZLIB 1
echo "On this machine the G4LIB_BUILD_ZLIB=$G4LIB_BUILD_ZLIB"
endif 

if ( X == Xy )  then
setenv G4LIB_USE_ZLIB 1
echo "On this machine the G4LIB_USE_ZLIB=$G4LIB_USE_ZLIB"
endif 

#+
#
# g4shared
#
if ( Xn == Xy ) then
setenv G4LIB_BUILD_SHARED 1
echo "On this machine the G4LIB_BUILD_SHARED=$G4LIB_BUILD_SHARED"
endif

if ( Xy == Xy ) then
setenv G4LIB_BUILD_STATIC 1
echo "On this machine the G4LIB_BUILD_STATIC=$G4LIB_BUILD_STATIC"
endif

#+
#
# g4granular
#
if ( Xy == Xy ) then
setenv G4LIB_USE_GRANULAR 1
echo "On this machine the G4LIB_USE_GRANULAR=$G4LIB_USE_GRANULAR"
endif

# Check for Windows!
if ( "X$G4SYSTEM" != "XWIN32-VC" && "X$G4SYSTEM" != "XWIN32-VC7" ) then
setenv G4UI_USE_TCSH 1
echo "On this machine the G4UI_USE_TCSH=$G4UI_USE_TCSH"
endif

#####################################################################



#+
#
# G4WORKDIR
#
if ( ${?G4WORKDIR} ) then
echo "In your environment you have the G4WORKDIR=$G4WORKDIR"
else
# Check for Windows!
if ( "X$G4SYSTEM" == "XWIN32-VC" || "X$G4SYSTEM" == "XWIN32-VC7" ) then

echo "G4WORKDIR will be set to c:/geant4 (in "native" Windows syntax)."
setenv G4WORKDIR "c:/geant4"

else # if Unix

echo "G4WORKDIR will be set to HOME/geant4=$HOME/geant4"
setenv G4WORKDIR $HOME/geant4

endif
endif

#
# Shared libraries
#
#  (G4LIB_BUILD_SHARED won't be modified by the following process because we didn't activate the shared libraries option when underwent Geant4 Configuration )
#
if ( ${?G4LIB_BUILD_SHARED} ) then

#
# Warning about LD_LIBRARY_PATH
#
echo ''
echo 'LD_LIBRARY_PATH is set to include CLHEP and Geant4 libraries. '
echo ''
echo 'NOTE : verify that the correct path for the CLHEP library'
echo '- $CLHEP_BASE_DIR/lib - is included in the $LD_LIBRARY_PATH'
echo 'variable in your environment, and no other outdated installations'
echo 'of CLHEP are by chance referenced through $LD_LIBRARY_PATH and'
echo 'present in your system !'
echo ''

if ( ${?LD_LIBRARY_PATH} )  then
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${G4LIB}/${G4SYSTEM}
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${CLHEP_BASE_DIR}/lib


if ( ${?G4LIB_BUILD_GDML} ) then
   setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${XERCESCROOT}/lib
endif

else
setenv LD_LIBRARY_PATH ${G4LIB}/${G4SYSTEM}
setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${CLHEP_BASE_DIR}/lib


if ( ${?G4LIB_BUILD_GDML} ) then
   setenv LD_LIBRARY_PATH ${LD_LIBRARY_PATH}:${XERCESCROOT}/lib
endif

endif
endif

#
# Shared libraries for Mac
#
if ( "X$G4SYSTEM" == "XDarwin-g++" ) then

if ( ${?G4LIB_BUILD_SHARED} ) then
if ( ${?DYLD_LIBRARY_PATH} )  then
setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:${G4LIB}/${G4SYSTEM}
setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:${CLHEP_BASE_DIR}/lib

if ( ${?G4LIB_BUILD_GDML} ) then
   setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:${XERCESCROOT}/lib
endif

else
setenv DYLD_LIBRARY_PATH ${G4LIB}/${G4SYSTEM}
setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:${CLHEP_BASE_DIR}/lib

if ( ${?G4LIB_BUILD_GDML} ) then
   setenv DYLD_LIBRARY_PATH ${DYLD_LIBRARY_PATH}:${XERCESCROOT}/lib
endif

endif
endif

endif

#
# For BIN
#
setenv PATH ${PATH}:${G4WORKDIR}/bin/${G4SYSTEM}
