
# configure.in

# File automatically generated by SConstruct ('scons autotools')
# DOT NOT EDIT!

# Init
AC_INIT([VMime Library], [0.9.0], [vincent@vincent-richard.net], [vmime])

AC_PREREQ([2.53])

AC_CONFIG_AUX_DIR(autotools)

# Library name
GENERIC_LIBRARY_NAME="vmime"
AC_SUBST(GENERIC_LIBRARY_NAME)

GENERIC_VERSIONED_LIBRARY_NAME="vmime"
AC_SUBST(GENERIC_VERSIONED_LIBRARY_NAME)

LIBRARY_NAME="libvmime"
AC_SUBST(LIBRARY_NAME)

# Library version
LIBRARY_VERSION="0:0:0"
AC_SUBST(LIBRARY_VERSION)

LIBRARY_RELEASE="0"
AC_SUBST(LIBRARY_RELEASE)


#
# Miscellaneous init stuff
#

AC_CANONICAL_HOST
AC_CANONICAL_TARGET

AM_INIT_AUTOMAKE(vmime, 0.9.0)
AC_CONFIG_SRCDIR([src/base.cpp])
AM_CONFIG_HEADER([config.h])

AM_MAINTAINER_MODE

VMIME_ADDITIONAL_DEFINES=""
VMIME_ADDITIONAL_PC_LIBS=""


#
# Check compilers, processors, etc
#

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AC_C_CONST
AC_C_INLINE
AC_HEADER_STDC
AC_HEADER_STDBOOL
AC_HEADER_DIRENT
AC_HEADER_TIME
AC_C_CONST

AC_LANG(C++)

AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_LN_S
AC_PROG_LIBTOOL

OST_LIB_PTHREAD  # from GNU Commons C++

AM_SANITY_CHECK
AM_PROG_LIBTOOL
AM_PROG_CC_C_O

AM_ICONV


#
# Some checks
#

# -- iconv
AC_MSG_CHECKING([if an usable version of iconv exists (required)])

if test "x$am_cv_func_iconv" = "xyes"; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
  AC_ERROR(no usable version of iconv has been found)
fi

# -- global constructors (stolen from 'configure.in' in libsigc++)
AC_MSG_CHECKING([if linker supports global constructors])
cat > mylib.$ac_ext <<EOF
#include <stdio.h>

struct A
{
  A() { printf("PASS\n"); }
};

A a;

int foo()
  { return 1; }

EOF
cat > mytest.$ac_ext <<EOF
#include <stdio.h>

extern int foo();

int main(int, char**)
{
  int i = foo();
  if(i != 1) printf("FAIL\n");
  return 0;
}

EOF
sh libtool --mode=compile $CXX -c mylib.$ac_ext >&5
sh libtool --mode=link $CXX -o libtest.la -rpath / -version-info 0 mylib.lo  >&5
$CXX -c $CFLAGS $CPPFLAGS mytest.$ac_ext >&5
sh libtool --mode=link $CXX -o mytest mytest.o libtest.la >&5 2>/dev/null

if test -x mytest; then
	myresult=`./mytest`
	if test "X$myresult" = "XPASS"; then
		AC_MSG_RESULT(yes)
	else
		AC_MSG_RESULT(no)
		AC_ERROR([
===================================================================
ERROR: This platform lacks support of construction of global
objects in shared libraries.

See ftp://rtfm.mit.edu/pub/usenet/news.answers/g++-FAQ/plain
for details about this problem.  Also for possible solutions
http://www.informatik.uni-frankfurt.de/~fp/Tcl/tcl-c++/tcl-c++.html
===================================================================])
	fi
else
	AC_MSG_RESULT(unknown)
fi
rm -f mylib.* mytest.* libtest.la .libs/libtest* mytest .libs/mytest .libs/lt-mytest .libs/mylib.* >&5
rmdir .libs >&5

