#! /bin/echo This file must be sourced inside csh using: source
#
#   GNUstep.csh.in
#
#   Shell initialization for the GNUstep environment.
#
#   Copyright (C) 1998-2002 Free Software Foundation, Inc.
#
#   Author:  Scott Christley <scottc@net-community.com>
#   Author:  Adam Fedor <fedor@gnu.org>
#   Author:  Richard Frith-Macdonald <rfm@gnu.org>
#   Author:  Nicola Pero <n.pero@mi.flashnet.it>
#
#   This file is part of the GNUstep Makefile Package.
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#   
#   You should have received a copy of the GNU General Public
#   License along with this library; see the file COPYING.LIB.
#   If not, write to the Free Software Foundation,
#   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

#
# Set the GNUstep system root and local root
#
setenv GNUSTEP_ROOT /usr/local/GNUstep
setenv GNUSTEP_SYSTEM_ROOT /usr/local/GNUstep/System
setenv GNUSTEP_FLATTENED 
if ( ! ${?LIBRARY_COMBO} ) then
  setenv LIBRARY_COMBO gnu-gnu-gnu
endif

setenv GNUSTEP_LOCAL_ROOT /usr/local/GNUstep/Local
setenv GNUSTEP_NETWORK_ROOT /usr/local/GNUstep/Network

setenv GNUSTEP_MAKEFILES ${GNUSTEP_SYSTEM_ROOT}/Makefiles

#
# Determine the host information
#
if ( ! ${?GNUSTEP_HOST} ) then
  pushd /tmp > /dev/null
  setenv GNUSTEP_HOST `${GNUSTEP_MAKEFILES}/config.guess`
  setenv GNUSTEP_HOST `${GNUSTEP_MAKEFILES}/config.sub ${GNUSTEP_HOST}`
  popd > /dev/null
endif

if ( ! ${?GNUSTEP_HOST_CPU} ) then
  setenv GNUSTEP_HOST_CPU `${GNUSTEP_MAKEFILES}/cpu.sh ${GNUSTEP_HOST}`
  setenv GNUSTEP_HOST_CPU `${GNUSTEP_MAKEFILES}/clean_cpu.sh ${GNUSTEP_HOST_CPU}`
endif

if ( ! ${?GNUSTEP_HOST_VENDOR} ) then
  setenv GNUSTEP_HOST_VENDOR `${GNUSTEP_MAKEFILES}/vendor.sh ${GNUSTEP_HOST}`
  setenv GNUSTEP_HOST_VENDOR `${GNUSTEP_MAKEFILES}/clean_vendor.sh ${GNUSTEP_HOST_VENDOR}`
endif

if ( ! ${?GNUSTEP_HOST_OS} ) then
  setenv GNUSTEP_HOST_OS `${GNUSTEP_MAKEFILES}/os.sh ${GNUSTEP_HOST}`
  setenv GNUSTEP_HOST_OS `${GNUSTEP_MAKEFILES}/clean_os.sh ${GNUSTEP_HOST_OS}`
endif

if ( "${GNUSTEP_FLATTENED}" == "" ) then
  setenv GNUSTEP_USER_ROOT `${GNUSTEP_MAKEFILES}/${GNUSTEP_HOST_CPU}/${GNUSTEP_HOST_OS}/user_home user`
else
  setenv GNUSTEP_USER_ROOT `${GNUSTEP_MAKEFILES}/user_home user`
endif

#
# Add the GNUstep tools directories to the path
#
if ( ! ${?GNUSTEP_PATHPREFIX_LIST} ) then
  setenv GNUSTEP_PATHPREFIX_LIST \
         ${GNUSTEP_USER_ROOT}:${GNUSTEP_LOCAL_ROOT}:${GNUSTEP_NETWORK_ROOT}:${GNUSTEP_SYSTEM_ROOT}
endif

set temp_path = ""
foreach dir ( `/bin/sh -c 'IFS=:; for i in ${GNUSTEP_PATHPREFIX_LIST}; do echo $i; done'` )
  set temp_path=${temp_path}${dir}/Tools:
  if ( "${GNUSTEP_FLATTENED}" == "" ) then
    set temp_path=${temp_path}${dir}/Tools/${GNUSTEP_HOST_CPU}/${GNUSTEP_HOST_OS}/${LIBRARY_COMBO}:
    set temp_path=${temp_path}${dir}/Tools/${GNUSTEP_HOST_CPU}/${GNUSTEP_HOST_OS}:
  endif
end

if ( ! ${?PATH} ) then
  setenv PATH "${temp_path}"
else if ( { (echo "$PATH" | fgrep -v "$temp_path" >/dev/null) } ) then
  setenv PATH "${temp_path}${PATH}"
endif
unset temp_path dir

source ${GNUSTEP_MAKEFILES}/ld_lib_path.csh

#
set gnustep_class_path="${GNUSTEP_USER_ROOT}/Libraries/Java:${GNUSTEP_LOCAL_ROOT}/Libraries/Java:${GNUSTEP_NETWORK_ROOT}/Libraries/Java:${GNUSTEP_SYSTEM_ROOT}/Libraries/Java"

if ( ! ${?CLASSPATH} ) then
  setenv CLASSPATH "${gnustep_class_path}"
else if ( { (echo "${CLASSPATH}" | fgrep -v "${gnustep_class_path}" >/dev/null) } ) then
  setenv CLASSPATH "${CLASSPATH}:${gnustep_class_path}"
endif

unset gnustep_class_path

#
# Perform any user initialization
#
if ( -e "$GNUSTEP_USER_ROOT/GNUstep.csh" ) then
  . "$GNUSTEP_USER_ROOT/GNUstep.csh"
endif

#
# Run 'make_services' in background if possible - updates cache of services
# and applications/file-extensions known to the applications.
#
if ( "${GNUSTEP_FLATTENED}" == "" ) then
  set TDIR=${GNUSTEP_SYSTEM_ROOT}/Tools/${GNUSTEP_HOST_CPU}/${GNUSTEP_HOST_OS}
  if ( -x $TDIR/$LIBRARY_COMBO/make_services ) then
    ($TDIR/$LIBRARY_COMBO/make_services &)
    if ( -x $TDIR/make_services ) then
      ($TDIR/make_services &)
    endif
  endif
else
  set TDIR=${GNUSTEP_SYSTEM_ROOT}/Tools
  if ( -x $TDIR/make_services ) then
    ($TDIR/make_services &)
  endif
endif

unset TDIR
