# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.57)
AC_INIT([ctrlgdb], [2.6.1], [jelmer@vernstok.nl])
AC_CONFIG_SRCDIR([line.c])
AC_CONFIG_HEADER([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

BINS="ctrlproxy"
MODS="liblog_irssi.so libctcp.so liblinestack_memory.so libauto-away.so libstrip.so libadmin.so libsocket.so libnoticelog.so libnickserv.so liblog_custom.so libantiflood.so librepl_simple.so librepl_command.so librepl_highlight.so librepl_memory.so librepl_none.so libmotd_file.so"
SOCKET_OBJS="socket.o"

# Checks for libraries.
AC_CHECK_LIB([popt], [poptGetArg], , AC_MSG_ERROR([Popt is required]))

PKG_CHECK_MODULES(PKG, libxml-2.0 glib-2.0 gmodule-2.0, , AC_MSG_ERROR([libxml and glib are required]))

LIB_PCRE=""

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_LIB(pcre, pcre_compile, [ LIB_PCRE="-lpcre" ] )
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h sys/ioctl.h sys/socket.h unistd.h popt.h tdb.h regex.h pcre.h openssl/ssl.h execinfo.h sys/time.h])

SSL_LIB=""

AC_CHECK_LIB(tdb, tdb_open, [ BINS="$BINS printstats"; MODS="$MODS libstats.so" ] )
AC_CHECK_LIB(crypto, DES_set_key)
AC_CHECK_LIB(ssl, SSL_connect, [ SOCKET_OBJS="$SOCKET_OBJS network-openssl.o"; SSL_LIB="-lssl" ] )

# Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_STRUCT_TM
AC_TYPE_UID_T

# Checks for library functions.
AC_FUNC_FORK
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_TYPE_SIGNAL

DOCBUILDE="#"
DOCINSTALLE="#"

AC_ARG_ENABLE(docs,
[ --enable-docs		 Build the documentation ],
[ test x$enableval = xyes && DOCBUILDE=""; ])

test -f ${srcdir-.}/doc/ctrlproxy.1 && DOCINSTALLE=""

DB2LATEXPATH=""
AC_ARG_WITH(db2latex,
[ --with-db2latex=path	Use db2latex from specified path ],
[ DB2LATEXPATH="$withval" ])

for I in /usr/share/sgml/docbook/stylesheet/xsl/db2latex/latex/docbook.xsl
do
	AC_MSG_CHECKING([for db2latex in $I])
	if test -f "$I"; then
		DB2LATEXPATH="$I"
		AC_MSG_RESULT([yes])
	else
		AC_MSG_RESULT([no])
	fi
done

NODB2LATEX=""
test -z "$DB2LATEXPATH" && NODB2LATEX="#"

# For the docs
AC_PATH_PROG(XSLTPROC, xsltproc)
AC_PATH_PROG(XMLTO, xmlto)
AC_PATH_PROG(DIA, dia)
AC_PATH_PROG(EPSTOPDF, epstopdf)
AC_PATH_PROG(PDFLATEX, pdflatex)

AC_SUBST(BINS)
AC_SUBST(MODS)
AC_SUBST(PDFLATEX)
AC_SUBST(DB2LATEXPATH)
AC_SUBST(NODB2LATEX)
AC_SUBST(SOCKET_OBJS)
AC_SUBST(SSL_LIB)
AC_SUBST(LIB_PCRE)
AC_SUBST(DIA)
AC_SUBST(EPSTOPDF)
AC_SUBST(DOCBUILDE)
AC_SUBST(DOCINSTALLE)
AC_CHECKING([which plugins to build])
AC_MSG_RESULT(["$MODS"])
AC_CHECK_FUNCS([gethostbyname gethostname memset mkdir socket strcasecmp strchr strdup strerror strncasecmp strstr uname dup2 backtrace_symbols gettimeofday strrchr])

AC_CONFIG_FILES([Makefile mods/Makefile ctrlproxy.pc doc/Makefile])
AC_OUTPUT
