:
# Guess values for system-dependant variables and create `Makefile'.
# Copyright (C) 1991 Free Software Foundation, Inc.
# Viscously hacked my mike@apl.ists.ca

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# Usage: configure [+srcdir=DIR] [+host=HOST] [+gas] [+nfp] [TARGET]
# All args except +srcdir=DIR are ignored.

trap 'rm -f conftest conftest.c; exit 1' 1 3 15

set +u # Make sure unset variables are ok.

# Make sure we don't find the System V /etc/install.
PATH=`echo $PATH|sed '
s,^/etc:,,
s,:/etc$,,
s,:/etc:,:,g'`

# A filename unique to this package, relative to the directory that
# configure is in, which we can look for to find out if srcdir is correct.
unique_file=.latexinfo

for arg in $*; do
  # Handle +srcdir with a space before the argument.
  if [ x$next_srcdir = xyes ]; then srcdir=$arg; next_srcdir=
  # Handle +host with a space before the argument.
  elif [ x$next_host = xyes ]; then next_host=
  else 
    case $arg in
     -srcdir=* | +srcdir=* | +srcdi=* | +srcd=* | +src=* | +sr=* | +s=*)
	srcdir=`echo $arg | sed 's/[+-]s[a-z]*=//'` ;;
     -srcdir | +srcdir | +srcdi | +srcd | +src | +sr | +s)
	next_srcdir=yes ;;
     -host=* | +host=* | +hos=* | +ho=* | +h=*) ;;
     -host | +host | +hos | +ho | +h)
	next_host=yes ;;
     -gas | +gas | +ga | +g) ;;
     -nfp | +nfp | +nf | +n) ;;
     *) ;;
    esac
  fi
done

vpsub='s@\$\([-./a-zA-Z0-9]*\)<@\1@g'
# Find the source files, if location was not specified.
if [ x$srcdir = x ]; then
  srcdirdefaulted=yes; srcdir=.
  if [ ! -r $unique_file ]; then srcdir=..; fi
fi
if [ $srcdir != . ]; then
  VPATH='VPATH = $(srcdir)'
  vpsub='s@\$\([-./a-zA-Z0-9]*\)<@\$<@g'
fi

if [ ! -r $srcdir/$unique_file ]; then
  if [ x$srcdirdefaulted = xyes ]; then
    echo "$0: Can not find sources in \`.' or \`..'." 1>&2
  else
    echo "$0: Can not find sources in \`${srcdir}'." 1>&2
  fi
  exit 1
fi

if test "$RANDOM" = "$RANDOM"; then
  # Plain old Bourne shell.
  echo checking for gcc
  test -z "$CC" -a -n "`gcc 2>&1`" && CC="gcc -O"

  echo checking for install
  if test -z "$INSTALL" -a -n "`install 2>&1`"; then
    INSTALL="install -c -m 755"
    INSTALLDATA="install -c -m 644"
  fi
else
  # ksh, bash or zsh.  ksh and zsh write "command not found" to stderr.
  echo checking for gcc
  test -z "$CC" && type gcc && CC="gcc -O"

  echo checking for install
  if test -z "$INSTALL" && type install; then
    INSTALL="install -c -m 755"
    INSTALLDATA="install -c -m 644"
  fi
fi

echo "Where would you like to install the binaries?"
echo ""
peachy="n"
while [ "$peachy" = n ]; do
echo "  Please type the full path to your binaries directory:"
echo -n "  >"
read FOUNDPATH
        if [ -d $FOUNDPATH ]; then
            echo ""
            echo "  The binaries path was verfied to be [$FOUNDPATH]"
            echo ""
            peachy="y"
        else
            echo ""
            echo "  Verification of [$FOUNDPATH] failed. Please try again."
            echo ""
        fi
    done #peachy
BINDIR=${FOUNDPATH-/usr/local/bin}

echo "Where are the Gnu Info files located?"
echo ""
peachy="n"
while [ "$peachy" = n ]; do
echo "  Please type the full path to your info directory:"
echo -n "  >"
read FOUNDPATH
        if [ -d $FOUNDPATH ]; then
            echo ""
            echo "  The Info directory was verfied to be [$FOUNDPATH]"
            echo ""
            peachy="y"
        else
            echo ""
            echo "  Verification of [$FOUNDPATH] failed. Please try again."
            echo ""
        fi
    done #peachy
INFODIR=${FOUNDPATH-/usr/local/info}

echo "Where is your GNU Emacs command:"
echo ""
echo "  Please type the name of your GNU Emacs command:"
echo -n "  >"
read FOUND
EMACS="$FOUND"
EMACS=${EMACS-/usr/local/man/man1}

CC=${CC-cc}
INSTALL=${INSTALL-cp}
INSTALLDATA=${INSTALLDATA-cp}
INCLUDEDIR=${INCLUDEDIR-/usr/include}

if test -z "$PWD" ; then
   PWD=`pwd`
fi
rm -f .login .emacs
cat << 'EOF'

Would you like to install the elisp and LaTeX files elsewhere,
or leave them here, and set an environment variable to point to here?

EOF
echo -n 'Set an environment variable to point to here [y/n]? '
read HERE
if [ "$HERE" = "y" ] ; then
	cat >.emacs << 'EOF'
;; Modify the following line to be the name of this file, and
;; put it in your ~/.emacs (without the semi-colons).
;; (load-file "/usr2/ai/nesc/.emacs")

;;; LaTeXinfo

(setq load-path 
      (cons (setq latexinfo-formats-directory
		  (expand-file-name (concat (getenv "LATEXINFO") "/elisp")))
	    load-path))

