dnl Process this file with autoconf to produce a configure script.
AC_INIT(entities.c)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_HOST

LIBXML_MAJOR_VERSION=2
LIBXML_MINOR_VERSION=6
LIBXML_MICRO_VERSION=16
LIBXML_MICRO_VERSION_SUFFIX=
LIBXML_VERSION=$LIBXML_MAJOR_VERSION.$LIBXML_MINOR_VERSION.$LIBXML_MICRO_VERSION$LIBXML_MICRO_VERSION_SUFFIX
LIBXML_VERSION_INFO=`expr $LIBXML_MAJOR_VERSION + $LIBXML_MINOR_VERSION`:$LIBXML_MICRO_VERSION:$LIBXML_MINOR_VERSION

LIBXML_VERSION_NUMBER=`expr $LIBXML_MAJOR_VERSION \* 10000 + $LIBXML_MINOR_VERSION \* 100 + $LIBXML_MICRO_VERSION`

if test -f CVS/Entries; then
  extra=`grep ChangeLog CVS/Entries | grep -v LIBXML | sed -e s\%/ChangeLog/1\.%% -e s\%/.*$%%`
  echo extra=$extra
  if test "$extra" != ""
  then
      LIBXML_VERSION_EXTRA="-CVS$extra"
  fi
fi
AC_SUBST(LIBXML_MAJOR_VERSION)
AC_SUBST(LIBXML_MINOR_VERSION)
AC_SUBST(LIBXML_MICRO_VERSION)
AC_SUBST(LIBXML_VERSION)
AC_SUBST(LIBXML_VERSION_INFO)
AC_SUBST(LIBXML_VERSION_NUMBER)
AC_SUBST(LIBXML_VERSION_EXTRA)

VERSION=${LIBXML_VERSION}

AM_INIT_AUTOMAKE(libxml2, $VERSION)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_CPP
AC_PATH_PROG(RM, rm, /bin/rm)
AC_PATH_PROG(MV, mv, /bin/mv)
AC_PATH_PROG(TAR, tar, /bin/tar)
AC_PATH_PROG(PERL, perl, /usr/bin/perl)
AC_PATH_PROG(XMLLINT, xmllint, /usr/bin/xmllint)
AC_PATH_PROG(XSLTPROC, xsltproc, /usr/bin/xsltproc)

dnl Make sure we have an ANSI compiler
AM_C_PROTOTYPES
test "x$U" != "x" && AC_MSG_ERROR(Compiler not ANSI compliant)

AC_LIBTOOL_WIN32_DLL
AM_PROG_LIBTOOL

# AM_MAINTAINER_MODE

dnl
dnl option to build a minimal libxml2 library
dnl
AC_ARG_WITH(minimum, [  --with-minimum          build a minimally sized library (off)])
if test "$with_minimum" = "yes"
then
    echo "Configuring for a minimal library"
fi

dnl Checks for zlib library.
_cppflags="${CPPFLAGS}"
_ldflags="${LDFLAGS}"


AC_ARG_WITH(zlib,
[  --with-zlib[[=DIR]]       use libz in DIR],[
  if test "$withval" != "no" -a "$withval" != "yes"; then
    Z_DIR=$withval
    CPPFLAGS="${CPPFLAGS} -I$withval/include"
    LDFLAGS="${LDFLAGS} -L$withval/lib"
  fi
])
if test "$with_minimum" = "yes" -a "$with_zlib" = ""
then
    with_zlib=no
fi
if test "$with_zlib" = "no"; then
    echo "Disabling compression support"
else
    AC_CHECK_HEADERS(zlib.h,
	AC_CHECK_LIB(z, gzread,[
	    AC_DEFINE([HAVE_LIBZ], [], [Have compression library])
	    if test "x${Z_DIR}" != "x"; then
		Z_CFLAGS="-I${Z_DIR}/include"
		Z_LIBS="-L${Z_DIR}/lib -lz"
		[case ${host} in
		    *-*-solaris*)
			Z_LIBS="-L${Z_DIR}/lib -R${Z_DIR}/lib -lz"
			;;
		esac]
	    else
		Z_LIBS="-lz"
	    fi]))
fi

AC_SUBST(Z_CFLAGS)
AC_SUBST(Z_LIBS)

