AC_INIT(main.cpp)

AC_CONFIG_HEADER(config.h)

AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL

AC_SUBST(CFLAGS2)
AC_SUBST(CFLAGS3)
AC_SUBST(CFLAGS4)
AC_SUBST(PREFIX_PATH)

if test "$prefix" = "NONE"; then
    PREFIX_PATH="$ac_default_prefix"
else
    PREFIX_PATH="$prefix"
fi
AC_DEFINE_UNQUOTED(PREFIX_PATH, "$PREFIX_PATH")

AC_MSG_CHECKING(OperatingSystem)
if test `uname -s` = "SunOS"; then
    AC_DEFINE(__SOLARIS__, 1)

    if test `uname -r` = "5.8"; then
        CFLAGS="$CFLAGS -I ruby-1.8.4 -I onig-4.0.1 -I/usr/local/gnu/include"
        CFLAGS2="$CFLAGS -lcurses -ldl -lcrypt -lsocket"
        CFLAGS3="-lcurses"
        CFLAGS4="-I/usr/local/gnu/include -lcurses"
    else
        CFLAGS="$CFLAGS -I onig-4.0.1 -I ruby-1.8.4"
        CFLAGS2="$CFLAGS -lcurses -ldl -lcrypt -lsocket"
        CFLAGS3="-lncurses"
        CFLAGS4="-lncurses"
    fi
elif test `uname -s` = "FreeBSD" || test `uname -s | sed -e 's/\(.*\)-\(.*\)/\1/'` = "CYGWIN_NT"; then
    CFLAGS="$CFLAGS -I ruby-1.8.4 -I onig-4.0.1"
    CFLAGS2="$CFLAGS -lcurses -lcrypt"
    CFLAGS3="-lcurses"
    CFLAGS4="-lcurses"
else
    CFLAGS="$CFLAGS -I ruby-1.8.4 -I onig-4.0.1"
    CFLAGS2="$CFLAGS -lcurses -ldl -lcrypt"
    CFLAGS3="-lcurses"
    CFLAGS4="-lcurses"
fi

AC_MSG_CHECKING(Pty)
if test -f "/dev/ptmx"; then
    AC_DEFINE(UNIX98_PTY, 1)
fi

AC_SUBST(DEBUG)
AC_ARG_WITH(debug, [ --with-debug debug mode ], [ DEBUG="-DDEBUG" ])

if test -f "/usr/local/lib/libmigemo.so" || test -f "/usr/local/lib/libmigemo.dll.a"; then
    AC_DEFINE(HAVE_MIGEMO, 1)
    MIGEMO="-L/usr/local/lib -lmigemo"
    AC_SUBST(MIGEMO)
    CFLAGS="$CFLAGS -I/usr/local/include"
fi

AC_OUTPUT(Makefile)

