getDefaultBinPaths.sh 3.19 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh

PATHFILE=./src/DefaultBinaryPaths.h

FOUNDTEX=0
BINPATHS=":"

8 9 10
if [ -x /usr/share/libtool/config.guess ]; then
	PLATFORM=`/usr/share/libtool/config.guess`
	ARCH=`echo $PLATFORM | sed 's/-.*//;s/i.86/i386/'`
11 12 13 14 15
# At least on Debian, Ubuntu, Gentoo and LFS, config.guess seems to be in a
# subdirectory
elif [ -x /usr/share/libtool/config/config.guess ]; then
	PLATFORM=`/usr/share/libtool/config/config.guess`
	ARCH=`echo $PLATFORM | sed 's/-.*//;s/i.86/i386/'`
16 17 18 19 20
else
	PLATFORM=`uname -s | tr A-Z a-z`
	ARCH=`uname -m | tr A-Z a-z | sed 's/i.86/i386/'`
fi

21 22 23 24
# append a path to $BINPATHS unless already present
appendPath()
{
	NEWPATH="$1"
25 26 27 28 29 30
	# Don't append common system directories here (they are added elsewhere)
	# to ensure that they are always at the end of the list
	if [ "$NEWPATH" = "/usr/bin" -o "$NEWPATH" = "/usr/local/bin" ]; then
		echo "$NEWPATH ignored"
		return
	fi
31 32 33 34 35 36 37
	case "$BINPATHS" in
		*:"$NEWPATH":*)	echo $NEWPATH already present;;
		*)				# note that BINPATHS already ends with colon
						BINPATHS="$BINPATHS$NEWPATH:";;
	esac
}

38
# (0) for Mac OS X, start with /Library/TeX/texbin (OSX 10.11 El Capitan) & /usr/texbin
39
case $PLATFORM in
40
	*darwin*)	appendPath "/Library/TeX/texbin"; appendPath "/usr/texbin";;
41 42
esac

43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
# (1) try to find tex and ghostscript

TEX=`which tex`
if [ "$TEX" != "" ]; then
	if [ -x "$TEX" ]; then
		appendPath `dirname "$TEX"`
		FOUNDTEX=1
	fi
fi

GS=`which gs`
if [ "$GS" != "" ]; then
	if [ -x "$GS" ]; then
		appendPath `dirname "$GS"`
	fi
fi

# (2) try to guess default TL path for the current system
# (no idea how much of this actually works....)

case $PLATFORM in
	*aix*)		OS=aix;;
	*cygwin*)	OS=cygwin;;
	*darwin*)	OS=darwin;;
	*freebsd*)	OS=freebsd;;
	*hpux*)		OS=hpux;;
	*irix*)		OS=irix;;
	*linux*)	OS=linux;;
	*netbsd*)	OS=netbsd;;
	*openbsd*)	OS=openbsd;;
	*solaris*)	OS=solaris;;
	*)			OS=`echo $PLATFORM | sed 's/.*-//'`
esac

77
appendPath "/usr/local/texlive/2018/bin/$ARCH-$OS"
78 79 80 81
appendPath "/usr/local/texlive/2017/bin/$ARCH-$OS"
appendPath "/usr/local/texlive/2016/bin/$ARCH-$OS"
appendPath "/usr/local/texlive/2015/bin/$ARCH-$OS"
appendPath "/usr/local/texlive/2014/bin/$ARCH-$OS"
82
appendPath "/usr/local/texlive/2013/bin/$ARCH-$OS"
83
appendPath "/usr/local/texlive/2012/bin/$ARCH-$OS"
84 85
appendPath "/usr/local/texlive/2011/bin/$ARCH-$OS"
appendPath "/usr/local/texlive/2010/bin/$ARCH-$OS"
86

87 88 89 90 91 92 93 94 95 96 97 98 99
for TEXLIVEROOT in /usr/local/texlive/* /opt/texlive/*; do
	# Check if this is really a folder (e.g., /opt/... might not exist)
	if [ -d "$TEXLIVEROOT/bin/$ARCH-$OS" ]; then
		# Check that this is of the form /texlive/1234
		if [ -z `basename $TEXLIVEROOT | sed 's/[0-9]//g'` ]; then
			# Paranoia: Make sure there actually is a bin/... subdirectory
			if [ -d "$TEXLIVEROOT/bin/$ARCH-$OS" ]; then
				appendPath "$TEXLIVEROOT/bin/$ARCH-$OS"
			fi
		fi
	fi
done

100 101
# (3) append default paths that we should always check

102
BINPATHS="$BINPATHS/usr/local/bin:/usr/bin"
103 104 105 106 107 108 109 110 111 112 113 114

# strip leading and trailing colons from the list
BINPATHS=`echo $BINPATHS | sed 's/^://;s/:$//'`

echo "// Default paths to TeX binaries, for TeXworks" > $PATHFILE
echo "// Generated by $0" >> $PATHFILE
echo "#define DEFAULT_BIN_PATHS \"$BINPATHS\"" >> $PATHFILE

echo "configuring default paths for TeX binaries as:"
echo "$BINPATHS"

exit $FOUNDTEX