# -- const_cast
AC_MSG_CHECKING([if C++ compiler supports const_cast<> (required)])
AC_TRY_COMPILE(
[
   class foo;
],[
   const foo *c=0;
   foo *c1=const_cast<foo*>(c);
],[
  AC_MSG_RESULT(yes)
],[
  AC_MSG_RESULT(no)
  AC_ERROR(C++ compiler const_cast<> does not work)
])

# -- dynamic_cast
AC_MSG_CHECKING([if C++ compiler supports dynamic_cast<> (required)])
AC_TRY_COMPILE(
[
   class foo { virtual ~foo() { } };
   class bar : public foo { };
],[
   foo *c=0;
   bar *c1=dynamic_cast<bar*>(c);
],[
  AC_MSG_RESULT(yes)
],[
  AC_MSG_RESULT(no)
  AC_ERROR(C++ compiler dynamic_cast<> does not work)
])

# -- mutable
AC_MSG_CHECKING(if C++ compiler supports mutable (required))
AC_TRY_COMPILE(
[
class k {
        mutable char *c;
public:
   void foo() const { c=0; }
};
],[
],[
  AC_MSG_RESULT(yes)
],[
  AC_MSG_RESULT(no)
  AC_ERROR(C++ compiler does not support 'mutable')
])

# -- namespace
AC_MSG_CHECKING(if C++ compiler supports name spaces (required))
AC_TRY_COMPILE(
[
namespace Check
  {
   int i;
  }
],[
  Check::i=1;
],[
  AC_MSG_RESULT(yes)
],[
  AC_MSG_RESULT(no)
  AC_ERROR(C++ compiler does not support 'namespace')
])


#
# Target OS and architecture
#

VMIME_TARGET_ARCH=${target_cpu}
VMIME_TARGET_OS=${target_os}

#
# Byte Order
#

AC_C_BIGENDIAN

if test "x$ac_cv_c_bigendian" = "xyes"; then
  VMIME_BYTE_ORDER_BIG_ENDIAN=1
  VMIME_BYTE_ORDER_LITTLE_ENDIAN=0
else
  VMIME_BYTE_ORDER_BIG_ENDIAN=0
  VMIME_BYTE_ORDER_LITTLE_ENDIAN=1
fi


#
# Generic Type Size
#

AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)

case 1 in
$ac_cv_sizeof_char)
  VMIME_TYPE_INT8=char
  ;;
*)
  AC_MSG_ERROR([no 8-bit type available])
esac

case 2 in
$ac_cv_sizeof_short)
  VMIME_TYPE_INT16=short
  ;;
$ac_cv_sizeof_int)
  VMIME_TYPE_INT16=int
  ;;
*)
  AC_MSG_ERROR([no 16-bit type available])
esac

case 4 in
$ac_cv_sizeof_int)
  VMIME_TYPE_INT32=int
  ;;
$ac_cv_sizeof_long)
  VMIME_TYPE_INT32=long
  ;;
*)
  AC_MSG_ERROR([no 32-bit type available])
esac


#
# Options
#

# ** debug

AC_ARG_ENABLE(debug,
     AC_HELP_STRING([--enable-debug], [Turn on debugging, default: disabled]),
     [case "${enableval}" in
       yes) conf_debug=yes ;;
       no)  conf_debug=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
      esac],
     [conf_debug=no])

if test "x$conf_debug" = "xyes"; then
	AM_CONDITIONAL(VMIME_DEBUG, true)
	VMIME_DEBUG=1
else
	AM_CONDITIONAL(VMIME_DEBUG, false)
	VMIME_DEBUG=0
fi

# ** messaging

AC_ARG_ENABLE(messaging,
     AC_HELP_STRING([--enable-messaging], [Enable messaging support and connection to mail servers, default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging=yes ;;
       no)  conf_messaging=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging) ;;
      esac],
     [conf_messaging=yes])

if test "x$conf_messaging" = "xyes"; then
	AM_CONDITIONAL(VMIME_HAVE_MESSAGING_FEATURES, true)
	VMIME_HAVE_MESSAGING_FEATURES=1
