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(HaveCurses)
if test -e "/usr/lib/libcurses.a" || test -e "/usr/lib/libcurses.so" || test -e "/usr/lib/libcurses.dylib"; then
    echo "-lcurses"

    LIBCURSES="-lcurses"
elif test -e "/usr/lib/libncurses.a" || test -e "/usr/lib/libncurses.so" || test -e "/usr/lib/libncurses.dylib"; then
    echo "-lncurses"

    LIBCURSES="-lncurses"
else
    echo "no curses. please install curses library"
    exit 1
fi

AC_MSG_CHECKING(OperatingSystem)
if test `uname -s` = "SunOS"; then
    echo "Solaris"

    AC_DEFINE(__SOLARIS__, 1)

    if test `uname -r` = "5.8"; then
        CFLAGS="$CFLAGS -I ruby-cvs -I onig-4.0.2 -I/usr/local/gnu/include"
        CFLAGS2="$CFLAGS $LIBCURSES -ldl -lcrypt -lsocket"
        CFLAGS3="$LIBCURSES"
        CFLAGS4="-I/usr/local/gnu/include $LIBCURSES"
    else
        CFLAGS="$CFLAGS -I onig-4.0.2 -I ruby-cvs"
        CFLAGS2="$CFLAGS $LIBCURSES -ldl -lcrypt -lsocket"
        CFLAGS3="-lncurses"
        CFLAGS4="-lncurses"
    fi
elif test `uname -s` = "FreeBSD"; then
    echo "FreeBSD"

    AC_DEFINE(__FREEBSD__, 1)

    CFLAGS="$CFLAGS -I ruby-cvs -I onig-4.0.2"
    CFLAGS2="$CFLAGS $LIBCURSES -lcrypt"
    CFLAGS3="$LIBCURSES"
    CFLAGS4="$LIBCURSES"
elif test `uname -s | sed -e 's/\(.*\)-\(.*\)/\1/'` = "CYGWIN_NT"; then
    echo "CYGWIN_NT"

    CFLAGS="$CFLAGS -I ruby-cvs -I onig-4.0.2"
    CFLAGS2="$CFLAGS $LIBCURSES -lcrypt"
    CFLAGS3="$LIBCURSES"
    CFLAGS4="$LIBCURSES"
elif test `uname -s` = "Darwin"; then
    echo "Darwin"

    AC_DEFINE(__DARWIN__, 1)

    CFLAGS="$CFLAGS -I ruby-cvs -I onig-4.0.2"
    CFLAGS2="$CFLAGS $LIBCURSES"
    CFLAGS3="$LIBCURSES"
    CFLAGS4="$LIBCURSES"
else
    echo "Linux"

    AC_DEFINE(__LINUX__, 1)

    CFLAGS="$CFLAGS -I ruby-cvs -I onig-4.0.2"
    CFLAGS2="$CFLAGS $LIBCURSES -ldl -lcrypt"
    CFLAGS3="$LIBCURSES"
    CFLAGS4="$LIBCURSES"
fi

AC_MSG_CHECKING(PtyType)
if test -e "/dev/ptmx"; then
    echo "UNIX98_PTY"

    AC_DEFINE(UNIX98_PTY, 1)
else
    echo "BSD PTY"
fi

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

AC_MSG_CHECKING(HaveMigemo)
if test -e "/usr/local/lib/libmigemo.so" || test -e "/usr/local/lib/libmigemo.dll.a"; then
    echo "yes"
    AC_DEFINE(HAVE_MIGEMO, 1)
    MIGEMO="-L/usr/local/lib -lmigemo"
    AC_SUBST(MIGEMO)
    CFLAGS="$CFLAGS -I/usr/local/include"
elif test -e "/usr/lib/libmigemo.so" || test -e "/usr/lib/libmigemo.dll.a"; then
    echo "yes"
    AC_DEFINE(HAVE_MIGEMO, 1)
    MIGEMO="-lmigemo"
    AC_SUBST(MIGEMO)
else
    echo "no"
fi

AC_OUTPUT(Makefile)

