:
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically by autoconf.
# Copyright (C) 1991 Free Software Foundation, Inc.

# 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.

for arg in $*; do
  # Handle --srcdir with a space before the argument.
  if test x$next_srcdir = xyes; then srcdir=$arg; next_srcdir=
  # Handle --host with a space before the argument.
  elif test 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

INCLUDEDIR=${INCLUDEDIR-/usr/include}

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

# 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=tex/tex.web

# Makefile rules whose targets are searched for in VPATH need to use $<.
# However, old makes do not support it, so we use a combination
# construction in Makefile.in: `$file<'.
# If srcdir is `.', we use sed to change that to `file' for old makes.
# Otherwise, we use sed to change it to `$<'.
# vpsub is the sed program, which changes `$file<' to one or the other.
vpsub='s,\$\([-./a-zA-Z0-9_]*\)<,\1,g'
# srsub changes `@srcdir@' in Makefile.in into either `.' or the path
# of the top of the source tree for the package.
srsub='s,@srcdir@[-./a-zA_Z0-9_]*,.,'

# Find the source files, if location was not specified.
if test x$srcdir = x; then
  srcdirdefaulted=yes; srcdir=.
  if test ! -r $unique_file; then srcdir=..; fi
fi
if test ! -r $srcdir/$unique_file; then
  if test x$srcdirdefaulted = xyes; then
    echo "configure: Can not find sources in \`.' or \`..'." 1>&2
  else
    echo "configure: Can not find sources in \`${srcdir}'." 1>&2
  fi
  exit 1