EOF
    cat .latexinfo >> .emacs
    cat >.login << EOF
#!/bin/csh

# LaTeXinfo
setenv LATEXINFO $PWD
EOF
	cat >>.login << 'EOF'

# Add the format files to the list of directories that LaTeX searches.
if ( $?TEXINPUTS ) then
	setenv TEXINPUTS "$TEXINPUTS"':'"$LATEXINFO/styles"
else
	setenv TEXINPUTS ".:$LATEXINFO/styles"
endif
EOF

else
   echo ""
   echo "Where would you like to install GNU Emacs code (elisp)?"
   echo ""
   peachy="n"
   while [ "$peachy" = n ]; do
   echo "  Please type the full path to your elisp directory:"
   echo -n "  >"
   read FOUNDPATH
           if [ -d $FOUNDPATH ]; then
               echo ""
               echo "  The elisp path was verfied to be [$FOUNDPATH]"
               echo ""
               peachy="y"
           else
               echo ""
               echo "  Verification of [$FOUNDPATH] failed. Please try again."
               echo ""
           fi
       done #peachy
   ELISPDIR=${FOUNDPATH-/usr/local/emacs/lisp}
   
   echo "Where would you like to install the LaTeX style files?"
   echo ""
   peachy="n"
   while [ "$peachy" = n ]; do
   echo "  Please type the full path to your LaTeX style directory:"
   echo -n "  >"
   read FOUNDPATH
           if [ -d $FOUNDPATH ]; then
               echo ""
               echo "  The  LaTeX style path was verfied to be [$FOUNDPATH]"
               echo ""
               peachy="y"
           else
               echo ""
               echo "  Verification of [$FOUNDPATH] failed. Please try again."
               echo ""
           fi
       done #peachy
   TEXDIR=${FOUNDPATH-/usr/local/tex/inputs}

   cat >.emacs << EOF
;; Modify the following line to be the name of this file, and
;; put it in your ~/.emacs (without the semi-colons).
;; (load-file "/usr2/ai/nesc/.emacs")

;;; LaTeXinfo
(setq load-path 
      (cons (setq latexinfo-formats-directory
		  (expand-file-name "$ELISPDIR"))
	    load-path))

EOF
    cat .latexinfo >> .emacs
	cat >>.login << EOF

# Add the format files to the list of directories that LaTeX searches.
if ( \$?TEXINPUTS ) then
	setenv TEXINPUTS "\$TEXINPUTS"':'"$TEXDIR"
else
	setenv TEXINPUTS ".:$TEXDIR"
endif
EOF

fi

# Set LATEXINFO for the install
LATEXINFO=$PWD

rm -f conftest conftest.c
compile="$CC $DEFS conftest.c -o conftest $LIBS >/dev/null 2>&1"

# Check for various header files.

echo checking for ANSI C header files
echo "#include <stdlib.h>
#include <string.h>
main () { exit(0); strerror(0); }" > conftest.c
eval $compile
if test -s conftest && ./conftest 2>/dev/null; then
  DEFS="$DEFS -DSTDC_HEADERS"
fi
rm -f conftest conftest.c

echo checking for BSD string and memory functions
echo "#include <strings.h>
main () { exit(0); rindex(0, 0); bzero(0, 0); }" > conftest.c
eval $compile
if test -s conftest && ./conftest 2>/dev/null; then :
  else DEFS="$DEFS -DUSG"
fi
rm -f conftest conftest.c

# Check other misc. things.

echo checking how to get alloca
echo '
#ifdef __GNUC__
#define alloca __builtin_alloca
#else
#ifdef sparc
#include <alloca.h>
#else
#ifdef _AIX
 #pragma alloca
#else
char *alloca ();
#endif
#endif
#endif
main() { char *p = (char *) alloca(1); exit(0); }' > conftest.c
eval $compile
if test -s conftest && ./conftest 2>/dev/null; then :
else
  rm -f conftest conftest.c
  echo 'char *alloca();
main() { char *p = alloca(1); exit(0); }' > conftest.c
  eval $compile -lPW
  if test -s conftest && ./conftest 2>/dev/null; then LIBS="$LIBS -lPW"
  elif test -d /usr/ucblib; then LIBS="$LIBS -L/usr/ucblib -lucb"
  else ALLOCA=alloca.o
  fi
fi
rm -f conftest conftest.c

trap "rm -f config.status $srcdir/C/Makefile; exit 1" 1 3 15

echo "CC=$CC
INSTALL=$INSTALL
INSTALLDATA=$INSTALLDATA
DEFS=$DEFS
LIBS=$LIBS
BINDIR=$BINDIR
INFODIR=$INFODIR
ELISPDIR=$ELISPDIR
TEXDIR=$TEXDIR
EMACS=$EMACS
LATEXINFO=$PWD
ALLOCA=$ALLOCA" > config.status
echo '# Generated automatically from Makefile.in by configure.' > $srcdir/C/Makefile
sed -e "
$vpsub
s,@srcdir@,$srcdir,
s,@VPATH@,$VPATH,
s,@CC@,$CC,
s,@INSTALL@,$INSTALL,
s,@INSTALLDATA@,$INSTALLDATA,
s,@DEFS@,$DEFS,
s,@LIBS@,$LIBS,
s,@BINDIR@,$BINDIR,
s,@MANDIR@,$MANDIR,
s,@INFODIR@,$INFODIR,
s,@ALLOCA@,$ALLOCA,
" $srcdir/C/Makefile.in >> $srcdir/C/Makefile

if [ "$HERE" = "y" ] ; then
	echo "Now type make"
else
	echo "Now type make, then"
	echo "         make install"
fi