dnl Process this file with autoconf to produce a configure script.
AC_INIT(forwback.c)
AC_CONFIG_HEADER(defines.h)

dnl Checks for programs.
AC_PROG_CC
AC_GCC_TRADITIONAL
AC_PROG_INSTALL

dnl Checks for libraries.
dnl Prefer BSD termcap library to SysV curses library.
AC_HAVE_LIBRARY(curses, [LIBS="$LIBS -lcurses"])
AC_HAVE_LIBRARY(termcap, [LIBS="$LIBS -ltermcap"])
dnl ??? AC_HAVE_LIBRARY(termlib, [LIBS="$LIBS -ltermlib"])
dnl Regular expressions (regcmp) are in -lgen or -lucb on Solaris 2.
AC_HAVE_LIBRARY(gen, [LIBS="$LIBS -lgen"])
AC_HAVE_LIBRARY(ucb, [LIBS="$LIBS -lucb"])
AC_HAVE_LIBRARY(intl, [LIBS="$LIBS -lintl"])
dnl ??? AC_HAVE_LIBRARY(gnuregex, [LIBS="$LIBS -lgnuregex"])

dnl Checks for header files.
AC_STDC_HEADERS
AC_HAVE_HEADERS(errno.h fcntl.h stdio.h termcap.h termio.h termios.h time.h unistd.h values.h sys/ioctl.h sys/stream.h sys/ptem.h)

dnl Checks for identifiers.
AC_OFF_T
AC_COMPILE_CHECK(void, , [void *foo = 0;], 
  [AC_DEFINE(HAVE_VOID)])
AC_COMPILE_CHECK(time_t, [#include <time.h>], [time_t t = 0;],
  [AC_DEFINE(HAVE_TIME_T)])

dnl Checks for functions and external variables.
AC_RETSIGTYPE
AC_HAVE_FUNCS(_setjmp system sigsetmask memcpy)
dnl Some systems have termios.h but not the corresponding functions.
AC_FUNC_CHECK(tcgetattr, AC_DEFINE(HAVE_TERMIOS_FUNCS))
AC_COMPILE_CHECK(strerror, [
#if HAVE_STDIO_H
#include <stdio.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif], [static char *x; x = strerror(0);],
  [AC_DEFINE(HAVE_STRERROR)])
AC_COMPILE_CHECK(, , [extern int sys_errlist; static int x; x = sys_errlist;], 
  [AC_DEFINE(HAVE_SYS_ERRLIST)])
AC_COMPILE_CHECK(, , [extern int errno; static int x; x = errno;], 
  [AC_DEFINE(HAVE_ERRNO)])
AC_COMPILE_CHECK(locale, [#include <locale.h>
#include <ctype.h>], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);],
  [AC_DEFINE(HAVE_LOCALE)])

have_ospeed=no
AC_CHECKING(termcap for ospeed)
AC_COMPILE_CHECK(, [
#include <sys/types.h>
#if HAVE_TERMIOS_H
#include <termios.h>
#endif
#if HAVE_TERMCAP_H
#include <termcap.h>
#endif], [ospeed = 0;], [AC_DEFINE(HAVE_OSPEED) have_ospeed=yes])
if test $have_ospeed = no; then
AC_COMPILE_CHECK(, , [extern short ospeed; ospeed = 0;], 
  [AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)])
fi


dnl Checks for regular expression functions.
have_regex=no
AC_CHECKING(for POSIX regex.h)
AC_COMPILE_CHECK(, [#include <sys/types.h>
#include <regex.h>],
  [regex_t *r; regfree(r);],
  AC_DEFINE(HAVE_POSIX_REGCOMP) have_regex=yes)
if test $have_regex = no; then
AC_FUNC_CHECK(regcmp, AC_DEFINE(HAVE_REGCMP) have_regex=yes)
fi
if test $have_regex = no; then
AC_COMPILE_CHECK(, [#include "regexp.h"], [regcomp("");],
AC_DEFINE(HAVE_V8_REGCOMP) have_regex=yes)
fi
if test $have_regex = no && test -f ${srcdir}/regex.c; then
AC_DEFINE(HAVE_POSIX_REGCOMP) REGEX_O='regex.$(O)' AC_SUBST(REGEX_O) have_regex=yes
fi
if test $have_regex = no && test -f ${srcdir}/regexp.c; then
AC_DEFINE(HAVE_V8_REGCOMP) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes
fi
if test $have_regex = no; then
AC_FUNC_CHECK(re_comp, AC_DEFINE(HAVE_RE_COMP) have_regex=yes)
fi
if test $have_regex = no; then
AC_DEFINE(NO_REGEX)
fi

AC_OUTPUT(Makefile)
