dnl Process this file with autoconf to produce a configure script.
AC_INIT(configure.in)
AC_CONFIG_AUX_DIR(config)
AM_INIT_AUTOMAKE(akaxiso, 2.0-beta3, no-define)
AM_CONFIG_HEADER(akaxiso2/config.h)


if test "x$CXXFLAGS" = "x"; then
  CXXFLAGS="-g -O -Wall"
fi

if test "x$CFLAGS" = "x"; then
  CFLAGS="-g -O -Wall"
fi



dnl Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_DISABLE_SHARED
AC_PROG_LIBTOOL
AC_PROG_INSTALL

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T



dnl Checks for std::istream::readsome() availability.
AC_LANG_SAVE

AC_LANG_CPLUSPLUS
AC_MSG_CHECKING(if std::istream::readsome() supported)
AC_TRY_COMPILE([#include <iostream>],
               [char *buf = 0;
                 std::cin.readsome(buf, 1);
               ],
               [ AC_MSG_RESULT(yes)
                 AC_DEFINE([AKAXISO2_ISTREAM_READSOME_SUPPORTED], 1, 
                          [std::istream::readsome(char*, unsigned int) is available])
               ],
               AC_MSG_RESULT(no)
)

AC_LANG_RESTORE


INTERNAL_ENCODING="UTF-8"
AC_ARG_WITH(internal, [  --with-internal Set internal encoding name.],
[ if test "x$withval" = "xUTF-8"; then
    INTERNAL_ENCODING="UTF-8"
  elif test "x$withval" = "xUCS-2"; then
    INTERNAL_ENCODING="UCS-2"
  else 
     AC_MSG_ERROR([arg of --with-internal should be UCS-2 or UTF-8])
  fi
]
)

if test "x$INTERNAL_ENCODING" = "xUTF-8"; then
dnl   AC_DEFINE_UNQUOTED([AKAXISO2_INTERNAL_UTF8], 
dnl                      1,
dnl                      [use UTF-8 as the internal encoding.])
   AC_MSG_RESULT(using UTF-8 as the internal encoding.)
fi

if test "x$INTERNAL_ENCODING" = "xUCS-2"; then
   AC_DEFINE_UNQUOTED([AKAXISO2_INTERNAL_UCS2], 
                      1,
                      [use UCS-2 as the internal encoding.])
   AC_MSG_RESULT(using UCS-2 as the internal encoding.)
fi


dnl encoding configuration

dnl checking given encoding name.
AC_ARG_WITH(encoding, [  --with-encoding Set default encoding name.],
[ if test "x$withval" = "x"; then
    AC_MSG_ERROR([--with-encoding=<OS's local encoding you'll use.>]) 
  fi
  AC_DEFINE_UNQUOTED([AKAXISO2_DEFAULT_ENCODING],
		     "$withval", 
		     [default encoding name])
]
)


dnl posix locale available?
AC_MSG_CHECKING(if POSIX-locale supported)
AC_CHECK_FUNC(setlocale,
	AC_DEFINE([AKAXISO2_POSIX_LOCALE_SUPPORTED], 
	          1, 
		  [use setlocale() to confirm codeset.])
)


dnl LIBRARIES

if test "x$AKAXISO2_INCLUDES" = "x"; then
   AKAXISO2_INCLUDES=
fi
if test "x$AKAXISO2_LDFLAGS" = "x"; then
   AKAXISO2_LDFLAGS=
fi


dnl iconv
AC_ARG_WITH(iconv,
	[  --with-iconv   Use iconv as transcoder.],
	[ AKAXISO2_USE_ICONV=$withval] ,
	[ AKAXISO2_USE_ICONV=yes ]
)

if test "x$AKAXISO2_USE_ICONV" = "xyes"; then
   AC_DEFINE([AKAXISO2_USE_ICONV], 1, [use iconv])
fi


dnl ICU
AC_ARG_WITH(icu,
	[  --with-icu=<ICU installation prefix>  Use ICU as transcoder.],
	[case "x$withval" in
	      xno)  AKAXISO2_USE_ICU=no ;;
	      xyes) AKAXISO2_LDFLAGS="$AKAXISO2_LDFLAGS -licuuc -licudata"
	            AKAXISO2_USE_ICU="yes" ;;
	      *)    AKAXISO2_INCLUDES="$AKAXISO2_INCLUDES -I$withval/include"
		    AKAXISO2_LDFLAGS="$AKAXISO2_LDFLAGS -L$withval/lib -licuuc -licudata" 
                    AKAXISO2_USE_ICU="yes" ;;
	 esac],
	 AKAXISO2_USE_ICU=no
)

if test "x$AKAXISO2_USE_ICU" = "xyes"; then
   AC_DEFINE([AKAXISO2_USE_ICU], 1, [define to enable ICU as transcoder.])
fi



dnl expat
AC_ARG_WITH(icu,
	[  --with-expat   Use expat as transcoder.],
	[case "x$withval" in
	      xno) ;;
	      xyes) AKAXISO2_USE_EXPAT=yes ;;
	      *)    AKAXISO2_USE_EXPAT="yes" ;;
	 esac],
	 AKAXISO2_USE_EXPAT=yes
)


if test "x$AKAXISO2_USE_EXPAT" = "xyes"; then
  AC_DEFINE([AKAXISO2_USE_EXPAT], 1, [define to use expat as XML parser])
fi

