summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/context/stubs/setup/setuptex
blob: fb65788b61a979719591cdb673d7e3add770edbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Example setup file for ConTeXt distribution
#
# Author:  Hans Hagen
# Patches: Arthur R. & Mojca M.
#
# Usage:
#   . setuptex [texroot]
#
# On the first run also execute:
#   mktexlsr
#   texexec --make --alone

#
# PLATFORM
#

# we will try to guess the platform first
# (needs to be kept in sync with first-setup.sh and mtxrun)
# if yours is missing, let us know

system=`uname -s`
cpu=`uname -m`

case "$system" in
	# linux
	Linux)
		if command -v ldd >/dev/null && ldd --version 2>&1 | grep -E '^musl' >/dev/null
		then
			libc=musl
		else
			libc=glibc
		fi
		case "$cpu" in
			i*86)
				case "$libc" in
					glibc) platform="linux" ;;
					musl) platform="linuxmusl" ;;
				esac ;;
			x86_64|ia64)
				case "$libc" in
					glibc) platform="linux-64" ;;
					musl) platform="linuxmusl-64" ;;
				esac ;;

			# a little bit of cheating with ppc64 (won't work on Gentoo)
			ppc|ppc64) platform="linux-ppc" ;;

			# we currently support just mipsel, but Debian is lying (reports mips64)
			# we need more hacks to fix the situation, this is just a temporary solution
			mips|mips64|mipsel|mips64el) platform="linux-mipsel" ;;

			armv7l) platform="linux-armhf"
				# machine id output by uname(1) is insufficent to determine whether this
				# is a soft or hard float system so we check ourselves.
				# a) binutils, this should work almost everywhere
				if $(which readelf >/dev/null 2>&1); then
					readelf -A /proc/self/exe | grep -q '^ \+Tag_ABI_VFP_args'
					if [ ! $? ]; then
						platform="linux-armel"
					fi
				# b) debian-specific fallback
				elif $(which dpkg >/dev/null 2>&1); then
					if [ "$(dpkg --print-architecture)" = armel ]; then
						platform="linux-armel"
					fi
				fi
				# else go with hard fp
				;;

			*) platform="unknown" ;;
		esac ;;
	# Mac OS X
	Darwin)
		case "$cpu" in
			i*86) platform="osx-intel" ;;
			x86_64) platform="osx-64" ;;
			ppc*|powerpc|power*|Power*) platform="osx-ppc" ;;
			*) platform="unknown" ;;
		esac ;;
	# FreeBSD
	FreeBSD|freebsd)
		case "$cpu" in
			i*86) platform="freebsd" ;;
			x86_64) platform="freebsd" ;;
			amd64) platform="freebsd-amd64" ;;
			*) platform="unknown" ;;
		esac ;;
	# OpenBSD
	OpenBSD)
		case "$cpu" in
			i*86) platform="openbsd" ;;
			amd64) platform="openbsd-amd64" ;;
			*) platform="unknown" ;;
		esac ;;
	# kFreeBSD (Debian)
	GNU/kFreeBSD)
		case "$cpu" in
			i*86) platform="kfreebsd-i386" ;;
			x86_64|amd64) platform="kfreebsd-amd64" ;;
			*) platform="unknown" ;;
		esac ;;
	# MSYS2
	MSYS_NT-10.0)
		case "$cpu" in
			i*86) platform="win32" ;;
			x86_64) platform="win64" ;;
			*) platform="unknown" ;;
		esac ;;
	# cygwin
	CYGWIN)
		case "$cpu" in
			i*86) platform="cygwin" ;;
			x86_64|ia64) platform="cygwin-64" ;;
			*) platform="unknown" ;;
		esac ;;
	# SunOS/Solaris
	SunOS)
		case "$cpu" in
			sparc) platform="solaris-sparc" ;;
			i86pc) platform="solaris-intel" ;;
			*) platform="unknown" ;;
		esac ;;
	*) platform="unknown"
esac

