#!/bin/sh

prefix="/usr/local"
exec_prefix="${prefix}"
datarootdir="${prefix}/share"
datadir="${datarootdir}"

if [ -z "$TEXMACS_PATH" ] ; then
  TEXMACS_PATH=${datarootdir}/TeXmacs
  export TEXMACS_PATH
  if [ -z "$TEXMACS_BIN_PATH" ] ; then
    TEXMACS_BIN_PATH=${exec_prefix}/libexec/TeXmacs
    export TEXMACS_BIN_PATH
  fi
else
  TEXMACS_BIN_PATH="$TEXMACS_PATH"
  export TEXMACS_BIN_PATH
fi

if [ -f "/usr/bin/cygwin1.dll" ] ; then
  # For coexistence with WinTeXmacs
  export TEXMACS_PATH=${datarootdir}/TeXmacs
  export TEXMACS_BIN_PATH=${exec_prefix}/libexec/TeXmacs
  unset GUILE_LOAD_PATH
  # For auxiliary file creation by subprograms like ps2pdf under cygwin
  export TEMP=/tmp
fi

DISTRIBUTOR_ID=`lsb_release -a 2>/dev/null |grep "Distributor ID"`
if [ ! "${DISTRIBUTOR_ID#*Ubuntu}" = "$DISTRIBUTOR_ID" ] ; then
  export QT_X11_NO_NATIVE_MENUBAR=1
fi

PATH="$TEXMACS_BIN_PATH/bin:$PATH"
LD_LIBRARY_PATH="$TEXMACS_BIN_PATH/lib${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}"
export PATH LD_LIBRARY_PATH

exec texmacs.bin "$@" < /dev/null