fi
if test $srcdir != .; then
  VPATH='VPATH = $(srcdir)'
  case $srcdir in
    /*|~*) ;;
    *) srcdir=`pwd`/$srcdir ;; # Make relative path absolute.
  esac
  vpsub='s,\$\([-./a-zA-Z0-9_]*\)<,\$<,g'
  srsub="s,@srcdir@,$srcdir,"
fi


# The Bourne shell writes "command not found" to /dev/tty, so if we get
# a usage message on stderr, we have the program.
#
# ksh and zsh write "command not found" to stderr, but test -n does not
# want any output if there is no program.  So we use the `type' builtin
# instead for them (and bash).
if test "$RANDOM" = "$RANDOM"; then
  checkfor='test -n "`$checkprog $checkargs 2>&1`"'
else
  checkfor='type $checkprog >/dev/null'
fi



compile='rm -f conftest.h conftest.x;
  echo "$DEFS" > conftest.h;
  cat conftest.h conftest.c > conftest.x;
  rm -f conftest.c conftest.h;
  mv conftest.x conftest.c;
  $CC conftest.c -o conftest $LIBS >/dev/null 2>&1'


# Make sure they've decided on their preferences.
sitedir=$srcdir/lib
siteh=$sitedir/site.h
if test ! -r $siteh
then
  echo "Please copy $sitedir/site.h-dist to $siteh, and edit it."
  echo "Then run configure again."
  exit 1
fi

echo checking for directory prefix using tex
if test -z "$prefix"
then
  # Guess /usr/local if they haven't set it.
  prefix=/usr/local
  saveifs="$IFS"
  IFS="$IFS:"
  for dir in $PATH
  do
    test -z "$dir" && dir=.
    if test $dir != . -a -f $dir/tex
    then
      # Do all systems have dirname?
      prefix=`dirname $dir`
      break
    fi
  done
  IFS="$saveifs"
fi



echo checking for gcc
checkprog=gcc checkargs=''
test -z "$CC" && eval $checkfor && CC='gcc -g'
CC=${CC-cc}

echo checking for install
# Make sure to not get the incompatible SysV /etc/install.
if test -z "$INSTALL" || test -z "$INSTALL_PROGRAM" || test -z "$INSTALL_DATA"
then
  saveifs="$IFS"; IFS="$IFS:"
  for dir in $PATH; do
    test -z "$dir" && dir=.
    if test $dir != /etc && test -f $dir/install; then
      test -z "$INSTALL" && INSTALL="$dir/install -c"
      test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM="$dir/install -c"
      test -z "$INSTALL_DATA" && INSTALL_DATA="$dir/install -c -m 644"
      break
    fi
  done
  IFS="$saveifs"
fi
INSTALL=${INSTALL-cp}
INSTALL_PROGRAM=${INSTALL_PROGRAM-cp}
INSTALL_DATA=${INSTALL_DATA-cp}

echo checking for ranlib
checkprog=ranlib checkargs='/dev/null'
test -z "$RANLIB" && eval $checkfor && RANLIB='ranlib '
RANLIB=${RANLIB-true}

echo checking for bison
checkprog=bison checkargs=''
test -z "$YACC" && eval $checkfor && YACC='bison -y'
YACC=${YACC-yacc}

echo checking for flex
checkprog=flex checkargs='conftest'
test -z "$LEX" && eval $checkfor && LEX='flex '
LEX=${LEX-lex}

if test -z "$LEXLIB"
then
  # The extra space comes from the empty arg list.
  if test "$LEX" = "flex "
  then
    if test -r $prefix/lib/libfl.a
    then LEXLIB=$prefix/lib/libfl.a
    elif test -r /usr/local/lib/libfl.a
    then LEXLIB=/usr/local/lib/libfl.a
    elif test -r /usr/local/gnu/lib/libfl.a
    then LEXLIB=/usr/local/gnu/libfl.a
    elif test -r /usr/gnu/lib/libfl.a
    then LEXLIB=/usr/gnu/lib/libfl.a
    else LEXLIB="-lfl"
    fi
  else LEXLIB="-ll"
  fi
fi
echo checking for ln -s
if ln -s X ShouldNotExist 2>/dev/null
then
  rm -f ShouldNotExist
  LN="ln -s"
else
  LN=ln
fi



echo checking for POSIXized ISC
if test -d /etc/conf/kconfig.d &&
  grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1
then
  isc=t
  case "$CC" in
  gcc*) CC="$CC -posix" ;;
  *) CC="$CC -Xp" ;;
  esac
fi


echo checking for directory library header
dirheader=sys/dir.h
if test -f $INCLUDEDIR/dirent.h; then
  DEFS="${DEFS}#ifndef DIRENT
#define DIRENT 
#endif
" dirheader=dirent.h
elif test -f $INCLUDEDIR/sys/ndir.h; then
  DEFS="${DEFS}#ifndef SYSNDIR
#define SYSNDIR 
#endif
" dirheader=sys/ndir.h
fi
echo checking for "void.*closedir" in "$dirheader"
grep 'void.*closedir' $INCLUDEDIR/$dirheader >/dev/null 2>&1 && DEFS="${DEFS}#ifndef VOID_CLOSEDIR
#define VOID_CLOSEDIR 
#endif
"

echo checking for float.h
test -f $INCLUDEDIR/float.h || DEFS="${DEFS}#ifndef FLOAT_H_MISSING
#define FLOAT_H_MISSING 
#endif
"

echo checking for limits.h
test -f $INCLUDEDIR/limits.h || DEFS="${DEFS}#ifndef LIMITS_H_MISSING
#define LIMITS_H_MISSING 
#endif
"

echo checking for memcpy in memory.h only
if grep -s memcpy $INCLUDEDIR/string.h
then :
elif test -r $INCLUDEDIR/memory.h
then DEFS="${DEFS}#ifndef NEED_MEMORY_H
#define NEED_MEMORY_H 
#endif
"
fi

echo checking for ANSI C header files
test -r $INCLUDEDIR/stdlib.h && test -r $INCLUDEDIR/string.h &&
  test -r $INCLUDEDIR/limits.h && DEFS="${DEFS}#ifndef STDC_HEADERS
#define STDC_HEADERS 
#endif
"

echo checking for unistd.h
test -f $INCLUDEDIR/unistd.h && DEFS="${DEFS}#ifndef HAVE_UNISTD_H
#define HAVE_UNISTD_H 
#endif
"

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

echo checking for unsigned characters
echo '
#if !__STDC__
#define volatile
#endif
main() { volatile char c = 255; exit(c < 0); }' > conftest.c
eval $compile
if test -s conftest && ./conftest 2>/dev/null; then
  DEFS="${DEFS}#ifndef __CHAR_UNSIGNED__
#define __CHAR_UNSIGNED__ 
#endif
"
fi
rm -f conftest conftest.c


echo checking for signal handler type
pattern='void[ 	]*(\*signal.*('
if grep "$pattern" $INCLUDEDIR/signal.h >/dev/null 2>&1 ||
  grep "$pattern" $INCLUDEDIR/sys/signal.h >/dev/null 2>&1; then :
else DEFS="${DEFS}#ifndef SIGTYPE
#define SIGTYPE int
#endif
"
fi


# We need CPP for YYTEXT_DECL.
if test -z "$CPP"
then CPP="$CC -E"
fi
echo checking for yytext declaration
# Since we have lex now, figure out what yytext is by creating a minimal
# parser and examining the (preprocessed, in case macros are used)
# output.  Why oh why didn't Lesk just make lex output a header file?
if test -z "$DECLARE_YYTEXT"
then
  echo "%%" | $LEX
  DECLARE_YYTEXT=`$CPP lex.yy.c \
    | sed -n '/extern.*yytext/s/^.*extern/extern/p'`
  rm -f lex.yy.c
fi
DEFS="${DEFS}#ifndef DECLARE_YYTEXT
#define DECLARE_YYTEXT "$DECLARE_YYTEXT"
#endif
"

echo checking endianness
echo 'main ()
{
  /* Are we little or big endians?  From Harbison&Steele.  */
  union
  {
    long l;
    char c[sizeof (long)];
  } u;
  u.l = 1;
  exit (u.c[0] != 0);
}' > conftest.c
eval $compile
if test -s conftest && ./conftest 2>/dev/null; then :
else DEFS="${DEFS}#ifndef WORDS_BIGENDIAN
#define WORDS_BIGENDIAN 
#endif
"
fi
rm -f conftest conftest.c


