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)

AC_CONFIG_HEADER(lib/c-auto.h)
dnl Don't complain when common.ac uses AC_CONFIG_HEADER.
define(AC_CONFIG_HEADER,)

sinclude(../kpathsea/common.ac)

AC_PROG_YACC
AC_PROG_LEX
AC_PROG_LN_S

AC_TYPE_SIGNAL

dnl These tests prevent reliable cross-compilation.  Sigh.
AC_C_CHAR_UNSIGNED
AC_LONG_64_BITS
AC_C_BIGENDIAN

dnl Must do this last, as the addition to DEFS in Autoconf 1.3 confuses
dnl the compiler.
AC_DECL_YYTEXT

dnl Check if lib/c-auto.h.in defines a preprocessor symbol.
define(AC_KBSYM_CHECK, AC_EGREP_CPP(yes,
[#include "$srcdir/lib/c-auto.h.in"
#ifdef $1
  yes
#endif
], $1=yes, $1=no))

AC_MSG_CHECKING(for sunwindow libraries)
AC_KBSYM_CHECK(SUNWIN)
AC_MSG_RESULT($SUNWIN)

AC_MSG_CHECKING(for xview libraries)
AC_KBSYM_CHECK(XVIEWWIN)
AC_MSG_RESULT($XVIEWWIN)

AC_MSG_CHECKING(for X11 libraries)
AC_KBSYM_CHECK(X11WIN)
AC_MSG_RESULT($X11WIN)

AC_MSG_CHECKING(for X10 libraries)
AC_KBSYM_CHECK(X10WIN)
AC_MSG_RESULT($X10WIN)

if test $XVIEWWIN = yes; then
  wlibs="-lxview -lolgx -lX11 $wlibs"
  (cd $srcdir/mf/MFwindow; rm -f sun.c; $LN_S sun-xview.c sun.c)
fi
if test $X11WIN = yes; then
  AC_PATH_X
  AC_PATH_XTRA
  wlibs="-lXt $X_PRE_LIBS -lX11 $wlibs"
  (cd $srcdir/mf/MFwindow; rm -f x11.c; $LN_S x11-Xt.c x11.c)
fi
if test $X10WIN = yes; then
  wlibs="-lX $wlibs"
fi
if test $SUNWIN = yes; then
  wlibs="-lsuntool -lsunwindow -lpixrect $wlibs"
  (cd $srcdir/mf/MFwindow; rm -f sun.c; $LN_S sun-sunview.c sun.c)
fi
AC_SUBST(wlibs)

dnl Do TeX first.
dnl If `small' version is not wanted, do nothing -- make will copy the
dnl default change file.
AC_MSG_CHECKING(for small TeX)
AC_KBSYM_CHECK(SMALLTeX)
AC_MSG_RESULT($SMALLTeX)
if test $SMALLTeX = yes; then
  (cd $srcdir/tex && rm -f ctex.ch && sed -f small.sed <tex.ch >ctex.ch)
  AC_DEFINE(GLUERATIO_TYPE, float)
fi

dnl Metafont next.
AC_MSG_CHECKING(for small MF)
AC_KBSYM_CHECK(SMALLMF)
AC_MSG_RESULT($SMALLMF)
if test $SMALLMF = yes; then
  (cd $srcdir/mf && rm -f cmf.ch && sed -f small.sed <mf.ch >cmf.ch)
fi

dnl MetaPost next.
AC_MSG_CHECKING(for small MP)
AC_KBSYM_CHECK(SMALLMP)
AC_MSG_RESULT($SMALLMP)
if test $SMALLMP = yes; then
  (cd $srcdir/mp && rm -f cmp.ch && sed -f small.sed <mp.ch >cmp.ch)
fi

dnl And finally BibTeX.
AC_MSG_CHECKING(for small BibTeX)
AC_KBSYM_CHECK(SMALLBibTeX)
AC_MSG_RESULT($SMALLBibTeX)
if test $SMALLBibTeX = yes; then
  (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 \
mp/Makefile mpware/Makefile tex/Makefile web/Makefile web2c/Makefile)
