
AC_INIT(src/chmfile.cpp)
AM_CONFIG_HEADER(config.h)

AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.11)

AM_OPTIONS_WXCONFIG

AM_PATH_WXCONFIG(2.4.0, wxWin=1)
if test "$wxWin" != 1; then
	AC_MSG_ERROR([
           wxWidgets must be installed on your system
           but the wx-config script couldn't be found.
     
     	   Please check that wx-config is in path, the directory
     	   where wxWidgets libraries are installed (returned by
     	   'wx-config --libs' command) is in LD_LIBRARY_PATH or
     	   equivalent variable and wxWidgets version is 2.3.4 or above.
        ])
fi

REZ_FLAGS="`$WX_CONFIG_PATH --rezflags`"
if test "x$REZ_FLAGS" = "x" -o "x$REZ_FLAGS" = "x#"; then
	REZ_COMMAND=""
else
	REZ_COMMAND="$REZ_FLAGS xchm"
fi
AC_SUBST(REZ_COMMAND)

wx_config_major_version=`echo $WX_VERSION | \
	sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
wx_config_minor_version=`echo $WX_VERSION | \
	sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`

if test $wx_config_major_version -gt 2 -o $wx_config_minor_version -ge 5;
	then
	CPPFLAGS="$CPPFLAGS -D_ENABLE_COPY_AND_FIND"
fi


CPPFLAGS="$CPPFLAGS $WX_CPPFLAGS"
CXXFLAGS="$CXXFLAGS $WX_CXXFLAGS_ONLY -W -Wall"
CFLAGS="$CFLAGS $WX_CFLAGS_ONLY"

     
AC_ARG_ENABLE(static, 
	      [  --enable-static         link statically to wxWidgets.], 
	      LINKOPT="$WX_LIBS_STATIC",
	      LINKOPT="$WX_LIBS")
AC_SUBST(LINKOPT)

AC_ARG_ENABLE(debug,
	      [  --enable-debug          compile with gdb debug information.], 
	      CXXFLAGS="$CXXFLAGS -g")

AC_ARG_ENABLE(optimize,
	      [  --enable-optimize       optimize compiled code (-O2).], 
	      CXXFLAGS="$CXXFLAGS -O2")
AC_ARG_ENABLE(xmlrpc,
	      [  --enable-xmlrpc         Enable XmlRpc functionality in xchm.],

	      [ enable_xmlrpc=yes ])

AM_INIT_AUTOMAKE(xchm, 0.9.7)
AC_PROG_CXX
AC_PROG_INSTALL

AC_CHECK_TYPE(u_int16_t, unsigned short)
AC_CHECK_TYPE(u_int32_t, unsigned int)
AC_CHECK_TYPE(u_int64_t, unsigned long long)

AC_CHECK_HEADER(chm_lib.h,,AC_MSG_ERROR([Can't find the CHMLIB header.]))
AC_CHECK_LIB(
    chm, chm_open,,
    AC_MSG_ERROR([Can't find/use -lchm. Please install CHMLIB first.])
)

if test "x$enable_xmlrpc" = "xyes" ; then
	AC_LANG_PUSH(C++)
	AC_CHECK_HEADERS(XmlRpc.h,,
	  AC_MSG_ERROR([Can't find the XmlRpc++ header.]))

	LIBS="$LIBS -lXmlRpc"	
	AC_TRY_LINK([#include<XmlRpc.h> ],
		[XmlRpc::XmlRpcServer svr;],
    	  [AC_DEFINE(WITH_LIBXMLRPC,1,[Compile with XmlRpc functionality.])],
	  AC_MSG_ERROR([Can't find/use -lXmlRpc. Please install XmlRpc++ first.])
	  )
	AC_LANG_POP()
fi

AC_OUTPUT(Makefile src/Makefile art/Makefile po/Makefile.in m4/Makefile )