echo checking for window system libraries
# Figure out window system libraries by inspecting site.h.
if grep -s define.*SUNWIN $siteh
then wlibs="$wlibs -lsuntool -lsunwindow -lpixrect"
fi
if grep -s define.*X11WIN $siteh
then wlibs="$wlibs -lXt -lX11"
elif grep define.*X10WIN $siteh
then wlibs="$wlibs -lX"
fi
echo checking for ISC X window libraries
if test -n "$isc"
then
  wlibs="$wlibs -lnsl_s -linet"
fi

echo checking for X11 headers and libraries
# We only need to rerun the preprocessor, so don't bother with $compile.
echo "#include <X11/Xaw/Box.h>" > conftest.c
if $CC -E conftest.c >/dev/null 2>&1
then :
else
  dir=""
  if test -r /usr/local/include/X11/Xaw/Box.h
  then dir=/usr/local/include
  elif test -r /usr/lpp/X11/Xamples/include/Box.h
  then dir=/usr/lpp/X11/Xamples/include
  elif test -r /usr/X11/include/X11/Xaw/Box.h
  then dir=/usr/X11/include
  fi
  test -n "$dir" && xincludedir=-I$dir
  
fi
rm -f conftest.c
# Now check for the libraries.
dir1=""
if test -r /usr/local/lib/libXaw.a
then dir1=/usr/local/lib
elif test -r /usr/X11/lib/libXaw.a
then dir1=/usr/X11/lib
elif test -r /usr/lpp/X11/Xamples/lib/Xaw/libXaw.a
then dir1=/usr/lpp/X11/Xamples/lib/Xaw
fi
dir2=""
if test -r /usr/lpp/X11/Xamples/lib/Xmu/libXmu.a
then dir2=/usr/lpp/X11/Xamples/lib/Xmu
fi
test -n "$dir1" && xlibdir=-L$dir1
test -n "$dir2" && xlibdir="$xlibdir -L$dir2"



echo setting up TeX/MF/BibTeX change files
(cd tex; rm -f ctex.ch; cp tex.ch ctex.ch)
if test -n "`grep '#define.*SMALLTeX' $siteh`"
then
  (cd tex; patch ctex.ch small.diff)
  DEFS="${DEFS}#ifndef GLUERATIO_TYPE
#define GLUERATIO_TYPE float
#endif
"
fi
# Similarly for Metafont.
(cd mf; rm -f cmf.ch; cp mf.ch cmf.ch)
if test -n "`grep '#define.*SMALLMF' $siteh`"
then (cd mf; patch cmf.ch small.diff)
fi
# And similarly for BibTeX.
(cd bibtex; rm -f cbibtex.ch; cp bibtex.ch cbibtex.ch)
if test -n "`grep '#define.*SMALLBibTeX' $siteh`"
then (cd bibtex; patch cbibtex.ch small.diff)
fi


trap 'for dir in .; do rm -f $dir/Makefile; done; rm -f config.status lib/c-auto.h; exit 1' 1 3 15

for dir in .; do
  test -d $dir || mkdir $dir
  echo creating $dir/Makefile
  echo '# Generated automatically from Makefile.in by configure.' > $dir/Makefile
  sed -e "
$vpsub
$srsub
s,@VPATH@,$VPATH,
s,@DEFS@,`echo $DEFS`,
s,@LIBS@,`echo $LIBS`,
s,@prefix@,`echo $prefix`,
s,@CC@,`echo $CC`,
s,@INSTALL@,`echo $INSTALL`,
s,@INSTALL_PROGRAM@,`echo $INSTALL_PROGRAM`,
s,@INSTALL_DATA@,`echo $INSTALL_DATA`,
s,@RANLIB@,`echo $RANLIB`,
s,@YACC@,`echo $YACC`,
s,@LEX@,`echo $LEX`,
s,@LEXLIB@,`echo $LEXLIB`,
s,@LN@,`echo $LN`,
s,@wlibs@,`echo $wlibs`,
s,@LDFLAGS@,`echo $LDFLAGS`,
s,@xincludedir@,`echo $xincludedir`,
s,@xlibdir@,`echo $xlibdir`,
" $srcdir/$dir/Makefile.in >> $dir/Makefile
done

echo creating lib/c-auto.h
echo "/* lib/c-auto.h: generated by configure.  */
$DEFS" > lib/c-auto.h

echo creating config.status
echo "\
DEFS=\"$DEFS\"
LIBS=\"$LIBS\"
prefix=\"$prefix\"
CC=\"$CC\"
INSTALL=\"$INSTALL\"
INSTALL_PROGRAM=\"$INSTALL_PROGRAM\"
INSTALL_DATA=\"$INSTALL_DATA\"
RANLIB=\"$RANLIB\"
YACC=\"$YACC\"
LEX=\"$LEX\"
LEXLIB=\"$LEXLIB\"
LN=\"$LN\"
wlibs=\"$wlibs\"
LDFLAGS=\"$LDFLAGS\"
xincludedir=\"$xincludedir\"
xlibdir=\"$xlibdir\"
" > config.status
