#! /bin/csh
### ====================================================================
### Source this file to change the environment to use the TeXlive
### distribution of TeX.
###
### Usage:
###	source  /usr/local/skel/SYS.texlive-2018.csh
###	source /usr/uumath/skel/SYS.texlive-2018.csh
###
### [17-Jan-2018] -- update for TeXLive 2018 release
### [04-Feb-2017] -- update for TeXLive 2017 release
### [30-Mar-2016] -- update for TeXLive 2016 release
### [28-Mar-2015] -- update for TeXLive 2015 release
### [08-Apr-2014] -- update for TeXLive 2014 release
### [30-Mar-2013] -- update for TeXLive 2013 release
### [14-Apr-2012] -- update for TeXLive 2012 release
### [30-May-2011] -- update for TeXLive 2011 release
### [08-Oct-2010] -- update for TeXLive 2010 release
### [09-Jul-2009] -- update for TeXLive 2009 release
### [22-Aug-2008] -- update for TeXLive 2008 release
### [20-Aug-2008] -- update for sun4v architecture
### [01-Jul-2004] -- update with TEXMFDBS and extra TEXINPUTS directories
### [16-Mar-2004] -- update for TeXlive 9/2003
### [27-Aug-2003] -- update with TEXMFCNF setting
### [27-Jan-2003] -- update for TeXlive7
### [19-Jul-2001] -- update for TeXlive6
### [22-May-2001] -- update for TeXlive5d
### [04-Aug-1999]
### ====================================================================

unsetenv BIBINPUTS DVIPSHEADERS MFINPUTS TEXCONFIG TEXFONTS TEXFORMATS TEXINPUTS TEXPKS VFFONTS XDVIFONTS
unalias amslatex amstex latex latex209 latex2e pdflatex pdftex tex

set TEXLIVEYEAR=2018

### On some of our systems, /usr/local has been usurped by the package
### manager, so our local builds are in /usr/uumath.  We therefore
### check for both.
set TEXLIVE=/usr/local/texlive/$TEXLIVEYEAR
test -d $TEXLIVE || set TEXLIVE=/usr/uumath/texlive/$TEXLIVEYEAR
if ( ! -d $TEXLIVE ) then
    if ( $?prompt ) then
	echo ERROR: No TeX Live $TEXLIVEYEAR on this system
    endif
    exit 1
endif

