AC_INIT([valknut], [0.4.7], [http://sourceforge.net/tracker/?group_id=181579&atid=897767])

# the required version of dclib, checked for by pkg-config
DCLIB_PKGCONFIG_VERSION="dclib >= 0.3.21"

AC_CONFIG_SRCDIR([COPYING.OpenSSL])

AC_CONFIG_AUX_DIR([admin])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([config.h])

AC_CANONICAL_TARGET
AC_CANONICAL_SYSTEM

AM_INIT_AUTOMAKE

AC_LANG([C++])

LINK_STATIC=""
AC_ARG_ENABLE([link-static],
[AS_HELP_STRING([--enable-link-static],[enable static link (default disabled)])],
[ if test x$enableval = "xyes"
  then
    LINK_STATIC="-static"
  fi ]
)

LARGEFILESUPPORT="-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
AC_ARG_ENABLE([lfs],
[AS_HELP_STRING([--disable-lfs],[disable largefile (files larger than 2GiB) support (default enabled)])],
[ if test x$enableval = "xno"
  then
    LARGEFILESUPPORT=""
  fi ]
)

dnl these have changed but I do not want to start doing
dnl 1000 tests of "does -Wsome-unusual-option-only-in-gcc-4.3 work?"
WARNINGFLAGS="-Wall -W -pedantic -Wno-long-long -Wundef -Wconversion"
AC_ARG_ENABLE([warnings],
[AS_HELP_STRING([--disable-warnings],[disable compiler warnings (default enabled)])],
[ if test "x$enableval" = "xno"
  then
    WARNINGFLAGS=""
  fi ]
)

DEBUGFLAGS=""
DEBUGCOMPILE=""
AC_ARG_ENABLE([debug],
[AS_HELP_STRING([--enable-debug],[enable debugging support (default disabled)])],
[ if test "x$enableval" = "xyes"
  then
    DEBUGFLAGS="-DDEBUG"
    DEBUGCOMPILE="-g"
  fi ]
)

PACKAGE_FLAGS="$DEBUGFLAGS $WARNINGFLAGS $LARGEFILESUPPORT -D_REENTRANT"
case $host in
  *-*-linux-gnu)
    PACKAGE_FLAGS="$PACKAGE_FLAGS -D_XOPEN_SOURCE=500 -D_BSD_SOURCE"
esac
AC_SUBST(PACKAGE_FLAGS)
AC_SUBST(DEBUGCOMPILE)

AC_PROG_CXX
AC_PROG_CXXCPP

AC_PROG_LIBTOOL

PKG_PROG_PKG_CONFIG([0.9.0])

VALKNUT_FIND_QT4

AC_MSG_CHECKING([for $DCLIB_PKGCONFIG_VERSION])
PKG_CHECK_EXISTS([$DCLIB_PKGCONFIG_VERSION], AC_MSG_RESULT([yes]), AC_MSG_ERROR([$DCLIB_PKGCONFIG_VERSION required]))

PKG_CHECK_MODULES([DCLIB],[$DCLIB_PKGCONFIG_VERSION])
DCLIB_LIBS="${DCLIB_LIBS} ${LINK_STATIC}"
AC_SUBST(DCLIB_LIBS)
AC_SUBST(DCLIB_CFLAGS)

AC_ARG_ENABLE([socks],
[AS_HELP_STRING([--enable-socks],[use the socks proxying library (default disabled)])],
[ if test x$enableval = "xyes"
    then
      AC_DEFINE(HAVE_SOCKS,1,[use the socks library])
      dnl #### This appears to be deficient with later versions of SOCKS.
      AC_CHECK_LIB(resolv, main)
      AC_CHECK_LIB([socks], [Rconnect], [], [AC_MSG_ERROR([Socks support requested but socks library not found])])
  fi
])

dnl /pretend command
AC_ARG_ENABLE([pretend-command],
[AS_HELP_STRING([--enable-pretend-command],[enable the /pretend chat command (default=yes for svn, no for release)])],
[ PRETEND_COMMAND=$enableval ],
[ PRETEND_COMMAND="auto"]
)

AC_MSG_CHECKING([for the /pretend command])

if test "x${PRETEND_COMMAND}" = "xauto"
then
  if echo "$PACKAGE_VERSION" | grep svn >/dev/null 2>&1
  then
    AC_DEFINE(ENABLE_PRETEND_TESTING_COMMAND,1,[enable the /pretend command])
    AC_MSG_RESULT([enabled for svn build])
  else
    AC_MSG_RESULT([disabled for release build])
  fi
elif test "x${PRETEND_COMMAND}" = "xyes"
then
  AC_DEFINE(ENABLE_PRETEND_TESTING_COMMAND,1,[enable the /pretend command])
  AC_MSG_RESULT([manually enabled])
elif test "x${PRETEND_COMMAND}" = "xno"
then
  AC_MSG_RESULT([manually disabled])
fi

AC_MSG_CHECKING([for build date and svn revision])

SERIAL="`date +%Y%m%d`"
AC_SUBST(SERIAL)

VALKNUT_BUILD_INFO="Build date: $SERIAL"
if echo "$PACKAGE_VERSION" | grep svn >/dev/null 2>&1
then
  VALKNUT_BUILD_INFO="$VALKNUT_BUILD_INFO svn: `svnversion`"
else
  VALKNUT_BUILD_INFO="$VALKNUT_BUILD_INFO release"
fi
AC_MSG_RESULT([$VALKNUT_BUILD_INFO])
AC_DEFINE_UNQUOTED([VALKNUT_BUILD_INFO],["$VALKNUT_BUILD_INFO"],[The date valknut was built, and if from svn, the svn revision])

dnl add here all your Makefiles. This are created by configure
AC_CONFIG_FILES([ Makefile ])
AC_CONFIG_FILES([ valknut.spec ])
AC_CONFIG_FILES([ valknut.lsm ])
AC_CONFIG_FILES([ Info.plist ])
AC_CONFIG_FILES([ valknut/Makefile ])
AC_CONFIG_FILES([ valknut/docs/Makefile ])
AC_CONFIG_FILES([ valknut/docs/en/Makefile ])
AC_CONFIG_FILES([ valknut/icons/Makefile ])
AC_CONFIG_FILES([ valknut/sounds/Makefile ])
AC_CONFIG_FILES([ valknut/ui/Makefile ])
AC_CONFIG_FILES([ valknut/ts/Makefile ])
AC_CONFIG_FILES([ valknut/ts/translations.pro ])
AC_OUTPUT
