dnl Process this file with autoconf to produce a configure script.
AC_INIT(dialog.c)

AC_CONFIG_AUX_DIR(../texk)

AC_PROG_CC
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_ISC_POSIX
AC_PROG_INSTALL
AC_SET_MAKE
AC_CONFIG_HEADER(dialogconfig.h)
AC_CHECK_FUNCS(strcasecmp)

dnl The --enable-multiplatform option.
AC_CANONICAL_HOST
AC_ARG_ENABLE(multiplatform,
[  --enable-multiplatform     put executables in bin/PLATFORM],
if test "x$enable_multiplatform" = xyes && test "$bindir" = '${exec_prefix}/bin'
then
  bindir="$bindir/$host"
fi)

sinclude(withenable.ac)

#
# Check for ncurses.
#

have_ncurses=no
HAVE_NCURSES_CURSES_H=no

CURSESCPPFLAGS=
if test "$try_ncurses" = yes; then
  AC_CHECK_LIB(ncurses, wresize, have_ncurses=yes, have_ncurses=no)
  if test "${have_ncurses}" = "yes" ; then
    AC_DEFINE(HAVE_NCURSES)
    if (
      AC_CHECK_HEADERS(ncurses/curses.h, HAVE_NCURSES_CURSES_H=yes, HAVE_NCURSES_CURSES_H=no)
      test $HAVE_NCURSES_CURSES_H = yes && exit 0
      exit 1
    )
    then
      HAVE_NCURSES_CURSES_H=yes
    else
      HAVE_NCURSES_CURSES_H=no
    fi

    if (
      AC_CHECK_HEADERS(ncurses.h, HAVE_NCURSES_H=yes, HAVE_NCURSES_H=no)
      test $HAVE_NCURSES_H = yes && exit 0
      exit 1
    )
    then
      HAVE_NCURSES_H=yes
    else
      HAVE_NCURSES_H=no
    fi

    if test "${HAVE_NCURSES_CURSES_H}" = no && test "${HAVE_NCURSES_H}" = no; then
      # Try again, and check for the bogus ncurses/ include bug.
      # (i.e. ncurses/curses.h bogusly includes <unctrl.h> instead of
      # <ncurses/unctrl.h>)
      AC_MSG_RESULT(Trying again with -I/usr/include/ncurses...)
      OLD_CPP="${CPP}"
      CPP="${CPP} -I/usr/include/ncurses"
      if (
        AC_CHECK_HEADERS(ncurses/curses.h, HAVE_NCURSES_CURSES_H=yes, HAVE_NCURSES_CURSES_H=no)
        test $HAVE_NCURSES_CURSES_H = yes && exit 0
        exit 1
      )
      then
        HAVE_NCURSES_CURSES_H=yes
      else
        HAVE_NCURSES_CURSES_H=no
      fi
      
      if test "${HAVE_NCURSES_CURSES_H}" = "yes" ; then
        CURSESCPPFLAGS=-I/usr/include/ncurses
        AC_MSG_RESULT([    Your system has the bogus ncurses include bug.])
      else
        CPP="${OLD_CPP}"
      fi
    fi
  fi
fi

if test "${have_ncurses}" = yes  && { test "${HAVE_NCURSES_CURSES_H}" = yes || test "${HAVE_NCURSES_H}" = yes; }; then
  LDCURSESLIB=-lncurses
  CURSESDEP=
  no_recursion=yes
else
  CURSESCPPFLAGS='-I$(NCURSESDIR)/include -I$(NCURSESSRCDIR)/include'
  LDCURSESLIB='-L$(NCURSESDIR)/lib -lncurses'
  CURSESDEP='$(NCURSESDIR)/lib/libncurses.a'
  AC_CONFIG_SUBDIRS(ncurses)
fi

AC_SUBST(CURSESCPPFLAGS)
AC_SUBST(LDCURSESLIB)
AC_SUBST(CURSESDEP)

ac_configure_args=`echo "$ac_configure_args" | sed 's@--prefix=[[^ ]]*@@'`

AC_OUTPUT(Makefile)