switch ("`uname -s`")
	case AIX:
		set BINDIR=powerpc-aix
		breaksw
	case Darwin:
		switch ("`uname -m`")
		case Power*:
			set BINDIR=powerpc-darwin
			set BINDIR=universal-darwin
			breaksw
		case i386:
			set BINDIR=i386-darwin
			set BINDIR=universal-darwin
			breaksw
		case x86_64:
			## set BINDIR=x86_64-darwin
			## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			set BINDIR=x86_64-macosx-10.10
			breaksw
		default:
			echo No TeX Live $TEXLIVEYEAR for this system
			exit 1
		endsw
		breaksw
	case DragonFly:
		set BINDIR=x86_64-dragonfly
		breaksw
	case FreeBSD:
		switch ("`uname -m`")
		case amd64:
			set BINDIR=amd64-freebsd
			breaksw
		case i386:
			switch ("`uname -r`")
			case 8.2-RELEASE:
				set BINDIR=i386-freebsd8.2
				breaksw
			default:
				set BINDIR=i386-freebsd
				breaksw
			endsw
		endsw
		breaksw
	case GNU:
		set BINDIR=i386-gnu-hurd
		breaksw
	case GNU/kFreeBSD:
		set BINDIR=x86_64-kfreebsd-7
		breaksw
	case IRIX64:
		set BINDIR=mips-irix
		breaksw
	case LibertyBSD:
		switch ("`uname -m`")
		case i386:
			set BINDIR=i386-libertybsd
			breaksw
		case amd64:
			set BINDIR=x86_64-libertybsd
			breaksw
		endsw
		breaksw
	case Linux:
		switch ("`uname -m`")
		case alpha:
			set BINDIR=alpha-linux
			breaksw
		case armv7l:
			set BINDIR=armv7l-linux
			breaksw
		case i686:
			set BINDIR=i386-linux
			## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			set BINDIR=i386-linux-centos-5
			breaksw
		case ia64:		# use IA-32 binaries for now
			# set BINDIR=i386-linux
			# TeX Live 2015 has a native IA-64 build
			set BINDIR=ia64-linux
			breaksw
		case ppc:
			set BINDIR=powerpc-linux
			breaksw
		case ppc64:
			set BINDIR=ppc64-linux
			breaksw
		case ppc64le:
			set BINDIR=ppc64le-linux
			breaksw
		case sparc64:
			set BINDIR=sparc-linux
			## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			set BINDIR=sparc-linux-debian-7
			breaksw
		case x86_64:
			## NB: The nondefault BINDIR values are our LOCAL ones, NOT from the TeX Live 2016 team!
			switch ("`test -f /etc/redhat-release && cat /etc/redhat-release || test -f  /etc/centos-release && cat /etc/centos-release || /bin/true`")
			case '*release 5*':
				set BINDIR=x86_64-linux-centos-5
				breaksw
			case '*release 6*':
				set BINDIR=x86_64-linux-centos-6
				breaksw
			case '*release 7*':
				set BINDIR=x86_64-linux-centos-7
				breaksw
			default:
				set BINDIR=x86_64-linux
				breaksw
			endsw
			breaksw
		default:
			echo No TeX Live $TEXLIVEYEAR for this system
			exit 1
		endsw
		breaksw
	case MidnightBSD:
		switch ("`uname -m`")
		case amd64:
			set BINDIR=amd64-freebsd
			breaksw
		default:
			echo No TeX Live $TEXLIVEYEAR for this system
			exit 1
		endsw
		breaksw
	case NetBSD:
		switch ("`uname -m`")
		case i386:
			set BINDIR=i386-netbsd
			breaksw
		case amd64:
			set BINDIR=x86_64-netbsd-6
			breaksw
		endsw
		breaksw
	case OpenBSD:
		switch ("`uname -m`")
		case i386:
			set BINDIR=i386-openbsd
			breaksw
		case amd64:
			set BINDIR=x86_64-openbsd
			breaksw
		endsw
		breaksw
	case OSF1:
		set BINDIR=alphaev5-osf4.0d
		set path=(/usr/local/share/lib/tex/texlive7/bin/$BINDIR $path)
		breaksw
	case SunOS:
		switch ("`uname -m`")
		case i86pc:
			# set BINDIR=i386-solaris
			# Use 64-bit version by default
			set BINDIR=x86_64-solaris
			set BINDIR=i386-solaris
			## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			set BINDIR=i386-solaris-10
			breaksw
		case sun4[uv]:
			set BINDIR=sparc64-solaris
			set BINDIR=sparc-solaris
			## NB: This BINDIR value is our LOCAL one, NOT from the TeX Live 2016 team!
			set BINDIR=sparc-solaris-10
			breaksw
		default:
			echo No TeX Live $TEXLIVEYEAR for this system
			exit 1
		endsw
		breaksw
	default:
		echo No TeX Live $TEXLIVEYEAR for this system
		exit 1
endsw

if ( ! -e $TEXLIVE/bin/$BINDIR ) then
    if ( $?prompt ) then
	echo ========================================================================
	echo ERROR: the TeX Live $TEXLIVEYEAR binary directory for this platform
	echo
	echo $TEXLIVE/bin/$BINDIR
	echo
	echo does not exist.  This could be an error in this script, but could also
	echo arise if some binary directories have been omitted from your TeX Live
	echo $TEXLIVEYEAR installation.
	echo ========================================================================
    endif
    exit 1
endif

set path=($TEXLIVE/bin/$BINDIR $path)

# Ensure that texmf.cnf in current directory is found first
test ${?TEXMFCNF} -eq 1 && setenv TEXMFCNF .:$TEXMFCNF
test ${?TEXMFCNF} -eq 0 && setenv TEXMFCNF .:

# This is the path for ls-R files:
setenv TEXMFDBS	 .:$TEXLIVE/texmf-local:$TEXLIVE/texmf-extra:$TEXLIVE/texmf-var//:

# We have three directory trees where files can be found; two are
# small enough to allow recursive searches:
setenv TEXFONTS  .:$TEXLIVE/texmf-local//:$TEXLIVE/texmf-extra//:$TEXLIVE/texmf-var//:
setenv TEXINPUTS .:$TEXLIVE/texmf-local//:$TEXLIVE/texmf-extra//:

# gsftopk uses this environment variable to find *.pf[ab] files
setenv TEXPSHEADERS $TEXINPUTS
