dnl Process this file with Autoconf to produce a configure script for TeX.
dnl
dnl We don't use (for example) tex/tex.web because people who only want
dnl to build part of the distribution may not have any given program.
dnl Even web2c.c isn't guaranteed, but then nothing is ...
AC_INIT(web2c/web2c.c)

dnl Write output here, instead of putting -D's on the command line.
AC_CONFIG_HEADER(lib/c-auto.h)

dnl Do something erroneous if the symbol we are testing is undefined.
dnl
define(user_sym_check, [AC_TEST_CPP(#include "$srcdir/lib/c-auto.h.in"
#ifndef $1
#include <nonexistxyz.kkk>
#endif
, $1=t
)])

dnl We use the prefix to guess the location of the [f]lex library.
AC_PREFIX(tex)

dnl Use gcc if we have it.
AC_PROG_CC
AC_PROG_CPP
AC_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_YACC
AC_PROG_LEX
AC_LN_S

AC_AIX
AC_DYNIX_SEQ
AC_ISC_POSIX
AC_MINIX
AC_XENIX_DIR

AC_DIR_HEADER
AC_HEADER_CHECK(limits.h, :, AC_DEFINE(LIMITS_H_MISSING))
AC_HEADER_CHECK(float.h, :, AC_DEFINE(FLOAT_H_MISSING))
AC_STDC_HEADERS
AC_HAVE_HEADERS(string.h memory.h)
AC_UNISTD_H

AC_RETSIGTYPE

AC_CONST
dnl These tests prevent reliable cross-compilation.  Sigh.
AC_CHAR_UNSIGNED
AC_WORDS_BIGENDIAN

dnl Must do this last, as the thing that gets added to DEFS in Autoconf
dnl 1.3 confuses the compiler.
AC_DECLARE_YYTEXT

echo checking for window system libraries
user_sym_check(HP2627WIN)
user_sym_check(SUNWIN)
user_sym_check(TEKTRONIXWIN)
user_sym_check(UNITERMWIN)
user_sym_check(XVIEWWIN)
user_sym_check(X11WIN)
user_sym_check(X10WIN)
if test -n "$XVIEWWIN"; then
  wlibs="$wlibs -lxview -lolgx"
  (cd $srcdir/mf/MFwindow; rm -f sun.c; $LN_S sun-xview.c sun.c)
fi
if test -n "$X11WIN"; then
  AC_X11_LOCATION
  wlibs="$wlibs -lXt -lX11"
  (cd $srcdir/mf/MFwindow; rm -f x11.c; $LN_S x11-Xt.c x11.c)
fi
if test -n "$X10WIN"; then
  wlibs="$wlibs -lX"
fi
if test -n "$SUNWIN"; then
  wlibs="$wlibs -lsuntool -lsunwindow -lpixrect"
fi
AC_ISC_WLIBS

echo checking for small TeX/MF/BibTeX
# Do TeX first.
# If `small' version is not wanted, do nothing -- make will copy the
# default change file.
user_sym_check(SMALLTeX)
if test -n "$SMALLTeX"; then
  echo "(small TeX, creating tex/ctex.ch)"
  (cd $srcdir/tex && rm -f ctex.ch && sed -f small.sed < tex.ch > ctex.ch)
  AC_DEFINE(GLUERATIO_TYPE, float)
fi

# Metafont next.
user_sym_check(SMALLMF)
if test -n "$SMALLMF"; then
  echo "(small Metafont, creating mf/cmf.ch)"
  (cd $srcdir/mf && rm -f cmf.ch && sed -f small.sed < mf.ch > cmf.ch)
fi

# And finally BibTeX.
user_sym_check(SMALLBibTeX)
if test -n "$SMALLBibTeX"; then
  echo "(small BibTeX, creating bibtex/cbibtex.ch)"
  (cd $srcdir/bibtex \
   && rm -f cbibtex.ch && sed -f small.sed < bibtex.ch > cbibtex.ch)
fi

dnl Generate `Makefile's, `config.status', and our header file.
AC_OUTPUT(Makefile bibtex/Makefile dviutil/Makefile fontutil/Makefile \
lib/Makefile man/Makefile mf/Makefile mf/MFwindow/Makefile \
tex/Makefile web/Makefile web2c/Makefile)