# temporary fix for Snow Leopard
if test "$platform" = "osx-intel"; then
	# running Snow Leopard or later
	if test `uname -r|cut -f1 -d"."` -ge 10 ; then
		# working on 64-bit hardware
		if test `sysctl -n hw.cpu64bit_capable` = 1; then
			platform="osx-64"
		fi
	fi
fi

if test "$platform" = "unknown" ; then
	echo "Error: your system \"$system $cpu\" is not supported yet."
	echo "Please report to the ConTeXt mailing-list (ntg-context@ntg.nl)"
elif test "$platform" = "linux-ppc" ; then
	echo "Error: support for your system \"$platform\" has been dropped."
	echo "Please ask on to the ConTeXt mailing-list if you still need it (ntg-context@ntg.nl)"
fi

#
# PATH
#

# this resolves to path of the setuptex script
# We use $0 for determine the path to the script, except for:
# * bash where $0 always is bash; here we use BASH_SOURCE
# * ksh93 where we use ${.sh.file}
# Thanks to Vasile Gaburici and Alessandro Perucchi for reporting this
# * http://www.ntg.nl/pipermail/ntg-context/2008/033953.html
# * http://www.ntg.nl/pipermail/ntg-context/2012/068658.html
if [ z"$BASH_SOURCE" != z ]; then
	SCRIPTPATH="$BASH_SOURCE"
elif [ z"$KSH_VERSION" != z ]; then
   	SCRIPTPATH="${.sh.file}"
else
	SCRIPTPATH="$0"
fi

OWNPATH=$(cd -P -- "$(dirname -- "$SCRIPTPATH")" && pwd -P)

# but one can also call
# . setuptex path-to-tree

TEXROOT=""
# first check if any path has been provided in the argument, and try to use that one
if [ $# -ne 0 ] ; then
	# TODO: resolve any errors
	ARGPATH=$(cd -P -- "$(dirname -- "$1")" && pwd -P) && ARGPATH=$ARGPATH/$(basename -- "$1")
	if test -f "$ARGPATH/texmf/tex/plain/base/plain.tex" ; then
		if [ -d "$ARGPATH/texmf-$platform/bin" ]; then
			TEXROOT="$ARGPATH"
		else
			echo "Binaries for platform '$platform' are missing."
			echo "(There is no folder \"$ARGPATH/texmf-$platform/bin\")"
		fi
	else
		echo "The argument \"$ARGPATH\" is not a valid TEXROOT path."
		echo "(There is no file \"$ARGPATH/texmf/tex/plain/base/plain.tex\")"

		if [ -f "$OWNPATH/texmf/tex/plain/base/plain.tex" ]; then
			TEXROOT="$OWNPATH"
		fi
	fi
else
	if [ -f "$OWNPATH/texmf/tex/plain/base/plain.tex" ]; then
		if [ -d "$OWNPATH/texmf-$platform/bin" ]; then
			TEXROOT="$OWNPATH"
		else
			echo "Binaries for platform '$platform' are missing."
			echo "(There is no folder \"$OWNPATH/texmf-$platform/bin\")"
		fi
	else
		echo "\"$OWNPATH\" is not a valid TEXROOT path."
		echo "(There is no file \"$OWNPATH/texmf/tex/plain/base/plain.tex\")"
	fi
fi

if [ "$TEXROOT" != "" ]; then
	# for Alan Braslau's server :)
	if [ "x$PS1" != "x" ] ; then
		echo "Setting \"$TEXROOT\" as ConTeXt root."
	fi

# ConTeXt binaries have to be added to PATH
TEXMFOS=$TEXROOT/texmf-$platform
export PATH=$TEXMFOS/bin:$PATH

# unset variables that won't be used lately
unset platform cpu system OWNPATH SCRIPTPATH ARGPATH TEXMFOS

# not sure why this would be needed
# export CTXMINIMAL=yes

else
	echo "provide a proper tex root (like '. setuptex /something/tex')" ;
fi