else
	AM_CONDITIONAL(VMIME_HAVE_MESSAGING_FEATURES, false)
	VMIME_HAVE_MESSAGING_FEATURES=0
fi

# ** SASL

AC_ARG_ENABLE(sasl,
     AC_HELP_STRING([--enable-sasl], [Enable SASL support with GNU SASL, default: enabled]),
     [case "${enableval}" in
       yes) conf_sasl=yes ;;
       no)  conf_sasl=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-sasl) ;;
      esac],
     [conf_sasl=yes])

if test "x$conf_sasl" = "xyes"; then
	# -- GNU SASL Library (http://www.gnu.org/software/gsasl/)
	AC_CHECK_HEADER(gsasl.h,
		AC_CHECK_LIB(gsasl, gsasl_check_version,
			[have_gsasl=yes AC_SUBST(GSASL_AVAIL_LIBS, -lgsasl) AC_SUBST(GSASL_AVAIL_REQUIRED, libgsasl)],
			 have_gsasl=no),
		have_gsasl=no)

	if test "x$have_gsasl" = "xyes"; then
		AM_CONDITIONAL(VMIME_HAVE_SASL_SUPPORT, true)
		VMIME_HAVE_SASL_SUPPORT=1

		GSASL_REQUIRED=${GSASL_AVAIL_REQUIRED}
		GSASL_LIBS=${GSASL_AVAIL_LIBS}
	else
		AC_MSG_ERROR(can't find an usable version of GNU SASL library)
	fi
else
	AM_CONDITIONAL(VMIME_HAVE_SASL_SUPPORT, false)
	VMIME_HAVE_SASL_SUPPORT=0

	GSASL_REQUIRED=
	GSASL_LIBS=
fi

AC_SUBST(GSASL_REQUIRED)
AC_SUBST(GSASL_LIBS)

# ** TLS

AC_ARG_ENABLE(tls,
     AC_HELP_STRING([--enable-tls], [Enable TLS/SSL support with GNU TLS, default: enabled]),
     [case "${enableval}" in
       yes) conf_tls=yes ;;
       no)  conf_tls=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-tls) ;;
      esac],
     [conf_tls=yes])

if test "x$conf_tls" = "xyes"; then
	# -- GNU TLS Library (http://www.gnu.org/software/gnutls/)
	PKG_CHECK_MODULES([LIBGNUTLS], [gnutls >= 1.2.0], have_gnutls=yes, have_gnutls=no)

	if test "x$have_gnutls" = "xyes"; then
		AM_CONDITIONAL(VMIME_HAVE_TLS_SUPPORT, true)
		VMIME_HAVE_TLS_SUPPORT=1
	else
		AC_MSG_ERROR(can't find an usable version of GNU TLS library)
	fi
else
	AM_CONDITIONAL(VMIME_HAVE_TLS_SUPPORT, false)
	VMIME_HAVE_TLS_SUPPORT=0
fi

# ** platform handlers

VMIME_BUILTIN_PLATFORMS=''
VMIME_DETECT_PLATFORM=''

case "x${target_os}" in
xwin* | xmingw* | xcygwin*)
	VMIME_DETECT_PLATFORM='windows'
	;;
x*)
	# Default is POSIX
	VMIME_DETECT_PLATFORM='posix'
	;;
esac

# ** messaging protocols

VMIME_BUILTIN_MESSAGING_PROTOS=''

AC_ARG_ENABLE(messaging-proto-pop3,
     AC_HELP_STRING([--enable-messaging-proto-pop3], [Enable built-in support for protocol 'pop3', default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging_proto_pop3=yes ;;
       no)  conf_messaging_proto_pop3=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging-proto-pop3) ;;
      esac],
     [conf_messaging_proto_pop3=yes])
if test "x$conf_messaging_proto_pop3" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_POP3, true)
	VMIME_BUILTIN_MESSAGING_PROTO_POP3=1
	VMIME_BUILTIN_MESSAGING_PROTOS="$VMIME_BUILTIN_MESSAGING_PROTOS pop3"
