# init.csh
#
# to use the Fink hierarchy, put the following in your .cshrc:
#
#  source /sw/bin/init.csh
#

#
# Fink - a package manager that downloads source and installs it
# Copyright (c) 2001 Christoph Pfisterer
# Copyright (c) 2001-2004 The Fink Team
#
# This program 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#

# define append_path and prepend_path to add directory paths, e.g. PATH, MANPATH.
# add to end of path
alias append_path 'if ( $\!:1 !~ \!:2\:* && $\!:1 !~ *\:\!:2\:* && $\!:1 !~ *\:\!:2 && $\!:1 !~ \!:2 ) setenv \!:1 ${\!:1}\:\!:2'
# add to front of path
alias prepend_path 'if ( $\!:1 !~ \!:2\:* && $\!:1 !~ *\:\!:2\:* && $\!:1 !~ *\:\!:2 && $\!:1 !~ \!:2 ) setenv \!:1 \!:2\:${\!:1}; if ( $\!:1 !~ \!:2\:* ) setenv \!:1 \!:2`echo \:${\!:1} | /usr/bin/sed -e s%^\!:2\:%% -e s%:\!:2\:%:%g -e s%:\!:2\$%%`'

# setup fink related paths. we assume that the fink directories exists.
if ( $?PATH ) then
    prepend_path PATH /sw/bin:/sw/sbin
else
    setenv PATH /sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin
endif

set osMajorVersion = `uname -r | cut -d. -f1`
set osMinorVersion = `uname -r | cut -d. -f2`
if ( ! $?MANPATH ) then
  if ( $osMajorVersion > 7) then
    setenv MANPATH `/usr/bin/manpath`
  else
    setenv MANPATH `/usr/bin/manpath -q`
  endif
endif
prepend_path MANPATH /sw/share/man
set perlversion = `/usr/bin/perl -e 'printf("%vd\n", $^V)'`
append_path MANPATH /sw/lib/perl5/$perlversion/man

if ( $?INFOPATH ) then
  prepend_path INFOPATH /sw/share/info:/sw/info
else
  setenv INFOPATH /sw/share/info:/sw/info:/usr/share/info
endif

if ( -r /sw/share/java/classpath ) then
  if ( $?CLASSPATH ) then
    set add2classpath = `cat /sw/share/java/classpath`
    prepend_path CLASSPATH $add2classpath
  else
    setenv CLASSPATH `cat /sw/share/java/classpath`:.
  endif
endif

if ( $?PERL5LIB ) then
  prepend_path PERL5LIB /sw/lib/perl5:/sw/lib/perl5/darwin
else
  setenv PERL5LIB /sw/lib/perl5:/sw/lib/perl5/darwin
endif

# Add X11 paths (but only if the directories are readable)
if ( -r /usr/X11R6/bin ) then
    append_path PATH /usr/X11R6/bin
endif
if ( -r /usr/X11R6/man ) then
    append_path MANPATH /usr/X11R6/man
endif

# On Mac OS X 10.4.{x|x<3} there is a dyld bug (rdar://problem/4139432)
# where a library will not load if a library with a matching basename
# is already loaded from one of the system paths,
# the workaround is to set DYLD_FALLBACK_LIBRARY_PATH to :
if ( ! $?DYLD_FALLBACK_LIBRARY_PATH ) then
  if (  $osMajorVersion == 8 && $osMinorVersion < 3 ) then
    setenv DYLD_FALLBACK_LIBRARY_PATH :
  endif
endif

if ($?version) then
  if ("$version" =~ tcsh*) then
    complete fink 'n/fink/(install remove purge update selfupdate update-all configure list apropos describe index validate --help --version)/'
  endif
endif

set PROXYHTTP=`grep ProxyHTTP /sw/etc/fink.conf | grep -v "#" | cut -d " " -f2`

if ( "$PROXYHTTP" != "" ) then
  setenv HTTP_PROXY $PROXYHTTP
  setenv http_proxy $PROXYHTTP
endif

set PROXYFTP=`grep ProxyFTP /sw/etc/fink.conf | grep -v "#" | cut -d " " -f2`

if ( "$PROXYFTP" != "" ) then
  setenv FTP_PROXY $PROXYFTP
  setenv ftp_proxy $PROXYFTP
endif

# read per-package scripts from /sw/etc/profile.d
if ( -d /sw/etc/profile.d ) then
  set nonomatch
  foreach i ( /sw/etc/profile.d/*.csh )
    if ( -r $i && -x $i ) then
      source $i
    endif
  end
  unset i nonomatch
endif

# eof