CPPFLAGS=${_cppflags}
LDFLAGS=${_ldflags}

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h])
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([ctype.h])
AC_CHECK_HEADERS([dirent.h])
AC_CHECK_HEADERS([errno.h])
AC_CHECK_HEADERS([malloc.h])
AC_CHECK_HEADERS([stdarg.h])
AC_CHECK_HEADERS([sys/stat.h])
AC_CHECK_HEADERS([sys/types.h])
AC_CHECK_HEADERS([time.h])
AC_CHECK_HEADERS([ansidecl.h])
AC_CHECK_HEADERS([ieeefp.h])
AC_CHECK_HEADERS([nan.h])
AC_CHECK_HEADERS([math.h])
AC_CHECK_HEADERS([limits.h])
AC_CHECK_HEADERS([fp_class.h])
AC_CHECK_HEADERS([float.h])
AC_CHECK_HEADERS([stdlib.h])
AC_CHECK_HEADERS([sys/socket.h], [], [],
[#if HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
])
AC_CHECK_HEADERS([netinet/in.h], [], [],
[#if HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
])
AC_CHECK_HEADERS([arpa/inet.h], [], [],
[#if HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
#if HAVE_ARPA_INET_H
# include <arpa/inet.h>
# endif
])
AC_CHECK_HEADERS([netdb.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([sys/select.h])
AC_CHECK_HEADERS([sys/mman.h])
AC_CHECK_HEADERS([sys/timeb.h])
AC_CHECK_HEADERS([signal.h])
AC_CHECK_HEADERS([arpa/nameser.h], [], [],
[#if HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
])
AC_CHECK_HEADERS([resolv.h], [], [],
[#if HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
# endif
#if HAVE_ARPA_NAMESER_H
# include <arpa/nameser.h>
# endif
])

dnl Specific dir for HTML output ?
AC_ARG_WITH(html-dir, AC_HELP_STRING([--with-html-dir=path],
            [path to base html directory, default $datadir/doc/html]),
            [HTML_DIR=$withval], [HTML_DIR='$(datadir)/doc'])

AC_ARG_WITH(html-subdir, AC_HELP_STRING([--with-html-subdir=path],
            [directory used under html-dir, default $PACKAGE-$VERSION/html]),
            [test "x$withval" != "x" && HTML_DIR="$HTML_DIR/$withval"],
            [HTML_DIR="$HTML_DIR/\$(PACKAGE)-\$(VERSION)/html"])

AC_SUBST(HTML_DIR)

dnl Checks for library functions.
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(strdup strndup strerror)
AC_CHECK_FUNCS(finite isnand fp_class class fpclass)
AC_CHECK_FUNCS(strftime localtime gettimeofday ftime)
AC_CHECK_FUNCS(stat _stat signal)

dnl Checking the standard string functions availability
AC_CHECK_FUNCS(printf sprintf fprintf snprintf vfprintf vsprintf vsnprintf sscanf,,
               NEED_TRIO=1)

dnl Checks for inet libraries:
AC_CHECK_FUNC(gethostent, , AC_CHECK_LIB(nsl, gethostent))
AC_CHECK_FUNC(setsockopt, , AC_CHECK_LIB(socket, setsockopt))
AC_CHECK_FUNC(connect, , AC_CHECK_LIB(inet, connect))

dnl Determine what socket length (socklen_t) data type is
AC_MSG_CHECKING([for type of socket length (socklen_t)])
AC_TRY_COMPILE2([
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>],[
(void)getsockopt (1, 1, 1, NULL, (socklen_t *)NULL)],[
  AC_MSG_RESULT(socklen_t *)
  SOCKLEN_T=socklen_t],[
  AC_TRY_COMPILE2([
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>],[
(void)getsockopt (1, 1, 1, NULL, (size_t *)NULL)],[
    AC_MSG_RESULT(size_t *)
    SOCKLEN_T=size_t],[
    AC_TRY_COMPILE2([
#include <stddef.h>
#include <sys/types.h>
#include <sys/socket.h>],[
(void)getsockopt (1, 1, 1, NULL, (int *)NULL)],[
      AC_MSG_RESULT(int *)
      SOCKLEN_T=int],[
      AC_MSG_WARN(could not determine)
      SOCKLEN_T="int"])])])
AC_DEFINE_UNQUOTED(SOCKLEN_T, $SOCKLEN_T, [Determine what socket length (socklen_t) data type is])

dnl ***********************Checking for availability of IPv6*******************

AC_MSG_CHECKING([whether to enable IPv6])
AC_ARG_ENABLE(ipv6, [ --enable-ipv6=[yes/no] enables compilation of IPv6 code],, enable_ipv6=yes)
if test "$with_minimum" = "yes"
then
    enable_ipv6=no
fi
if test $enable_ipv6 = yes; then
  have_ipv6=no
  AC_TRY_COMPILE([
    #include <sys/socket.h>
    #include <sys/types.h>], [
    struct sockaddr_storage ss;
    socket(AF_INET6, SOCK_STREAM, 0)
    ],
    have_ipv6=yes,
    have_ipv6=no
  )
  AC_MSG_RESULT($have_ipv6)

  if test $have_ipv6 = yes; then
    AC_DEFINE([SUPPORT_IP6], [], [Support for IPv6])
    have_broken_ss_family=no

    dnl *********************************************************************
    dnl on some platforms (like AIX 5L), the structure sockaddr doesn't have
    dnl a ss_family member, but rather __ss_family. Let's detect that
    dnl and define the HAVE_BROKEN_SS_FAMILY when we are on one of these platforms.
    dnl ********************************************************************
    AC_MSG_CHECKING([broken struct sockaddr::ss_family])
    AC_TRY_COMPILE([
      #include <sys/socket.h>
      #include <sys/types.h>], [
      struct sockaddr_storage ss ;
      ss.__ss_family = 0 ;
      ],
      have_broken_ss_family=yes,
      have_broken_ss_family=no
    )
    AC_MSG_RESULT($have_broken_ss_family)
    if test x$have_broken_ss_family = xyes ; then
      AC_DEFINE(HAVE_BROKEN_SS_FAMILY, [], [Whether struct sockaddr::__ss_family exists]) 
      AC_DEFINE(ss_family, __ss_family, [ss_family is not defined here, use __ss_family instead])
    fi

    have_getaddrinfo=no
    AC_CHECK_FUNC(getaddrinfo, have_getaddrinfo=yes)
    if test $have_getaddrinfo != yes; then
      for lib in bsd socket inet; do
        AC_CHECK_LIB($lib, getaddrinfo, [LIBS="$LIBS -l$lib";have_getaddrinfo=yes;break])
      done
    fi

    if test $have_getaddrinfo = yes; then
      AC_DEFINE([HAVE_GETADDRINFO], [], [Define if getaddrinfo is there])
    fi
  fi
fi 

dnl ******************************End IPv6 checks******************************

dnl Checks for isnan in libm if not in libc
AC_CHECK_FUNC(isnan, AC_DEFINE([HAVE_ISNAN],[], [Define if isnan is there]) , AC_CHECK_LIB(m, isnan,
  [AC_DEFINE([HAVE_ISNAN],[], [Define if isnan is there])]))

AC_CHECK_FUNC(isinf, AC_DEFINE([HAVE_ISINF], [], [Define if isinf is there]) , AC_CHECK_LIB(m, isinf,
  [AC_DEFINE([HAVE_ISINF], [], [Define if isinf is there])]))

XML_LIBDIR='-L${libdir}'
XML_INCLUDEDIR='-I${includedir}/libxml2'

dnl
dnl Extra flags
dnl
XML_CFLAGS=""
RDL_LIBS=""

AC_ARG_WITH(fexceptions,
[  --with-fexceptions      add GCC flag -fexceptions for C++ exceptions (off)])
if test "$with_minimum" = "yes" -a "$with_fexceptions" = ""
then
    with_fexceptions=no
fi
dnl
dnl Workaround for native compilers
dnl  HP  : http://bugs.gnome.org/db/31/3163.html
dnl  DEC : Enable NaN/Inf
dnl
if test "${GCC}" != "yes" ; then
    case "${host}" in
          *-*-hpux* )
	       CFLAGS="${CFLAGS} -Wp,-H30000"
	       ;;
          *-dec-osf* )
               CFLAGS="${CFLAGS} -ieee"
               ;;
	  alpha*-*-linux* )
	       CFLAGS="${CFLAGS} -ieee"
	       ;;
    esac
