AC_INIT(00readme)
AC_CONFIG_AUX_DIR(../support)
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PATH_PROG(RM,rm)
AC_PATH_PROG(PERL,perl)
if test -z $PERL; then
	AC_MSG_ERROR([perl not found! installation terminated])
fi
dnl AC_PATH_PROG(NKF, nkf)
dnl if test -z $NKF; then
dnl 	AC_MSG_ERROR([nkf not found! installation terminated])
dnl fi
AC_PATH_PROG(BISON, bison)
if test -z $BISON; then
	AC_MSG_ERROR([bison not found! installation terminated])
fi
AC_PATH_PROG(FLEX, flex)
if test -z $FLEX; then
	AC_MSG_ERROR([flex not found! installation terminated])
fi
AC_PATH_PROG(ICONV,iconv)
if test -z $ICONV; then
	AC_MSG_ERROR([iconv not found! installation terminated])
else 
    AC_MSG_CHECKING([for Jcode module in perl])
    if test `$PERL -e "use Jcode;"`; then
	AC_MSG_ERROR([ not found! installation terminated])
    else
        AC_MSG_RESULT("yes")
    fi
fi
dnl check for readline library for nextword
have_readline=no
AC_CHECK_HEADER(readline/readline.h,
    AC_CHECK_LIB(readline, readline,
	   have_readline=yes
	   LIBS="$LIBS -lreadline",
	AC_MSG_CHECKING([for readline in -lreadline with -ltermcap])
	ac_save_LIBS="$LIBS"
	LIBS="$ac_save_LIBS -lreadline -ltermcap"
	AC_TRY_LINK([#include <stdio.h>
#include <readline/readline.h>],[readline("");],
	    AC_MSG_RESULT("yes")
	    have_readline=yes,
	  AC_MSG_RESULT("no")
	  AC_MSG_CHECKING([for readline in -lreadline with -lncurses])
	  LIBS="$ac_save_LIBS -lreadline -lncurses"
	  AC_TRY_LINK([#include <stdio.h>
#include <readline/readline.h>],[readline("");],
	      AC_MSG_RESULT("yes")
	      have_readline=yes,
	    AC_MSG_RESULT("no")
	    LIBS="$ac_save_LIBS"
	  )
	)
    )
)
if test $have_readline = yes; then
    AC_DEFINE(HAVE_READLINE)
    dnl check some definition
    AC_MSG_CHECKING([for readline verion > 4.1])
    AC_EGREP_HEADER(rl_compentry_func_t, readline/readline.h,
	AC_MSG_RESULT([yes]),
      AC_MSG_RESULT([no - use old func])
      AC_DEFINE(HAVE_READLINE_4_1_OLDER)
    )
fi

AC_OUTPUT(Makefile mkdfa/Makefile mkdfa/mkdfa.pl mkdfa/mkfa-1.44-flex/Makefile generate/Makefile accept_check/Makefile nextword/Makefile yomi2voca/Makefile yomi2voca/yomi2voca.pl gram2sapixml/Makefile gram2sapixml/gram2sapixml.pl)