else
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_POP3, false)
	VMIME_BUILTIN_MESSAGING_PROTO_POP3=0
fi

AC_ARG_ENABLE(messaging-proto-smtp,
     AC_HELP_STRING([--enable-messaging-proto-smtp], [Enable built-in support for protocol 'smtp', default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging_proto_smtp=yes ;;
       no)  conf_messaging_proto_smtp=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging-proto-smtp) ;;
      esac],
     [conf_messaging_proto_smtp=yes])
if test "x$conf_messaging_proto_smtp" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_SMTP, true)
	VMIME_BUILTIN_MESSAGING_PROTO_SMTP=1
	VMIME_BUILTIN_MESSAGING_PROTOS="$VMIME_BUILTIN_MESSAGING_PROTOS smtp"
else
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_SMTP, false)
	VMIME_BUILTIN_MESSAGING_PROTO_SMTP=0
fi

AC_ARG_ENABLE(messaging-proto-imap,
     AC_HELP_STRING([--enable-messaging-proto-imap], [Enable built-in support for protocol 'imap', default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging_proto_imap=yes ;;
       no)  conf_messaging_proto_imap=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging-proto-imap) ;;
      esac],
     [conf_messaging_proto_imap=yes])
if test "x$conf_messaging_proto_imap" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_IMAP, true)
	VMIME_BUILTIN_MESSAGING_PROTO_IMAP=1
	VMIME_BUILTIN_MESSAGING_PROTOS="$VMIME_BUILTIN_MESSAGING_PROTOS imap"
else
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_IMAP, false)
	VMIME_BUILTIN_MESSAGING_PROTO_IMAP=0
fi

AC_ARG_ENABLE(messaging-proto-maildir,
     AC_HELP_STRING([--enable-messaging-proto-maildir], [Enable built-in support for protocol 'maildir', default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging_proto_maildir=yes ;;
       no)  conf_messaging_proto_maildir=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging-proto-maildir) ;;
      esac],
     [conf_messaging_proto_maildir=yes])
if test "x$conf_messaging_proto_maildir" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR, true)
	VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR=1
	VMIME_BUILTIN_MESSAGING_PROTOS="$VMIME_BUILTIN_MESSAGING_PROTOS maildir"
else
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR, false)
	VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR=0
fi

AC_ARG_ENABLE(messaging-proto-sendmail,
     AC_HELP_STRING([--enable-messaging-proto-sendmail], [Enable built-in support for protocol 'sendmail', default: enabled]),
     [case "${enableval}" in
       yes) conf_messaging_proto_sendmail=yes ;;
       no)  conf_messaging_proto_sendmail=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-messaging-proto-sendmail) ;;
      esac],
     [conf_messaging_proto_sendmail=yes])
if test "x$conf_messaging_proto_sendmail" = "xyes"; then
if test "x$VMIME_DETECT_PLATFORM" = "xposix"; then
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL, true)
	VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL=1
	VMIME_BUILTIN_MESSAGING_PROTOS="$VMIME_BUILTIN_MESSAGING_PROTOS sendmail"
else
	AC_MSG_WARN(sendmail is only available on POSIX platforms)
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL, false)
	VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL=0
fi
else
	AM_CONDITIONAL(VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL, false)
	VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL=0
fi




#
# System mail
#

AC_PATH_PROG(SENDMAIL, sendmail, /usr/sbin/sendmail, /usr/sbin:/usr/lib)


#
# Detect some platform-specific stuff
#

# -- MLang (Windows)
if test "x$VMIME_DETECT_PLATFORM" = "xwindows"; then
	AC_CHECK_HEADER(mlang.h, [VMIME_ADDITIONAL_DEFINES="$VMIME_ADDITIONAL_DEFINES HAVE_MLANG_H"])
fi

