#! /bin/csh
### ====================================================================
### Source this file to change the environment to use the TeXlive
### distribution of TeX.
###
### Usage:
###	source /opt/uumath/skel/SYS.texlive-2022.csh
###	source /usr/uumath/skel/SYS.texlive-2022.csh
###
### [18-Feb-2023] -- update for TeXLive 2023 release
### [05-Jan-2022] -- update for TeXLive 2022 release
### [06-Jan-2021] -- update for TeXLive 2021 release
### [23-Dec-2019] -- update for TeXLive 2020 release
### [07-Mar-2019] -- update for TeXLive 2019 release
### [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=2023

### Some TeX Live 2018 binaries cannot run on Red Hat 6 and CentOS 6,
### so fall back to previous year.
### [09-May-2019] no longer needed: test -f /etc/redhat-release && fgrep -q -s 'release 6' /etc/redhat-release && set TEXLIVEYEAR=2017

### 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/uumath/texlive/$TEXLIVEYEAR
test -d $TEXLIVE || set TEXLIVE=/usr/local/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-macosx1010
			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:
			switch ("`uname -r`")
			case 13.*):
				set BINDIR=amd64-freebsd130
				breaksw
			case 14.*):
				set BINDIR=amd64-freebsd140
				breaksw
			default:
				set BINDIR=amd64-freebsd
				breaksw
			endsw
			breaksw
		case arm64:
			set BINDIR=arm64-freebsd
			breaksw
		case i386:
			switch ("`uname -r`")
			case 8.2-RELEASE:
				set BINDIR=i386-freebsd8.2
				breaksw
			default:
				set BINDIR=i386-freebsd
				breaksw
			endsw
			breaksw
		case powerpc:
			set BINDIR=powerpc-freebsd
			breaksw
		case riscv:
			set BINDIR=riscv-freebsd
			breaksw
		endsw
		breaksw
	case GNU:
		set BINDIR=i386-gnu-hurd
		breaksw
	case GNU/kFreeBSD:
		set BINDIR=x86_64-kfreebsd7
		breaksw
	case IRIX64:
		set BINDIR=mips-irix
		breaksw
	case LibertyBSD:
		switch ("`uname -m`")
		case i386:
			set BINDIR=i386-libertybsd
			breaksw
		case amd64:
			set BINDIR=amd64-libertybsd
			breaksw
		endsw
		breaksw
	case Linux:
		switch ("`uname -m`")
		case aarch64:
			set BINDIR=aarch64-linux
			breaksw
		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-centos5
			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 m68k:
			set BINDIR=m68k-linux
			breaksw
		case ppc:
			set BINDIR=powerpc-linux
			breaksw
		case ppc64:
			set BINDIR=ppc64-linux
			breaksw
		case ppc64le:
			set BINDIR=ppc64le-linux
			breaksw
		case riscv64:
			set BINDIR=riscv64-fedora32
			breaksw
		case s390x:
			set BINDIR=s390x-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=sparc64-debian11
			breaksw
		case x86_64:
			## NB: The nondefault BINDIR values are our LOCAL ones, NOT from the TeX Live 2016 team!
			set relstr="`find /etc/*release* -prune ! -type d | xargs cat`"
			switch ("$relstr")
			case '*openSUSE Leap 15*':
				set BINDIR=x86_64-opensuse15
				breaksw
			case '*release 5*':
				set BINDIR=x86_64-centos5
				breaksw
			case '*release 6*':
				set BINDIR=x86_64-centos6
				breaksw
			case '*release 7*':
				set BINDIR=x86_64-centos7
				breaksw
			case '*release 8*':
				set BINDIR=x86_64-centos8
				breaksw
			case '*Ubuntu 20*':
				set BINDIR=x86_64-ubuntu2004
				breaksw
			case '*Ubuntu 22*':
				set BINDIR=x86_64-ubuntu2204
				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=amd64-netbsd
			breaksw
		endsw
		breaksw
	case OpenBSD:
		switch ("`uname -m`")
		case i386:
			set BINDIR=i386-openbsd
			breaksw
		case amd64:
			set BINDIR=amd64-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:
			# Use 64-bit version by default
			set BINDIR=no-such-directory
			test -d $TEXLIVE/bin/i386-solaris   && set BINDIR=i386-solaris
			test -d $TEXLIVE/bin/i386-solaris10 && set BINDIR=i386-solaris10
			test -d $TEXLIVE/bin/x86_64-solaris && set BINDIR=x86_64-solaris
			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-solaris10
			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

# documentation paths

if ( ${?INFOPATH} ) then
    setenv INFOPATH $TEXLIVE/texmf-dist/doc/info:$INFOPATH
else
    setenv INFOPATH $TEXLIVE/texmf-dist/doc/info:
endif

if ( ${?MANPATH} ) then
    setenv MANPATH $TEXLIVE/texmf-dist/doc/man:$MANPATH
else
    setenv MANPATH $TEXLIVE/texmf-dist/doc/man:
endif
