#!/bin/sh
# Run the squeak VM, setting SQUEAK_PLUGINS if unset to the VM's containing directory
# if unset, and ensuring LD_LIBRARY_PATH includes the VM's containing directory.
# This version hacked about by tim@rowledge.org for RaspberryPi
BIN=`/usr/bin/dirname $0`/../lib/squeak/5.0-3427
if [ "${SQUEAK_PLUGINS-unset}" = unset ]; then
	export SQUEAK_PLUGINS="$BIN"
fi
# At least on linux LD_LIBRARY_PATH's components must be absolute path names
case "$BIN" in
/*) PLUGINS="$BIN";;
*) PLUGINS="`pwd`/$BIN"
esac
# On some linuxes there multiple versions of the C library.  If the image uses
# libc (e.g. through the FFI) then it must use the same version that the VM uses
# and so it should take precedence over /lib libc.  This is done by setting
# LD_LIBRARY_PATH appropriately, based on ldd's idea of the libc use by the VM.
LIBC_SO="`/usr/bin/ldd "$BIN/squeak" | /bin/fgrep /libc. | sed 's/^.*=> \([^ ]*\).*/\1/'`"
case "$LIBC_SO" in
/lib/arm-linux-gnueabihf/libc*)	\
	SVMLLP="/lib/arm-linux-gnueabihf:/lib:/usr/lib/arm-linux-gnueabihf:/usr/lib";;
"")	case `/bin/uname -m || /usr/bin/uname -m` in
	*)	echo "/usr/bin/ldd didn't produce any output. Can't infer base LD_LIBRARY_PATH. Aborting." 1>&2
	esac
	exit 1;;
*)	echo "Can't infer base LD_LIBRARY_PATH. Aborting. Try adding a line for $LIBC_SO to $0. Please report your edit to squeak vm-dev." 1>&2
	exit 1
esac
# prepending is less flexible but safer because it ensures we find the plugins
# in the same directory as the VM.  We must include at least /lib and /usr/lib
# if libraries there-in are to be found.  These directories are not implicit.
echo execing: "$BIN/squeak" " -vm-sound-alsa " "$@"
LD_LIBRARY_PATH="$PLUGINS:$SVMLLP:${LD_LIBRARY_PATH}" exec "$BIN/squeak" "-vm-sound-alsa" "$@"