else
    if test "$with_fexceptions" = "yes"
    then
        #
	# Not activated by default because this inflates the code size
	# Used to allow propagation of C++ exceptions through the library
	#
	CFLAGS="${CFLAGS} -fexceptions"
    fi
       
    CFLAGS="${CFLAGS} -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls" 
    case "${host}" in
          alpha*-*-linux* )
	       CFLAGS="${CFLAGS} -mieee"
	       ;;
	  alpha*-*-osf* )
	       CFLAGS="${CFLAGS} -mieee"
	       ;;
    esac
fi
case ${host} in
    *-*-solaris*)
        XML_LIBDIR="${XML_LIBDIR} -R${libdir}"
        ;;
    hppa*-hp-mpeix)
        NEED_TRIO=1
	;;
esac


dnl
dnl check for python
dnl

PYTHON=
PYTHON_VERSION=
PYTHON_INCLUDES=
PYTHON_SITE_PACKAGES=
PYTHON_TESTS=
pythondir=
AC_ARG_WITH(python,
[  --with-python[[=DIR]]     build Python bindings if found])
if test "$with_minimum" = "yes" -a "$with_python" = ""
then
    with_python=no
fi
if test "$with_python" != "no" ; then
    if test -x "$with_python/bin/python"
    then
        echo Found python in $with_python/bin/python
        PYTHON="$with_python/bin/python"
    else
	if test -x "$with_python"
	then
	    echo Found python in $with_python
	    PYTHON="$with_python"
	else
	    AC_PATH_PROG(PYTHON, python python2.3 python2.2 python2.1 python2.0 python1.6 python1.5)
	fi
    fi
    if test "$PYTHON" != ""
    then
        PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
	echo Found Python version $PYTHON_VERSION
    fi
    if test "$PYTHON_VERSION" != ""
    then
	if test -r $with_python/include/python$PYTHON_VERSION/Python.h -a \
	   -d $with_python/lib/python$PYTHON_VERSION/site-packages
	then
	    PYTHON_INCLUDES=$with_python/include/python$PYTHON_VERSION
	    PYTHON_SITE_PACKAGES=$with_python/lib/python$PYTHON_VERSION/site-packages
	else
	    if test -r $prefix/include/python$PYTHON_VERSION/Python.h
	    then
	        PYTHON_INCLUDES='$(prefix)/include/python$(PYTHON_VERSION)'
		PYTHON_SITE_PACKAGES='$(libdir)/python$(PYTHON_VERSION)/site-packages'
	    else
		if test -r /usr/include/python$PYTHON_VERSION/Python.h
		then
		    PYTHON_INCLUDES=/usr/include/python$PYTHON_VERSION
		    PYTHON_SITE_PACKAGES='$(libdir)/python$(PYTHON_VERSION)/site-packages'
		else
		    echo could not find python$PYTHON_VERSION/Python.h
		fi
	    fi
	    if test ! -d "$PYTHON_SITE_PACKAGES"
	    then
		    PYTHON_SITE_PACKAGES=`$PYTHON -c "from distutils import sysconfig; print sysconfig.get_python_lib()"`
	    fi
	fi
    fi
    if test "$with_python" != ""
    then
        pythondir='$(PYTHON_SITE_PACKAGES)'
    else
        pythondir='$(libdir)/python${PYTHON_VERSION}/site-packages'
    fi
