dnl
dnl JD用 configure.in
dnl
AC_PREREQ(2.50)
AC_INIT(jd, 1.0)
AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS(config.h)

AC_ISC_POSIX
AC_PROG_CC
AM_PROG_CC_STDC
AC_HEADER_STDC
AC_PROG_CPP
AC_PROG_CXX
AC_PROG_CXXCPP
AC_PROG_LIBTOOL
AC_LANG_CPLUSPLUS

dnl
dnl buildinfo.h
dnl
AC_DEFINE(HAVE_BUILDINFO_H, 1, Define to 1 if you have the 'buildinfo.h' header file.)
AC_PATH_PROG(SVN, svn)
AC_PATH_PROG(SVNVERSION, svnversion)
AC_PATH_PROG(DIFF, diff)

dnl
dnl OSを判定してOS別の設定
dnl 
case "${host_os}" in 
 linux*|gnu*|*-gnu)
   echo "os = linux or gnu"
   AC_DEFUN([AM_ICONV],[])
   AC_DEFINE(ICONV_CONST, , "iconv_const")
   ;;
 freebsd*) 
   echo "os = freebsd"
   AC_DEFINE(ICONV_CONST, const , "iconv_const")
   ;;
 solaris*)
   echo "os = solaris"
   AC_DEFINE(ICONV_CONST, const , "iconv_const")
   AC_DEFINE(NO_MSG_NOSIGNAL, , "no MSG_NOSIGNAL")
   AC_DEFINE(NO_TIMEGM, , "no timegm")
   ;;
 *)
   echo "os = ???(${host_os})"
   ;;
esac

AM_ICONV


dnl ---------------------------------------------------
dnl ---------------------------------------------------
dnl
dnl ユーザー設定
dnl

dnl 追加コンパイルオプション
CXXFLAGS="$CXXFLAGS -ggdb -Wall"

dnl ---------------------------------------------------
dnl ---------------------------------------------------

LIBSM_CFLAGS=""
LIBSM_LIBS=""
GNOMEUI_CFLAGS=""
GNOMEUI_LIBS=""

dnl
dnl パッケージのチェック
dnl
PKG_CHECK_MODULES(GTKMM,[gtkmm-2.4 >= 2.12.0], [ echo "gtkmm >= 2.12.0" ; GTKMMVER=2120 ], [ 

PKG_CHECK_MODULES(GTKMM,[gtkmm-2.4 >= 2.8.0], [ echo "gtkmm >= 2.8.0" ; GTKMMVER=280 ], [ 

   PKG_CHECK_MODULES(GTKMM,[gtkmm-2.4 >= 2.6.0], [ echo "gtkmm >= 2.6.0" ; GTKMMVER=260 ], [ 
  
     PKG_CHECK_MODULES(GTKMM, [gtkmm-2.4 >= 2.4.0], [ echo "gtkmm >= 2.4.0"; GTKMMVER=240   ] ) 
   ] ) 
] )
] )
PKG_CHECK_MODULES(GTHREAD, [gthread-2.0 >= 2.0] )
CXXFLAGS="$CXXFLAGS -DGTKMMVER=$GTKMMVER"

AC_SUBST(GTKMM_CFLAGS)
AC_SUBST(GTKMM_LIBS)
AC_SUBST(GTHREAD_CFLAGS)
AC_SUBST(GTHREAD_LIBS)

dnl 
dnl uname
dnl

echo "use uname"
AC_CHECK_HEADERS([sys/utsname.h])


dnl 
dnl crypt
dnl

echo "use crypt"
AC_CHECK_HEADERS([crypt.h])
AC_CHECK_LIB(crypt,crypt)


dnl
dnl zlib
dnl

echo "use zlib"
AC_CHECK_HEADERS([zlib.h])
AC_CHECK_LIB(z,inflate)

dnl
dnl socket
dnl

echo "use socket"
AC_CHECK_HEADERS([socket.h])
AC_CHECK_LIB(socket,socket)


