AC_PREREQ(2.57)
AC_REVISION($Revision: 4719 $)
AC_COPYRIGHT(Copyright 2002 - 2013 The pgAdmin Development Team)
AC_INIT(pgadmin3, 1.18.1, pgadmin-support@postgresql.org)
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([pgadmin/pgAdmin3.cpp])
AC_CONFIG_HEADERS([config.h])
AC_CANONICAL_HOST
AM_INIT_AUTOMAKE([tar-ustar])
AC_PREFIX_DEFAULT([/usr/local/pgadmin3])

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AM_PROG_CC_C_O
AC_PROG_RANLIB
CHECK_CPP_COMPILER
CHECK_SUN_COMPILER
AM_CONDITIONAL([SUN_CC], [test x$SUN_CC_COMPILER = xyes])
AM_CONDITIONAL([SUN_CXX], [test x$SUN_CXX_COMPILER = xyes])

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([arpa/inet.h netdb.h netinet/in.h stdlib.h])
AC_CHECK_HEADERS([errno.h fcntl.h stdio.h unistd.h sys/uio.h])
AC_CHECK_HEADERS([sys/select.h sys/socket.h sys/ioctl.h sys/time.h])
AC_CHECK_HEADERS([sys/un.h], [have_sys_un_h=yes], [have_sys_un_h=no])
AM_CONDITIONAL([HAVE_SYS_UN_H], test "x$have_sys_un_h" = xyes)
AC_CONFIG_HEADERS([pgadmin/include/libssh2/libssh2_config.h])

# 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_STRTOD
AC_CHECK_FUNCS([gethostbyname inet_ntoa memmove memset strchr])

# Custom checks
ENABLE_DEBUG
ENABLE_STATIC
ENABLE_APPBUNDLE
ENABLE_DATABASEDESIGNER

AM_CONDITIONAL([APPBUNDLE], [test x$BUILD_APPBUNDLE = xyes])
AM_CONDITIONAL([BUILD_DEBUG], [test x$BUILD_DEBUG = xyes])
AM_CONDITIONAL([INSTALL_DOCS], [test x$INSTALL_DOCS = xyes])

LOCATE_POSTGRESQL
SETUP_POSTGRESQL
CHECK_EDB_LIBPQ
AM_CONDITIONAL([EDB_LIBPQ], [test x$EDB_LIBPQ = xyes])

SETUP_ARCH_I386
SETUP_ARCH_X86_64
SETUP_ARCH_PPC
SETUP_ARCH_PPC64
SET_WX_VERSION
LOCATE_WXWIDGETS
CHECK_WXWIDGETS
SETUP_WXWIDGETS

LOCATE_LIBXML2
SETUP_LIBXML2
CHECK_LIBXML2

LOCATE_LIBXSLT
SETUP_LIBXSLT

# Configure parameters
AC_ARG_WITH(libgcrypt,
	AC_HELP_STRING([--with-libgcrypt],[Use Libgcrypt for crypto]),
	use_libgcrypt=$withval,use_libgcrypt=auto)
AC_ARG_WITH(openssl,
	AC_HELP_STRING([--with-openssl],[Use OpenSSL for crypto]),
	use_openssl=$withval,use_openssl=auto)
AC_ARG_WITH(libz,
	AC_HELP_STRING([--with-libz],[Use Libz for compression]),
	use_libz=$withval,use_libz=auto)

# Look for OpenSSL (default)
if test "$use_openssl" != "no" && test "$use_libgcrypt" != "yes"; then
	AC_LIB_HAVE_LINKFLAGS([ssl], [crypto], [#include <openssl/ssl.h>])
	LIBSREQUIRED=libssl,libcrypto
fi

# Look for libgcrypt
if test "$ac_cv_libssl" != "yes" && test "$use_libgcrypt" != "no"; then
	AC_LIB_HAVE_LINKFLAGS([gcrypt], [], [#include <gcrypt.h>])
	LIBSREQUIRED=libgcrypt
fi

AC_SUBST(LIBSREQUIRED)

if test "$ac_cv_libssl" != "yes" && test "$ac_cv_libgcrypt" != "yes"; then
	AC_MSG_NOTICE([cannot find OpenSSL or Libgcrypt, try --with-libssl-prefix=PATH or --with-libgcrypt-prefix=PATH])
	BUILD_SSH_TUNNEL="no"
else
	BUILD_SSH_TUNNEL="yes"
fi
AM_CONDITIONAL([BUILD_SSH_TUNNEL], [test x$BUILD_SSH_TUNNEL = xyes])

if test "$ac_cv_libssl" = "yes"; then
	CPPFLAGS="$CPPFLAGS -DHAVE_OPENSSL_CRYPTO"
	LIBS="$LIBS $LIBSSL"
fi

if test "$ac_cv_libgcrypt" = "yes"; then
	CPPFLAGS="$CPPFLAGS -DHAVE_GCRYPT"
	LIBS="$LIBS $LIBGCRYPT"
	AC_DEFINE(LIBSSH2_LIBGCRYPT, 1, [Use libgcrypt])
fi
AM_CONDITIONAL(LIBGCRYPT, test "$ac_cv_libgcrypt" = "yes")

# Not all OpenSSL have AES-CTR functions.
if test "$ac_cv_libssl" = "yes"; then
	save_LDFLAGS="$LDFLAGS"
	LDFLAGS="$LDFLAGS $LIBSSL"
	AC_CHECK_FUNCS(EVP_aes_128_ctr)
	LDFLAGS="$save_LDFLAGS"
fi

# Look for Libz
if test "$use_libz" != "no"; then
	AC_LIB_HAVE_LINKFLAGS([z], [], [#include <zlib.h>])
	if test "$ac_cv_libz" != yes; then
		AC_MSG_NOTICE([Cannot find libz, disabling compression])
		AC_MSG_NOTICE([Try --with-libz-prefix=PATH if you know you have it])
	else
		LIBS="$LIBS $LIBZ"
		AC_DEFINE(LIBSSH2_HAVE_ZLIB, 1, [Compile in zlib support])
	fi
fi

CURL_CHECK_NONBLOCKING_SOCKET

LOCATE_SPHINX
AM_CONDITIONAL([SPHINX_BUILD], [test x$SPHINX_BUILD != x])

AC_CONFIG_FILES([Makefile
		 branding/Makefile
		 i18n/Makefile
		 plugins.d/Makefile
		 pgadmin/Makefile
		 pkg/Makefile
		 pkg/debian/Makefile
		 pkg/mac/Makefile
		 pkg/mandrake/Makefile
		 pkg/redhat/Makefile
		 pkg/slackware/Makefile
		 pkg/src/Makefile
		 pkg/suse/Makefile
		 pkg/win32/Makefile
		 xtra/Makefile
		 xtra/png2c/Makefile
		 xtra/wx-build/Makefile])
AC_OUTPUT

SUMMARY