fi
AM_CONDITIONAL(WITH_PYTHON, test "$PYTHON_INCLUDES" != "")
if test "$PYTHON_INCLUDES" != ""
then
    PYTHON_SUBDIR=python
else
    PYTHON_SUBDIR=
fi
AC_SUBST(pythondir)
AC_SUBST(PYTHON_SUBDIR)

dnl
dnl Tester makes use of readline if present
dnl
_cppflags="${CPPFLAGS}"
_ldflags="${LDFLAGS}"

AC_ARG_WITH(readline,
[  --with-readline=DIR     use readline in DIR],[
  if test "$withval" != "no" -a "$withval" != "yes"; then
    RDL_DIR=$withval
    CPPFLAGS="${CPPFLAGS} -I$withval/include"
    LDFLAGS="${LDFLAGS} -L$withval/lib"
  fi
])
if test "$with_minimum" = "yes" -a "$with_readline" = ""
then
    with_readline=no
fi

dnl
dnl specific tests to setup DV's devel environment with debug etc ...
dnl (-Wunreachable-code)
dnl
if [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XML" ]] || \
   [[ "${LOGNAME}" = "veillard" -a "`pwd`" = "/home/veillard/libxml2" ]] || \
   [[ "${LOGNAME}" = "bill" -a "`pwd`" = "/home/bill/gnomecvs/xmltest" ]] || \
   [[ "${LOGNAME}" = "wbrack" -a "`pwd`" = "/Users/wbrack/gnomecvs/xmltest" ]]
   then
    if test "$with_minimum" != "yes"
    then
	if test "${with_mem_debug}" = "" ; then
	    with_mem_debug="yes"
	    with_run_debug="yes"
	fi
	if test "${with_docbook}" = "" ; then
	    with_docbook="yes"
	fi
    fi
    if test "${CC}" = "gcc" ; then
    CFLAGS="-g -O -pedantic -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
    fi
    STATIC_BINARIES="-static"
dnl -Wcast-qual -ansi
else
    STATIC_BINARIES=
fi
AC_SUBST(STATIC_BINARIES)

dnl
dnl Check for trio string functions
dnl

if test "${NEED_TRIO}" = "1" ; then
    echo Adding trio library for string functions
    WITH_TRIO=1
else    
    WITH_TRIO=0
fi
AM_CONDITIONAL(WITH_TRIO_SOURCES, test "${NEED_TRIO}" = "1")
AC_SUBST(WITH_TRIO)

dnl
dnl Allow to enable/disable various pieces
dnl

THREAD_LIBS=""
WITH_THREADS=0
THREAD_CFLAGS=""
TEST_THREADS=""
THREADS_W32=""

AC_ARG_WITH(threads,
[  --with-threads          add multithread support(on)])
if test "$with_minimum" = "yes" -a "$with_threads" = ""
then
    with_threads=no
fi
if test "$with_threads" = "no" ; then
    echo Disabling multithreaded support
else
    echo Enabling multithreaded support

    AC_CHECK_HEADER(pthread.h,
	AC_CHECK_LIB(pthread, pthread_join,[
	   THREAD_LIBS="-lpthread"
	   AC_DEFINE([HAVE_LIBPTHREAD], [], [Define if pthread library is there (-lpthread)])
	   AC_DEFINE([HAVE_PTHREAD_H], [], [Define if <pthread.h> is there])
	   WITH_THREADS="1"]))
    case $host_os in
       *mingw32*) WITH_THREADS="1"
           THREADS_W32="Win32"
	   THREAD_CFLAGS="$THREAD_CFLAGS -DHAVE_WIN32_THREADS"
       ;;
    esac
    if test "$WITH_THREADS" = "1" ; then
	THREAD_CFLAGS="$THREAD_CFLAGS -D_REENTRANT"
	TEST_THREADS="Threadtests"
    fi
fi
AC_ARG_WITH(thread-alloc,
[  --with-thread-alloc     add per-thread memory(off)])
if test "$with_minimum" = "yes" -a "$with_thread_alloc" = ""
then
    with_thread_alloc=no
fi
if test "$with_thread_alloc" = "yes" -a "$WITH_THREADS" = "1" ; then
    THREAD_CFLAGS="$THREAD_CFLAGS -DLIBXML_THREAD_ALLOC_ENABLED"
fi