dnl
dnl セッション管理
dnl
dnl
use_xsmp=no
use_gnomeui=no

AC_ARG_WITH(sessionlib,
[
  --with-sessionlib[[=xsmp/gnomeui/no]]
                          use session control library [[default=xsmp]]
],
[case "${withval}" in
  xsmp)
    use_xsmp=yes
    ;;
  gnomeui)
    use_gnomeui=yes
    ;;
  no)
    use_xsmp=no
    use_gnomeui=no
    ;;
  *)
    use_xsmp=yes
    ;;
esac],use_xsmp=yes)

dnl
dnl XSMPを使ってセッション管理をする。libSMとlibICEが必要。無ければXSMPは無効になる
dnl
dnl dirsの並びは Tk の configure に書いてあったもの + Fedora 向けにディレクトリを追加
dnl
if test x"$use_xsmp" = "xyes" ; then
  
  AC_MSG_CHECKING(for SMlib.h and ICElib.h)
  LIBSM_CFLAGS=""
  dirs="/usr/unsupported/include /usr/local/include /usr/X386/include /usr/X11R6/include /usr/X11R5/include /usr/include/X11R5 /usr/include/X11R4 /usr/openwin/include /usr/X11/include /usr/sww/include /usr/include"
  for i in $dirs ; do
    if test -r $i/X11/ICE/ICElib.h -a -r $i/X11/SM/SMlib.h ; then
      AC_MSG_RESULT($i)
      LIBSM_CFLAGS="-I$i"
      break
    fi
  done
  if test -z "$LIBSM_CFLAGS" ; then
    AC_MSG_RESULT(could not find SMlib.h and ICElib.h)
  fi

  AC_MSG_CHECKING(for libSM and libICE)
  LIBSM_LIBS="" 
  dirs="/usr/unsupported/lib /usr/local/lib /usr/X386/lib /usr/X11R6/lib /usr/X11R5/lib /usr/lib/X11R5 /usr/lib/X11R4 /usr/openwin/lib /usr/X11/lib /usr/sww/X11/lib /usr/lib /usr/X11R6/lib64 /usr/lib64"
  for i in $dirs ; do
    if test -r $i/libICE.so -a -r $i/libSM.so ; then
      AC_MSG_RESULT($i)
      LIBSM_LIBS="-L$i -lICE -lSM"
      break
    fi
  done
  if test -z "$LIBSM_LIBS" ; then
    AC_MSG_RESULT(could not find libSM and libICE.)
  fi

  if test -n "$LIBSM_CFLAGS" -a -n "$LIBSM_LIBS" ; then
    echo "use XSMP"
    AC_SUBST(LIBSM_CFLAGS)
    AC_SUBST(LIBSM_LIBS)
    CXXFLAGS="$CXXFLAGS -DUSE_XSMP"
  fi
fi

dnl
dnl GNOMEUIを使ってセッション管理をする。libgnomeui-develが必要。
dnl
if test x"$use_gnomeui" = "xyes" ; then

  PKG_CHECK_MODULES(GNOMEUI, [libgnomeui-2.0 >= 2.0] )

  echo "use GNOMEUI"
  AC_SUBST(GNOMEUI_CFLAGS)
  AC_SUBST(GNOMEUI_LIBS)
  CXXFLAGS="$CXXFLAGS -DUSE_GNOMEUI"
fi


dnl
dnl SSL
dnl

use_gnutls=yes

AC_ARG_WITH(openssl,[ --with-openssl    (use openssl)],
       [ if test "$withval" != "no" ;then
         use_gnutls=no
       fi ])

case "${use_gnutls}" in 
 yes)
   echo "use gnutls"
   PKG_CHECK_MODULES(GNUTLS, [gnutls >= 1.2] )
   AC_DEFINE(USE_GNUTLS, , "use gnutls")
   AC_SUBST(GNUTLS_CFLAGS)
   AC_SUBST(GNUTLS_LIBS)
   ;;
 *)
   echo "use openssl"
   PKG_CHECK_MODULES(OPENSSL, [openssl >= 0.9] )
   AC_DEFINE(USE_OPENSSL, , "use openssl")
   AC_SUBST(OPENSSL_CFLAGS)
   AC_SUBST(OPENSSL_LIBS)
   ;;