# -- Link with Winsock (Windows)
if test "x$VMIME_DETECT_PLATFORM" = "xwindows"; then
	VMIME_ADDITIONAL_PC_LIBS="$VMIME_ADDITIONAL_PC_LIBS -lwsock32"
fi

# -- getaddrinfo (POSIX)
if test "x$VMIME_DETECT_PLATFORM" = "xposix"; then
	AC_CHECK_HEADERS(netdb.h sys/types.h sys/socket.h,)
	AC_CHECK_FUNC(getaddrinfo, [VMIME_ADDITIONAL_DEFINES="$VMIME_ADDITIONAL_DEFINES HAVE_GETADDRINFO"])
fi

# -- pthreads (POSIX)

ACX_PTHREAD([VMIME_ADDITIONAL_DEFINES="$VMIME_ADDITIONAL_DEFINES HAVE_PTHREAD"])


if test "x$VMIME_DETECT_PLATFORM" = "xwindows"; then
	conf_platform_windows=yes
else
	conf_platform_windows=no
fi

AC_ARG_ENABLE(platform-windows,
     AC_HELP_STRING([--enable-platform-windows], [Compile built-in platform handler for 'windows' , default: disabled, except if default for your platform]),
     [case "${enableval}" in
       yes) conf_platform_windows=yes ;;
       no)  conf_platform_windows=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-platform-windows) ;;
      esac],
      [])
if test "x$conf_platform_windows" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_PLATFORM_WINDOWS, true)
	VMIME_BUILTIN_PLATFORM_WINDOWS=1
	VMIME_BUILTIN_PLATFORMS="$VMIME_BUILTIN_PLATFORMS windows"
else
	AM_CONDITIONAL(VMIME_BUILTIN_PLATFORM_WINDOWS, false)
	VMIME_BUILTIN_PLATFORM_WINDOWS=0
fi

if test "x$VMIME_DETECT_PLATFORM" = "xposix"; then
	conf_platform_posix=yes
else
	conf_platform_posix=no
fi

AC_ARG_ENABLE(platform-posix,
     AC_HELP_STRING([--enable-platform-posix], [Compile built-in platform handler for 'posix' , default: disabled, except if default for your platform]),
     [case "${enableval}" in
       yes) conf_platform_posix=yes ;;
       no)  conf_platform_posix=no ;;
       *) AC_MSG_ERROR(bad value ${enableval} for --enable-platform-posix) ;;
      esac],
      [])
if test "x$conf_platform_posix" = "xyes"; then
	AM_CONDITIONAL(VMIME_BUILTIN_PLATFORM_POSIX, true)
	VMIME_BUILTIN_PLATFORM_POSIX=1
	VMIME_BUILTIN_PLATFORMS="$VMIME_BUILTIN_PLATFORMS posix"
else
	AM_CONDITIONAL(VMIME_BUILTIN_PLATFORM_POSIX, false)
	VMIME_BUILTIN_PLATFORM_POSIX=0
fi



#
# Workarounds for some platforms
#

# -- pkgconfigdir
case "x${target_os}" in
xfreebsd*)

	VMIME_PKGCONFIGDIR='$(prefix)/libdata/pkgconfig'
	;;

x*)

	VMIME_PKGCONFIGDIR='$(libdir)/pkgconfig'
	;;
esac

AC_SUBST(VMIME_PKGCONFIGDIR)

# -- libtool 'CXX' tag
case "x${target_os}" in
xfreebsd*)
	# FIXME: temporary hack until I find a better solution
	# to make libtool use the C++ tag...
	LIBTOOL="$LIBTOOL --tag=CXX"
	;;
esac


#
# Flags
#

LIBRARY_LD_FLAGS="\$(top_builddir)/src/\$(LIBRARY_NAME).la"
AC_SUBST(LIBRARY_LD_FLAGS)

PKGCONFIG_CFLAGS=""
PKGCONFIG_LIBS=""

AC_SUBST(PKGCONFIG_CFLAGS)
AC_SUBST(PKGCONFIG_LIBS)