AC_SUBST(THREAD_LIBS)
AC_SUBST(WITH_THREADS)
AC_SUBST(THREAD_CFLAGS)
AC_SUBST(TEST_THREADS)
AC_SUBST(THREADS_W32)

AC_ARG_WITH(history,
[  --with-history          add history support to xmllint shell(off)])
if test "$with_minimum" = "yes" -a "$with_history" = ""
then
    with_history=no
fi
if test "$with_history" = "yes" ; then
    echo Enabling xmllint shell history
    dnl check for terminal library. this is a very cool solution
    dnl from octave's configure.in
    unset tcap
    for termlib in ncurses curses termcap terminfo termlib; do
	AC_CHECK_LIB(${termlib}, tputs, [tcap="-l$termlib"])
	test -n "$tcap" && break
    done

    AC_CHECK_HEADER(readline/history.h,
	AC_CHECK_LIB(history, append_history,[
	   RDL_LIBS="-lhistory"
	   AC_DEFINE([HAVE_LIBHISTORY], [], [Define if history library is there (-lhistory)])]))
    AC_CHECK_HEADER(readline/readline.h,
	AC_CHECK_LIB(readline, readline,[
	   RDL_LIBS="-lreadline $RDL_LIBS $tcap"
	   AC_DEFINE([HAVE_LIBREADLINE], [], [Define if readline library is there (-lreadline)])], , $tcap))
    if test -n "$RDL_DIR" -a -n "$RDL_LIBS"; then
	CPPFLAGS="$CPPFLAGS -I${RDL_DIR}/include"
	RDL_LIBS="-L${RDL_DIR}/lib $RDL_LIBS"
    else
	CPPFLAGS=${_cppflags}
    fi
    LDFLAGS=${_ldflags}
fi

AC_ARG_WITH(output,
[  --with-output           add the serialization support (on)])
if test "$with_minimum" = "yes" -a "$with_output" = ""
then
    with_output=no
fi
if test "$with_output" = "no" ; then
    echo Disabling serialization/saving support
    WITH_OUTPUT=0
else    
    WITH_OUTPUT=1
fi
AC_SUBST(WITH_OUTPUT)

AC_ARG_WITH(tree,
[  --with-tree             add the DOM like tree manipulation APIs (on)])
if test "$with_minimum" = "yes" -a "$with_tree" = ""
then
    with_tree=no
fi
if test "$with_tree" = "no" ; then
    echo Disabling DOM like tree manipulation APIs
    WITH_TREE=0
else    
    WITH_TREE=1
fi
AC_SUBST(WITH_TREE)

AC_ARG_WITH(ftp,
[  --with-ftp              add the FTP support (on)])
if test "$with_minimum" = "yes" -a "$with_ftp" = ""
then
    with_ftp=no
fi
if test "$with_ftp" = "no" ; then
    echo Disabling FTP support
    WITH_FTP=0
    FTP_OBJ=
else    
    WITH_FTP=1
    FTP_OBJ=nanoftp.o
fi
AC_SUBST(WITH_FTP)
AC_SUBST(FTP_OBJ)

AC_ARG_WITH(http,
[  --with-http             add the HTTP support (on)])
if test "$with_minimum" = "yes" -a "$with_http" = ""
then
    with_http=no
fi
if test "$with_http" = "no" ; then
    echo Disabling HTTP support
    WITH_HTTP=0
    HTTP_OBJ=
else    
    WITH_HTTP=1
    HTTP_OBJ=nanohttp.o
fi
AC_SUBST(WITH_HTTP)
AC_SUBST(HTTP_OBJ)

AC_ARG_WITH(legacy,
[  --with-legacy           add deprecated APIs for compatibility (on)])
if test "$with_minimum" = "yes" -a "$with_legacy" = ""
then
    with_legacy=no
fi
if test "$with_legacy" = "no" ; then
    echo Disabling deprecated APIs
    WITH_LEGACY=0
else    
    WITH_LEGACY=1
fi
AC_SUBST(WITH_LEGACY)

AC_ARG_WITH(reader,
[  --with-reader           add the xmlReader parsing interface (on)])
if test "$with_minimum" = "yes" -a "$with_reader" = ""
then
    with_reader=no
fi
if test "$with_reader" = "no" ; then
    echo Disabling the xmlReader parsing interface
    WITH_READER=0
    READER_TEST=
else    
    WITH_READER=1
    READER_TEST=Readertests
fi
AC_SUBST(WITH_READER)
AC_SUBST(READER_TEST)

AC_ARG_WITH(pattern,
[  --with-pattern           add the xmlPattern selection interface (on)])
if test "$with_minimum" = "yes" -a "$with_pattern" = ""
then
    with_pattern=no
fi
if test "$with_pattern" = "no" ; then
    echo Disabling the xmlPattern parsing interface
    WITH_PATTERN=0
    PATTERN_TEST=
else    
    WITH_PATTERN=1
    PATTERN_TEST=Patterntests
fi
AC_SUBST(WITH_PATTERN)
AC_SUBST(PATTERN_TEST)

AC_ARG_WITH(writer,
[  --with-writer           add the xmlWriter saving interface (on)])
if test "$with_minimum" = "yes" -a "$with_writer" = ""
then
    with_writer=no
