dnl Process this file with autoconf to produce a configure script.
AC_INIT
AC_CONFIG_SRCDIR([bvi.c])
AC_CONFIG_HEADER(config.h)

AC_CANONICAL_HOST

dnl On SunOS4 systems you have to use the /usr/5bin/cc compiler
dnl to get the SYSV curses library:
case "$host_os" in
sunos4*)
	AC_MSG_RESULT("using /usr/5bin/cc")
	CC="/usr/5bin/cc"
	ac_objext="o"
	;;
*)
	AC_PROG_CC
	;;
esac


dnl Some curses specials
dnl Solaris needs for tputs 'putc(char)' instead of 'putc(int)'
case "$host_os" in
solaris*)
	CPPFLAGS="${CPPFLAGS} -D_MSE_INT_H"
	AC_DEFINE(NEED_PUTC_CHAR)
	;;
hpux9*) DEFS=${DEFS-"-DMINICURSES"}
	;;
esac


dnl Checks for programs.
AC_PROG_INSTALL

dnl Check for typedefs
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(void *)

AC_CHECK_TYPE(size_t, unsigned int)
AC_CHECK_TYPE(off_t, int)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h termcap.h termio.h termios.h unistd.h term.h ncurses/term.h)

dnl Check if ncurses requested
_cppflags="${CPPFLAGS}"
_ldflags="${LDFLAGS}"

AC_ARG_WITH(ncurses,
[  --with-ncurses[=DIR]    path to ncurses],[
  if test "$withval" != "no"; then
    CPPFLAGS="${CPPFLAGS} -I$withval/include -I$withval/include/ncurses"
    LDFLAGS="${LDFLAGS} -L$withval/lib"
  fi
])

AC_CHECK_HEADER(ncurses.h,
    AC_CHECK_LIB(ncurses, initscr,
        AC_DEFINE(HAVE_NCURSES_H) LIBS="${LIBS} -lncurses",
        AC_CHECK_LIB(curses, initscr,
        AC_DEFINE(HAVE_CURSES_H) LIBS="${LIBS} -lcurses",
        AC_MSG_ERROR([bvi requires the curses library]))),
    AC_CHECK_HEADER(curses.h,
        AC_CHECK_LIB(curses, initscr,
		AC_DEFINE(HAVE_CURSES_H) LIBS="${LIBS} -lcurses",
		AC_MSG_ERROR([bvi requires the curses library])),
		AC_MSG_ERROR([bvi requires the curses library])))

dnl Checks for typedefs, structures, and compiler characteristics.
dnl AC_TYPE_SIZE_T

dnl Checks for library functions.
dnl AC_TYPE_SIGNAL
AC_CHECK_FUNCS(strdup strtol strerror memmove)

AC_PROG_INSTALL

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