esac


dnl
dnl enable gprof
dnl

use_gprof=no

AC_ARG_ENABLE(gprof,[ --enable-gprof  (enable gprof)],
       [ if test "$enable_gprof" = "yes"; then
               echo "use gprof"
               CXXFLAGS="$CXXFLAGS -pg"
               use_gprof=yes
       fi ])

dnl
dnl checking migemo
dnl
AC_ARG_WITH(migemo,[ --with-migemo    (enable migemo search)],
       [ if test "$withval" != "no" ;then
               echo "use migemo"
               AC_CHECK_HEADERS([migemo.h])
               AC_CHECK_LIB(migemo,migemo_open)
       fi ])


AC_ARG_WITH(migemodict,[ --with-migemodict    (specifiy the path of migemo dictionary)],
       [ if test "$withval" ;then
               echo "migemodict = $withval"
               AC_DEFINE_UNQUOTED(MIGEMODICT, "$withval" , "migemodict")
       fi ])


dnl
dnl checking xdg-open
dnl
AC_ARG_WITH(xdgopen,[ --with-xdgopen    (use xdg-open as default browser)],
       [ if test "$withval" ;then
               echo "use xdg-open"
               AC_DEFINE(XDGOPEN, , "use xdg-open")
       fi ])


dnl
dnl checking alsa
dnl
AC_ARG_WITH(alsa,[ --with-alsa    (enable alsa)],
       [ if test "$withval" != "no" ;then
               echo "use alsa"
	       PKG_CHECK_MODULES(ALSA, [alsa >= 1.0] )
	       AC_DEFINE(USE_ALSA, , "use alsa")
	       AC_SUBST(ALSA_CFLAGS)
	       AC_SUBST(ALSA_LIBS)
       fi ])

dnl
dnl checking core2duo
dnl
if test "$use_gprof" == "no" ;then
AC_ARG_WITH(core2duo,[ --with-core2duo    (use core2duo)],
       [ if test "$withval" != "no" ;then
               echo "use core2duo"
	       CXXFLAGS="$CXXFLAGS -march=pentium-m -msse3 -pipe -fomit-frame-pointer"
       fi ])
fi


dnl
dnl checking athlon64
dnl
if test "$use_gprof" == "no" ;then
AC_ARG_WITH(athlon64,[ --with-athlon64    (use athlon64)],
       [ if test "$withval" != "no" ;then
               echo "use athlon64"
	       CXXFLAGS="$CXXFLAGS -march=athlon64 -pipe"
       fi ])
fi


dnl
dnl checking atom
dnl
if test "$use_gprof" == "no" ;then
AC_ARG_WITH(atom,[ --with-atom    (use atom)],
       [ if test "$withval" != "no" ;then
               echo "use atom"
	       CXXFLAGS="$CXXFLAGS -march=prescott -pipe -fomit-frame-pointer"
       fi ])
fi


dnl
dnl checking pangolayout
dnl
AC_ARG_WITH(pangolayout,[ --with-pangolayout    (use pangolayout)],
       [ if test "$withval" != "no" ;then
               echo "use pango_layout for drawing"
	       CXXFLAGS="$CXXFLAGS -DUSE_PANGOLAYOUT"
       fi ])


AC_OUTPUT(Makefile src/Makefile src/skeleton/Makefile src/jdlib/Makefile src/dbtree/Makefile src/dbimg/Makefile  src/bbslist/Makefile src/board/Makefile src/article/Makefile src/image/Makefile src/message/Makefile src/history/Makefile src/config/Makefile src/icons/Makefile src/sound/Makefile src/xml/Makefile )