fi
if test "$with_writer" = "no" ; then
    echo Disabling the xmlWriter saving interface
    WITH_WRITER=0
#    WRITER_TEST=
else    
    WITH_WRITER=1
#    WRITER_TEST=Writertests
fi
AC_SUBST(WITH_WRITER)
#AC_SUBST(WRITER_TEST)

AC_ARG_WITH(sax1,
[  --with-sax1             add the older SAX1 interface (on)])
if test "$with_minimum" = "yes" -a "$with_sax1" = ""
then
    with_sax1=no
fi
if test "$with_sax1" = "no" ; then
    echo Disabling the older SAX1 interface
    WITH_SAX1=0
    TEST_SAX=
else    
    WITH_SAX1=1
    TEST_SAX=SAXtests
fi
AC_SUBST(WITH_SAX1)
AC_SUBST(TEST_SAX)

AC_ARG_WITH(push,
[  --with-push             add the PUSH parser interfaces (on)])
if test "$with_minimum" = "yes" -a "$with_push" = ""
then
    with_push=no
fi
if test "$with_push" = "no" ; then
    echo Disabling the PUSH parser interfaces
    WITH_PUSH=0
    TEST_PUSH=
else    
    WITH_PUSH=1
    TEST_PUSH="XMLPushtests"
fi
AC_SUBST(WITH_PUSH)
AC_SUBST(TEST_PUSH)

AC_ARG_WITH(html,
[  --with-html             add the HTML support (on)])
if test "$with_minimum" = "yes" -a "$with_html" = ""
then
    with_html=no
fi
if test "$with_html" = "no" ; then
    echo Disabling HTML support
    WITH_HTML=0
    HTML_OBJ=
    TEST_HTML=
else    
    WITH_HTML=1
    HTML_OBJ="HTMLparser.o HTMLtree.o"
    TEST_HTML=HTMLtests
    if test "$with_push" != "no" ; then
        TEST_PHTML=HTMLPushtests
    else
        TEST_PHTML=
    fi
fi
AC_SUBST(WITH_HTML)
AC_SUBST(HTML_OBJ)
AC_SUBST(TEST_HTML)
AC_SUBST(TEST_PHTML)

AC_ARG_WITH(valid,
[  --with-valid            add the DTD validation support (on)])
if test "$with_minimum" = "yes" -a "$with_valid" = ""
then
    with_valid=no
fi
if test "$with_valid" = "no" ; then
    echo Disabling DTD validation support
    WITH_VALID=0
    TEST_VALID=
    TEST_VTIME=
else    
    WITH_VALID=1
    TEST_VALID=Validtests
    TEST_VTIME=VTimingtests
fi
AC_SUBST(WITH_VALID)
AC_SUBST(TEST_VALID)
AC_SUBST(TEST_VTIME)

AC_ARG_WITH(catalog,
[  --with-catalog          add the Catalog support (on)])
if test "$with_minimum" = "yes" -a "$with_catalog" = ""
then
    with_catalog=no
fi
if test "$with_catalog" = "no" ; then
    echo Disabling Catalog support
    WITH_CATALOG=0
    CATALOG_OBJ=
    TEST_CATALOG=
else    
    WITH_CATALOG=1
    CATALOG_OBJ="catalog.o"
    TEST_CATALOG=Catatests
fi
AC_SUBST(WITH_CATALOG)
AC_SUBST(CATALOG_OBJ)
AC_SUBST(TEST_CATALOG)

AC_ARG_WITH(docbook,
[  --with-docbook          add Docbook SGML support (on)])
if test "$with_minimum" = "yes" -a "$with_docbook" = ""
then
    with_docbook=no
fi
if test "$with_docbook" = "no" ; then
    echo Disabling Docbook support
    WITH_DOCB=0
    DOCB_OBJ=
else    
    WITH_DOCB=1
    DOCB_OBJ="DOCBparser.o"
fi
AC_SUBST(WITH_DOCB)
AC_SUBST(DOCB_OBJ)


AC_ARG_WITH(xpath,
[  --with-xpath            add the XPATH support (on)])
if test "$with_minimum" = "yes" -a "$with_xpath" = ""
then
    with_xpath=no
fi
if test "$with_xpath" = "no" ; then
    echo Disabling XPATH support
    with_xptr="no"
    with_c14n="no"
    with_xinclude="no"
    WITH_XPATH=0
    XPATH_OBJ=
    TEST_XPATH=
else    
    WITH_XPATH=1
    XPATH_OBJ=xpath.o
    TEST_XPATH=XPathtests
fi
AC_SUBST(WITH_XPATH)
AC_SUBST(XPATH_OBJ)
AC_SUBST(TEST_XPATH)

AC_ARG_WITH(xptr,
[  --with-xptr             add the XPointer support (on)])
if test "$with_minimum" = "yes" -a "$with_xptr" = ""
then
    with_xptr=no
fi
if test "$with_xptr" = "no" ; then
    echo Disabling XPointer support
    WITH_XPTR=0
    XPTR_OBJ=
    TEST_XPTR=
