#!/bin/sh
# MakeTeXcommon -- common MakeTeX* options, etc.
# Meant to be sourced after $usage and $version and $TEXMF have been set.
# 
# te@informatik.uni-hannover.de and kb@mail.tug.org. Public domain.
# $Id: MakeTeXcommon,v 1.7 1997/02/08 15:53:56 karl Exp karl $
 
if test x$1 = x--help -o x$1 = x-help; then
  echo "$usage"
  exit 0
elif test x$1 = x--version -o x$1 = x-version; then
  echo "`basename $0` $version"
  kpsewhich --version
  exit 0
elif test $# -lt ${mt_min_args-1}; then
  echo "$0: Missing argument(s)." >&2
  echo "Try \``basename $0` --help' for more information." >&2
  exit 1
elif test $# -gt ${mt_max_args-1}; then
  while test $# -gt ${mt_max_args-1}; do shift; done
  echo "$0: Extra arguments $*." >&2
  echo "Try \``basename $0` --help' for more information." >&2
  exit 1
fi

# TEMPDIR needs to be unique to each process because of the possibility of two
# people running dvips (or whatever) simultaneously.
TEMPDIR=${TMPDIR-/tmp}/mt.$$

# We want to output only filenames to standard output, but it's too
# error-prone to write the scripts that way, so we direct stdout here.
STDOUT=$TEMPDIR/stdout.$$

# We will change search paths to include $KPSE_DOT. This is necessary
# since we cd to $TEMPDIR.
: ${KPSE_DOT=`pwd`}; export KPSE_DOT

# Clean up on normal or abnormal exit.
trap 'cd $KPSE_DOT; test -f $STDOUT && cat $STDOUT; rm -rf $TEMPDIR; exit 0' \
  0 1 2 15

mkdir $TEMPDIR
cd $TEMPDIR || exit 1

# The texmf tree where we put generated files into. Defaults to system tree:
: ${VARTEXMF=`kpsewhich -expand-var='$VARTEXMF'`}
test -n "$VARTEXMF" || VARTEXMF=$TEXMFMAIN

# The directory where we search for private scripts and config files.
# Defaults to $VARTEXMF/web2c.
: ${TEXMFCNF_DIR=`kpsewhich -expand-var='$TEXMFCNF_DIR'`}
test -n "$TEXMFCNF_DIR" || TEXMFCNF_DIR=$VARTEXMF/web2c

# Get some configuration variables:
. $TEXMFMAIN/web2c/MakeTeX.cnf

# Allow fonts to be read and written (especially in case we make
# directories) by everyone.  
umask 0

# MakeTeXupdate and MakeTeXls-R make sure they're coordinated via this.
ls_R_magic='% ls-R -- maintained by MakeTeXls-R; do not change this line.'
