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

AC_PREREQ(2.52)
AC_INIT(libircclient, 1.3, gyunaev@ulduzsoft.com)
AC_CONFIG_SRCDIR([include/libircclient.h])
AC_CONFIG_HEADER([include/config.h])

# Check for command-line
AC_ARG_ENABLE([debug],
            [AS_HELP_STRING([--enable-debug],
               [compile with debug information (no)])],
            [use_debug=$enableval],
            [use_debug=no])

AC_ARG_ENABLE([threads],
            [AS_HELP_STRING([--enable-threads],
               [compile with multithread support (yes)])],
            [use_threads=$enableval],
            [use_threads=yes])

AC_ARG_ENABLE([ipv6],
            [AS_HELP_STRING([--enable-ipv6],
               [compile with IPv6 support (no)])],
            [use_ipv6=$enableval],
            [use_ipv6=no])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_CHECK_TOOL(AR, ar, :)
AC_PROG_RANLIB

# Checks for header files.
AC_HEADER_STDC

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME

# Checks for library functions.
AC_FUNC_MALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_CHECK_FUNCS([localtime_r socket])

AC_CHECK_LIB(socket, socket, AC_DEFINE(HAVE_SOCKET) LIBS="$LIBS -lsocket")

if test "$use_debug" = "yes"; then
	CFLAGS="${CFLAGS} -g -DENABLE_DEBUG"
else
	CFLAGS="${CFLAGS} -O3"
fi

if test "$use_ipv6" = "yes"; then
	AC_CHECK_FUNCS([getaddrinfo inet_pton])
	AC_CHECK_LIB(nsl, getaddrinfo, AC_DEFINE(HAVE_GETADDRINFO) LIBS="$LIBS -lnsl")
	CFLAGS="$CFLAGS -DENABLE_IPV6"
else
	AC_CHECK_FUNCS([gethostbyname_r inet_ntoa])
	AC_CHECK_LIB(nsl, inet_ntoa, AC_DEFINE(HAVE_INET_NTOA) LIBS="$LIBS -lnsl")
fi

if test "$use_threads" = "yes"; then
	CFLAGS="$CFLAGS -DENABLE_THREADS -D_REENTRANT"
fi


AC_SUBST(CFLAGS)
AC_SUBST(LIBS)
AC_SUBST(PREFIX)
AC_CONFIG_FILES([examples/Makefile src/Makefile])
AC_OUTPUT