else    
    WITH_XPTR=1
    XPTR_OBJ=xpointer.o
    TEST_XPTR=XPtrtests
fi
AC_SUBST(WITH_XPTR)
AC_SUBST(XPTR_OBJ)
AC_SUBST(TEST_XPTR)

AC_ARG_WITH(c14n,
[  --with-c14n             add the Canonicalization support (on)])
if test "$with_minimum" = "yes" -a "$with_c14n" = ""
then
    with_c14n=no
fi
if test "$with_c14n" = "no" ; then
    echo Disabling C14N support
    WITH_C14N=0
    C14N_OBJ=
    TEST_C14N=
else    
    WITH_C14N=1
    C14N_OBJ="c14n.c"
    TEST_C14N=C14Ntests
fi
AC_SUBST(WITH_C14N)
AC_SUBST(C14N_OBJ)
AC_SUBST(TEST_C14N)

AC_ARG_WITH(xinclude,
[  --with-xinclude         add the XInclude support (on)])
if test "$with_minimum" = "yes" -a "$with_xinclude" = ""
then
    with_xinclude=no
fi
if test "$with_xinclude" = "no" ; then
    echo Disabling XInclude support
    WITH_XINCLUDE=0
    XINCLUDE_OBJ=
    with_xinclude="no"
    TEST_XINCLUDE=
else    
    WITH_XINCLUDE=1
    XINCLUDE_OBJ=xinclude.o
    TEST_XINCLUDE=XIncludetests
fi
AC_SUBST(WITH_XINCLUDE)
AC_SUBST(XINCLUDE_OBJ)
AC_SUBST(TEST_XINCLUDE)

WITH_ICONV=0
AC_ARG_WITH(iconv,
[  --with-iconv[[=DIR]]      add ICONV support (on)])
if test "$with_minimum" = "yes" -a "$with_iconv" = ""
then
    with_iconv=no
fi
if test "$with_iconv" = "no" ; then
    echo Disabling ICONV support
else
    if test "$with_iconv" != "yes" -a "$with_iconv" != "" ; then
	CPPFLAGS="${CPPFLAGS} -I$with_iconv/include"
	# Export this since our headers include iconv.h
	XML_INCLUDEDIR="${XML_INCLUDEDIR} -I$with_iconv/include"
	ICONV_LIBS="-L$with_iconv/lib"
    fi

    AC_CHECK_HEADER(iconv.h,
	AC_MSG_CHECKING(for iconv)
	AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],[
iconv_t cd = iconv_open ("","");
iconv (cd, NULL, NULL, NULL, NULL);],[
	    AC_MSG_RESULT(yes)
	    WITH_ICONV=1],[
	    AC_MSG_RESULT(no)
	    AC_MSG_CHECKING(for iconv in -liconv)

	    _ldflags="${LDFLAGS}"
	    _libs="${LIBS}"
	    LDFLAGS="${LDFLAGS} ${ICONV_LIBS}"
	    LIBS="${LIBS} -liconv"

	    AC_TRY_LINK([#include <stdlib.h>
#include <iconv.h>],[
iconv_t cd = iconv_open ("","");
iconv (cd, NULL, NULL, NULL, NULL);],[
		AC_MSG_RESULT(yes)
		WITH_ICONV=1
		ICONV_LIBS="${ICONV_LIBS} -liconv"
		LIBS="${_libs}"
		LDFLAGS="${_ldflags}"],[
		AC_MSG_RESULT(no)
		LIBS="${_libs}"
		LDFLAGS="${_ldflags}"])]))
fi
case "$host" in
	*mingw*) M_LIBS=""
	;;
	*) M_LIBS="-lm"
	;;
esac
XML_LIBS="-lxml2 $Z_LIBS $THREAD_LIBS $ICONV_LIBS $M_LIBS $LIBS"
XML_LIBTOOLLIBS="libxml2.la"
AC_SUBST(WITH_ICONV)

WITH_ISO8859X=1
AC_ARG_WITH(iso8859x,
[  --with-iso8859x         add ISO8859X support if no iconv (on)])
if test "$with_minimum" = "yes" -a "$with_iso8859x" = ""
then
    with_iso8859x=no
fi
if test "$WITH_ICONV" != "1" ; then
if test "$with_iso8859x" = "no" ; then
    echo Disabling ISO8859X support
    WITH_ISO8859X=0
fi
fi
AC_SUBST(WITH_ISO8859X)

AC_ARG_WITH(schemas,
[  --with-schemas          add Relax-NG and experimental Schemas support (on)])
if test "$with_minimum" = "yes" -a "$with_schemas" = ""
then
    with_schemas=no
fi
if test "$with_schemas" = "no" ; then
    echo "Disabled Schemas/Relax-NG support"
    WITH_SCHEMAS=0
    TEST_SCHEMAS=
else    
    echo "Enabled Schemas/Relax-NG support"
    WITH_SCHEMAS=1
    TEST_SCHEMAS="Schemastests Relaxtests"
    if test "$PYTHON_INCLUDES" != "" ; then
        PYTHON_TESTS="$PYTHON_TESTS RelaxNGPythonTests SchemasPythonTests"
    fi
    with_regexps=yes