EXTRA_CFLAGS="$EXTRA_CFLAGS -D_REENTRANT=1 -D_THREAD_SAFE=1 $LIBGNUTLS_CFLAGS"
EXTRA_LIBS="$GSASL_LIBS $LIBGNUTLS_LIBS"

CFLAGS=""
CXXFLAGS=""

# -- Debug
if test x$VMIME_DEBUG = x1 ; then
	# -g
	OLD_CXXFLAGS="$CXXFLAGS"
	CXXFLAGS="$CXXFLAGS -g"
	AC_MSG_CHECKING(whether cc accepts -g)
	AC_TRY_COMPILE(,,echo yes,echo no; CXXFLAGS="$OLD_CXXFLAGS")
else
	# -O2
	OLD_CXXFLAGS="$CXXFLAGS"
	CXXFLAGS="$CXXFLAGS -O2"
	AC_MSG_CHECKING(whether cc accepts -O2)
	AC_TRY_COMPILE(,,echo yes,echo no; CXXFLAGS="$OLD_CXXFLAGS")
fi

# -- HACK: add -fPIC or -fpic on static library object files
EXTRA_CFLAGS="$EXTRA_CFLAGS $lt_prog_compiler_pic"



#
# Check to see if the compiler can handle some flags
#

# -pipe
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -pipe"
AC_MSG_CHECKING(whether cc accepts -pipe)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -ansi
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -ansi"
AC_MSG_CHECKING(whether cc accepts -ansi)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -pedantic
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -pedantic"
AC_MSG_CHECKING(whether cc accepts -pedantic)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -W
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -W"
AC_MSG_CHECKING(whether cc accepts -W)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -Wall
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wall"
AC_MSG_CHECKING(whether cc accepts -Wall)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -Wpointer-arith
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wpointer-arith"
AC_MSG_CHECKING(whether cc accepts -Wpointer-arith)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -Wold-style-cast
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wold-style-cast"
AC_MSG_CHECKING(whether cc accepts -Wold-style-cast)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")

# -Wconversion
OLD_EXTRA_CFLAGS="$EXTRA_CFLAGS"
EXTRA_CFLAGS="$EXTRA_CFLAGS -Wconversion"
AC_MSG_CHECKING(whether cc accepts -Wconversion)
AC_TRY_COMPILE(,,echo yes,echo no; EXTRA_CFLAGS="$OLD_EXTRA_CFLAGS")


#EXTRA_CFLAGS=`echo $EXTRA_CFLAGS | sed -e 's| |\n|g' | sort | uniq | tr '\n' ' '`
EXTRA_CFLAGS=`echo $EXTRA_CFLAGS | tr '\n' ' ' | sort | uniq | tr '\n' ' '`
EXTRA_LIBS=`echo $EXTRA_LIBS | sed -e 's|^ ||g' | sed -e 's|  | |g'`

AC_SUBST(CFLAGS)
AC_SUBST(CXXFLAGS)

AC_SUBST(EXTRA_CFLAGS)
AC_SUBST(EXTRA_LIBS)

AC_SUBST(VMIME_ADDITIONAL_PC_LIBS)

LIBS=`echo $LIBS | sed -e 's|^ ||g' | sed -e 's|  | |g'`

AC_CONFIG_FILES([ vmime.pc
	Makefile
	src/Makefile
	vmime/Makefile
	])
AC_OUTPUT


#
# Generate vmime/config.hpp
#

echo "
//
// This file was automatically generated by configuration script.
//

#ifndef VMIME_CONFIG_HPP_INCLUDED
#define VMIME_CONFIG_HPP_INCLUDED


// Name of package
#define VMIME_PACKAGE \"libvmime\"

// Version number of package
#define VMIME_VERSION \"0.9.0\"
#define VMIME_API \"0:0:0\"

// Target OS and architecture
#define VMIME_TARGET_ARCH \"${VMIME_TARGET_ARCH}\"
#define VMIME_TARGET_OS \"${VMIME_TARGET_OS}\"