dnl Xerces-C++
AC_ARG_WITH(xercesc, 
        [  --with-xercesc=[yes|no|<Xerces-C++ installation prefix>]  Use Xerces-C++ as XML parser.],
        [case "x$withval" in
	      xno)  AKAXISO2_USE_XERCESC=no ;;
	      xyes) AKAXISO2_LDFLAGS="$AKAXISO2_LDFLAGS -lxerces-c"
	            AKAXISO2_USE_XERCESC="yes" ;;
	      *)    AKAXISO2_INCLUDES="$AKAXISO2_INCLUDES -I$withval/include"
		    AKAXISO2_LDFLAGS="$AKAXISO2_LDFLAGS -L$withval/lib -lxerces-c" 
                    AKAXISO2_USE_XERCESC="yes" ;;
	 esac],
	 [AKAXISO2_USE_XERCESC=no]
)


if test "x$AKAXISO2_USE_XERCESC" = "xyes"; then
  AC_DEFINE([AKAXISO2_USE_XERCESC], 1, [define to use Xerces-C++ as XML parser])
fi


AC_ARG_WITH(pthread, [  --with-pthread use pthread],
  [AKAXISO2_USE_PTHRAD="$withval"],
  [AKAXISO2_USE_PTHREAD=yes]
)


if test "x$AKAXISO2_USE_PTHREAD" = "xyes"; then
  CXXFLAGS="$CXXFLAGS -D_REENTRANT" 
  CFLAGS="$CFLAGS -D_REENTRANT"
  AKAXISO2_LDFLAGS="$AKAXISO2_LDFLAGS -lpthread"
  AC_DEFINE([AKAXISO2_USE_PTHREAD], 1, [use pthread.])
  AC_DEFINE([AKAXISO2_MULTITHREADED], 1, [activate multithread-ability])
fi


dnl VARIABLES
AC_SUBST(AKAXISO2_INCLUDES)
AC_SUBST(AKAXISO2_LDFLAGS)


if which cppunit-config > /dev/null 2>&1 ; then
  CPPUNIT_PREFIX=`cppunit-config --prefix`
  CPPUNIT_EXECPREFIX=`cppunit-config --exec-prefix`

  CPPUNIT_INCLUDES="-I$CPPUNIT_PREFIX/include"
  CPPUNIT_LDFLAGS="-L$CPPUNIT_EXECPREFIX/lib -lcppunit -ldl"
fi

AC_SUBST(CPPUNIT_INCLUDES)
AC_SUBST(CPPUNIT_LDFLAGS)


dnl
dnl expat config.
dnl

dnl
dnl Increment LIBREVISION if source code has changed at all
dnl
dnl If the API has changed, increment LIBCURRENT and set LIBREVISION to 0
dnl
dnl If the API changes compatibly (i.e. simply adding a new function
dnl without changing or removing earlier interfaces), then increment LIBAGE.
dnl 
dnl If the API changes incompatibly set LIBAGE back to 0
dnl

LIBCURRENT=5
LIBREVISION=0
LIBAGE=5

AC_SUBST(LIBCURRENT)
AC_SUBST(LIBREVISION)
AC_SUBST(LIBAGE)


if test "$GCC" = yes ; then
    dnl
    dnl Be careful about adding the -fexceptions option; some versions of
    dnl GCC don't support it and it causes extra warnings that are only
    dnl distracting; avoid.
    dnl
    OLDCFLAGS="$CFLAGS -Wall -Wmissing-prototypes -Wstrict-prototypes"
    CFLAGS="$OLDCFLAGS -fexceptions"
    AC_MSG_CHECKING(whether gcc accepts -fexceptions)
    AC_TRY_COMPILE(,(void)1,
                   AC_MSG_RESULT(yes),
                   AC_MSG_RESULT(no); CFLAGS="$OLDCFLAGS")
fi

dnl Checks for header files.
dnl AC_HEADER_STDC
dnl AC_CHECK_HEADERS(fcntl.h unistd.h)

dnl Checks for library functions.
dnl AC_FUNC_MEMCMP
dnl AC_FUNC_MMAP

if test "$ac_cv_func_mmap_fixed_mapped" = "yes"; then
    FILEMAP=unixfilemap
else
    FILEMAP=readfilemap
fi
AC_SUBST(FILEMAP)

AC_CHECK_FUNCS(memmove bcopy)

dnl some basic configuration
dnl AC_DEFINE([XML_NS], 1,
dnl          [Define to make XML Namespaces functionality available.])
AC_DEFINE([XML_DTD], 1,
          [Define to make parameter entity parsing functionality available.])
AC_DEFINE([XML_CONTEXT_BYTES], 1024,
          [Define to specify how much context to retain around the current parse point.])


dnl Checks for library functions.

AC_OUTPUT(
	Makefile
	akaxiso2/Makefile
	akaxiso2/framework/Makefile
	akaxiso2/util/Makefile
	akaxiso2/unicode/Makefile
	akaxiso2/transcoders/Makefile
	akaxiso2/XML/Makefile
	akaxiso2/XML/serializer/Makefile
	akaxiso2/XML/deserializer/Makefile
	akaxiso2/XML/expat/Makefile
	akaxiso2/XML/xerces/Makefile
	akaxiso2/imported/Makefile
	akaxiso2/imported/expat/Makefile
	akaxiso2/builtin/Makefile
	osixaka2/Makefile
	tools/Makefile
	tools/macros.h

	akaxiso2_sample/Makefile
	osixaka2_sample/Makefile

	wsdl_sample/Makefile
	akaxiso2_tests/Makefile
	osixaka2_tests/Makefile
	doc/Makefile
)