fi
AC_SUBST(WITH_SCHEMAS)
AC_SUBST(TEST_SCHEMAS)

AC_ARG_WITH(regexps,
[  --with-regexps          add Regular Expressions support (on)])
if test "$with_minimum" = "yes" -a "$with_regexps" = ""
then
    with_regexps=no
fi
if test "$with_regexps" = "no" ; then
    echo Disabling Regexps support
    WITH_REGEXPS=0
    TEST_REGEXPS=
else    
    WITH_REGEXPS=1
    TEST_REGEXPS="Regexptests Automatatests"
fi
AC_SUBST(WITH_REGEXPS)
AC_SUBST(TEST_REGEXPS)

AC_ARG_WITH(debug,
[  --with-debug            add the debugging module (on)])
if test "$with_minimum" = "yes" -a "$with_debug" = ""
then
    with_debug=no
fi
if test "$with_debug" = "no" ; then
    echo Disabling DEBUG support
    WITH_DEBUG=0
    DEBUG_OBJ=
    TEST_DEBUG=
else    
    WITH_DEBUG=1
    DEBUG_OBJ=debugXML.o
    TEST_DEBUG=Scripttests
fi
AC_SUBST(WITH_DEBUG)
AC_SUBST(DEBUG_OBJ)
AC_SUBST(TEST_DEBUG)

AC_ARG_WITH(mem_debug,
[  --with-mem-debug        add the memory debugging module (off)])
if test "$with_minimum" = "yes" -a "$with_mem_debug" = ""
then
    with_mem_debug=no
fi
if test "$with_mem_debug" = "yes" ; then
    if test "$with_thread_alloc" = "yes" ; then
        echo Disabling memory debug - cannot use mem-debug with thread-alloc!
	WITH_MEM_DEBUG=0
    else
        echo Enabling memory debug support
        WITH_MEM_DEBUG=1
    fi
else    
    WITH_MEM_DEBUG=0
fi
AC_SUBST(WITH_MEM_DEBUG)

AC_ARG_WITH(run_debug,
[  --with-run-debug        add the runtime debugging module (off)])
if test "$with_minimum" = "yes" -a "$with_run_debug" = ""
then
    with_run_debug=no
fi
if test "$with_run_debug" = "yes" ; then
    echo Enabling runtime debug support
    WITH_RUN_DEBUG=1
else    
    WITH_RUN_DEBUG=0
fi
AC_SUBST(WITH_RUN_DEBUG)

WIN32_EXTRA_LIBADD=
WIN32_EXTRA_LDFLAGS=
case "$host" in
 *-*-mingw*)
 CPPFLAGS="$CPPFLAGS -DWIN32"
 WIN32_EXTRA_LIBADD="-lws2_32"
 WIN32_EXTRA_LDFLAGS="-no-undefined"
 AC_DEFINE([_WINSOCKAPI_],1,[Using the Win32 Socket implementation])
 AC_DEFINE([snprintf],[_snprintf],[Win32 Std C name mangling work-around])
 AC_DEFINE([vsnprintf],[_vsnprintf],[Win32 Std C name mangling work-around])
 ;;
 *-*-cygwin*)
 CYGWIN_EXTRA_LDFLAGS="-no-undefined"
 CYGWIN_EXTRA_PYTHON_LIBADD="-L/usr/lib/python2.3/config -lpython2.3"
 ;;
esac
AC_SUBST(WIN32_EXTRA_LIBADD)
AC_SUBST(WIN32_EXTRA_LDFLAGS)
AC_SUBST(CYGWIN_EXTRA_LDFLAGS)
AC_SUBST(CYGWIN_EXTRA_PYTHON_LIBADD)

AC_SUBST(CPPFLAGS)
AC_SUBST(CFLAGS)
AC_SUBST(XML_CFLAGS)

AC_SUBST(XML_LIBDIR)
AC_SUBST(XML_LIBS)
AC_SUBST(XML_LIBTOOLLIBS)
AC_SUBST(ICONV_LIBS)
AC_SUBST(XML_INCLUDEDIR)
AC_SUBST(HTML_DIR)
AC_SUBST(HAVE_ISNAN)
AC_SUBST(HAVE_ISINF)
AC_SUBST(PYTHON)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(PYTHON_INCLUDES)
AC_SUBST(PYTHON_SITE_PACKAGES)

AC_SUBST(M_LIBS)
AC_SUBST(RDL_LIBS)

dnl for the spec file
RELDATE=`date +'%a %b %e %Y'`
AC_SUBST(RELDATE)
AC_SUBST(PYTHON_TESTS)

rm -f COPYING.LIB COPYING
ln -s Copyright COPYING

# keep on one line for cygwin c.f. #130896
AC_OUTPUT(libxml2.spec:libxml.spec.in Makefile include/Makefile include/libxml/Makefile doc/Makefile doc/examples/Makefile example/Makefile python/Makefile python/tests/Makefile xstc/Makefile include/libxml/xmlversion.h xml2-config libxml-2.0.pc libxml-2.0-uninstalled.pc python/setup.py)

chmod +x xml2-config python/setup.py