// Set to 1 if debugging should be activated
#define VMIME_DEBUG ${VMIME_DEBUG}

// Byte order (set one or the other, but not both!)
#define VMIME_BYTE_ORDER_BIG_ENDIAN    ${VMIME_BYTE_ORDER_BIG_ENDIAN}
#define VMIME_BYTE_ORDER_LITTLE_ENDIAN ${VMIME_BYTE_ORDER_LITTLE_ENDIAN}

// Generic types
// -- 8-bit
typedef signed ${VMIME_TYPE_INT8} vmime_int8;
typedef unsigned ${VMIME_TYPE_INT8} vmime_uint8;
// -- 16-bit
typedef signed ${VMIME_TYPE_INT16} vmime_int16;
typedef unsigned ${VMIME_TYPE_INT16} vmime_uint16;
// -- 32-bit
typedef signed ${VMIME_TYPE_INT32} vmime_int32;
typedef unsigned ${VMIME_TYPE_INT32} vmime_uint32;

// Options
// -- Wide characters support
#define VMIME_WIDE_CHAR_SUPPORT 0
// -- File-system support
#define VMIME_HAVE_FILESYSTEM_FEATURES 1
// -- SASL support
#define VMIME_HAVE_SASL_SUPPORT ${VMIME_HAVE_SASL_SUPPORT}
// -- TLS support
#define VMIME_HAVE_TLS_SUPPORT ${VMIME_HAVE_TLS_SUPPORT}
// -- Messaging support
#define VMIME_HAVE_MESSAGING_FEATURES ${VMIME_HAVE_MESSAGING_FEATURES}
// -- Built-in messaging protocols
#define VMIME_BUILTIN_MESSAGING_PROTOS \"$VMIME_BUILTIN_MESSAGING_PROTOS\"
#define VMIME_BUILTIN_MESSAGING_PROTO_POP3 $VMIME_BUILTIN_MESSAGING_PROTO_POP3
#define VMIME_BUILTIN_MESSAGING_PROTO_SMTP $VMIME_BUILTIN_MESSAGING_PROTO_SMTP
#define VMIME_BUILTIN_MESSAGING_PROTO_IMAP $VMIME_BUILTIN_MESSAGING_PROTO_IMAP
#define VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR $VMIME_BUILTIN_MESSAGING_PROTO_MAILDIR
#define VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL $VMIME_BUILTIN_MESSAGING_PROTO_SENDMAIL
// -- Built-in platform handlers
#define VMIME_BUILTIN_PLATFORMS \"$VMIME_BUILTIN_PLATFORMS\"
#define VMIME_BUILTIN_PLATFORM_WINDOWS $VMIME_BUILTIN_PLATFORM_WINDOWS 
#define VMIME_BUILTIN_PLATFORM_POSIX $VMIME_BUILTIN_PLATFORM_POSIX 

" > vmime/config.hpp

# Miscellaneous flags
echo "// Miscellaneous flags" >> vmime/config.hpp
echo "#define VMIME_SENDMAIL_PATH \"$SENDMAIL\"" >> vmime/config.hpp
echo "" >> vmime/config.hpp

# Additional defines
echo "// Additional defines" >> vmime/config.hpp

for d in $VMIME_ADDITIONAL_DEFINES ; do
	echo "#define VMIME_$d 1" >> vmime/config.hpp
done


echo "" >> vmime/config.hpp
echo "#endif // VMIME_CONFIG_HPP_INCLUDED" >> vmime/config.hpp


AC_MSG_RESULT([
+=================+
|  CONFIGURATION  |
+=================+

Installation prefix      : $prefix
Debugging mode           : $conf_debug
Messaging support        : $conf_messaging
     * protocols         :$VMIME_BUILTIN_MESSAGING_PROTOS
File-system support      : yes
Platform handlers        :$VMIME_BUILTIN_PLATFORMS
SASL support             : $conf_sasl
TLS/SSL support          : $conf_tls

Please check 'vmime/config.hpp' to ensure the configuration is correct.
])
