AC_INIT(libxslt/xslt.c)

dnl
dnl libxslt is the main part of the package
dnl libexslt is an extension
dnl
LIBXSLT_MAJOR_VERSION=1
LIBXSLT_MINOR_VERSION=0
LIBXSLT_MICRO_VERSION=14
PACKAGE=libxslt
LIBEXSLT_MAJOR_VERSION=0
LIBEXSLT_MINOR_VERSION=7
LIBEXSLT_MICRO_VERSION=5
LIBXML_REQUIRED_VERSION=2.4.17


LIBXSLT_VERSION=$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION.$LIBXSLT_MICRO_VERSION
LIBXSLT_VERSION_INFO=`expr $LIBXSLT_MAJOR_VERSION + $LIBXSLT_MINOR_VERSION`:$LIBXSLT_MICRO_VERSION:$LIBXSLT_MINOR_VERSION

LIBXSLT_VERSION_NUMBER=`expr $LIBXSLT_MAJOR_VERSION \* 10000 + $LIBXSLT_MINOR_VERSION \* 100 + $LIBXSLT_MICRO_VERSION`

AC_SUBST(LIBXSLT_MAJOR_VERSION)
AC_SUBST(LIBXSLT_MINOR_VERSION)
AC_SUBST(LIBXSLT_MICRO_VERSION)
AC_SUBST(LIBXSLT_VERSION)
AC_SUBST(LIBXSLT_VERSION_INFO)
AC_SUBST(LIBXSLT_VERSION_NUMBER)

dnl
dnl libexslt is an extension library
dnl

LIBEXSLT_VERSION=$LIBEXSLT_MAJOR_VERSION.$LIBEXSLT_MINOR_VERSION.$LIBEXSLT_MICRO_VERSION
LIBEXSLT_VERSION_INFO=`expr $LIBEXSLT_MAJOR_VERSION + $LIBEXSLT_MINOR_VERSION`:$LIBEXSLT_MICRO_VERSION:$LIBEXSLT_MINOR_VERSION

LIBEXSLT_VERSION_NUMBER=`expr $LIBEXSLT_MAJOR_VERSION \* 10000 + $LIBEXSLT_MINOR_VERSION \* 100 + $LIBEXSLT_MICRO_VERSION`

AC_SUBST(LIBEXSLT_MAJOR_VERSION)
AC_SUBST(LIBEXSLT_MINOR_VERSION)
AC_SUBST(LIBEXSLT_MICRO_VERSION)
AC_SUBST(LIBEXSLT_VERSION)
AC_SUBST(LIBEXSLT_VERSION_INFO)
AC_SUBST(LIBEXSLT_VERSION_NUMBER)

dnl
dnl libxsltbreakpoint is a compatibility obsoleted library
dnl it's blocked at 1.0.8 and should be removed in default build in the
dnl future
dnl

LIBXSLTBREAK_MAJOR_VERSION=1
LIBXSLTBREAK_MINOR_VERSION=0
LIBXSLTBREAK_MICRO_VERSION=8

LIBXSLTBREAK_VERSION=$LIBXSLTBREAK_MAJOR_VERSION.$LIBXSLTBREAK_MINOR_VERSION.$LIBXSLTBREAK_MICRO_VERSION
LIBXSLTBREAK_VERSION_INFO=`expr $LIBXSLTBREAK_MAJOR_VERSION + $LIBXSLTBREAK_MINOR_VERSION`:$LIBXSLTBREAK_MICRO_VERSION:$LIBXSLTBREAK_MINOR_VERSION

LIBXSLTBREAK_VERSION_NUMBER=`expr $LIBXSLTBREAK_MAJOR_VERSION \* 10000 + $LIBXSLTBREAK_MINOR_VERSION \* 100 + $LIBXSLTBREAK_MICRO_VERSION`

AC_SUBST(LIBXSLTBREAK_MAJOR_VERSION)
AC_SUBST(LIBXSLTBREAK_MINOR_VERSION)
AC_SUBST(LIBXSLTBREAK_MICRO_VERSION)
AC_SUBST(LIBXSLTBREAK_VERSION)
AC_SUBST(LIBXSLTBREAK_VERSION_INFO)
AC_SUBST(LIBXSLTBREAK_VERSION_NUMBER)




VERSION=${LIBXSLT_VERSION}

AM_CONFIG_HEADER(config.h)
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)
AM_MAINTAINER_MODE

AC_ARG_WITH(html-dir, [  --with-html-dir=PATH path to installed docs ])

dnl
dnl Specific dir for HTML output ?
dnl

if test "x$with_html_dir" = "x" ; then
  HTML_DIR='$(prefix)/doc'
else
  HTML_DIR=$with_html_dir
fi
AC_SUBST(HTML_DIR)

dnl
dnl Check the environment
dnl

AC_ISC_POSIX
AC_PROG_CC
AC_STDC_HEADERS
AC_ARG_PROGRAM
AM_PROG_LIBTOOL

dnl
dnl Math detection
dnl

AC_CHECK_HEADERS(sys/types.h sys/time.h stdlib.h unistd.h string.h)
AC_CHECK_HEADERS(ieeefp.h nan.h math.h fp_class.h float.h ansidecl.h)
AC_CHECK_HEADERS(sys/timeb.h time.h sys/stat.h stdarg.h)
AC_CHECK_FUNCS(stat _stat)
AC_CHECK_FUNC(isnan, , AC_CHECK_LIB(m, isnan,
  [M_LIBS="-lm"; AC_DEFINE(HAVE_ISNAN)]))

AC_CHECK_FUNC(isinf, , AC_CHECK_LIB(m, isinf,
  [M_LIBS="-lm"; AC_DEFINE(HAVE_ISINF)]))

AC_CHECK_FUNC(pow, , AC_CHECK_LIB(m, pow,
  [M_LIBS="-lm"; AC_DEFINE(HAVE_POW)]))

AC_CHECK_FUNC(floor, , AC_CHECK_LIB(m, floor,
  [M_LIBS="-lm"; AC_DEFINE(HAVE_FLOOR)]))

AC_CHECK_FUNC(fabs, , AC_CHECK_LIB(m, fabs,
  [M_LIBS="-lm"; AC_DEFINE(HAVE_FABS)]))
AC_CHECK_FUNCS(gettimeofday)
AC_CHECK_FUNCS(mktime localtime asctime time gmtime ftime)

dnl
dnl Perl is just needed for generating some data for XSLtmark
dnl

AC_CHECK_PROG(PERL, perl, perl, false)
AM_CONDITIONAL(WITH_PERL, test "$PERL" != "false")

dnl
dnl check for python
dnl

PYTHON=
PYTHON_VERSION=
PYTHON_INCLUDES=
PYTHON_SITE_PACKAGES=
AC_ARG_WITH(python, [  --with-python[=DIR]    Build Python bindings if found])
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
	AC_PATH_PROG(PYTHON, python python2.2 python2.1 python2.0 python1.6 python1.5)
    fi
    if test "$PYTHON" != ""
    then
        PYTHON_VERSION=`$PYTHON -c "import sys; print sys.version[[0:3]]"`
	echo Found Python version $PYTHON_VERSION
	LIBXML2_PYTHON=`python -c "try : import libxml2 ; print 1
except: print 0"`
	if test "$LIBXML2_PYTHON" = "1"
	then
	    echo Found libxml2-python module
	else
	    echo Missing libxml2-python
	fi
    fi
    if test "$PYTHON_VERSION" != "" -a "$LIBXML2_PYTHON" = "1"
    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='$(prefix)/lib/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='$(prefix)/lib/python$(PYTHON_VERSION)/site-packages'
		else
		    echo could not find python$PYTHON_VERSION/Python.h
		fi
	    fi
	fi
    fi
fi
AM_CONDITIONAL(WITH_PYTHON, test "$PYTHON_INCLUDES" != "")

dnl
dnl Debug for DV (-Wunreachable-code)
dnl
if test "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XSLT" ; then
    if test "${with_mem_debug}" = "" ; then
	with_mem_debug="yes"
    fi
    CFLAGS="-Wall -g -O -ansi -pedantic -W -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 "
fi

AC_ARG_WITH(debug, [  --with-debug            Add the debugging code (on)])
if test "$with_debug" = "no" ; then
    echo Disabling debug support
    WITH_XSLT_DEBUG=0
else    
    WITH_XSLT_DEBUG=1
fi
AC_SUBST(WITH_XSLT_DEBUG)

AC_ARG_WITH(mem_debug, [  --with-mem-debug        Add the memory debugging module (off)])
if test "$with_mem_debug" = "yes" ; then
    echo Enabling memory debug support
    WITH_MEM_DEBUG=1
else    
    WITH_MEM_DEBUG=0
fi
AC_SUBST(WITH_MEM_DEBUG)

dnl 
dnl Is debugger support requested
dnl
AC_ARG_WITH(with_debugger, [  --with-debugger        Add the debugging support (on)])
if test "$with_debugger" = "no" ; then
    echo Disabling debugger
    WITH_DEBUGGER=0
else
    echo Enabling debugger
    WITH_DEBUGGER=1
    AC_DEFINE(WITH_DEBUGGER)
fi
AM_CONDITIONAL(WITH_DEBUGGER, test "${WITH_DEBUGGER}" = "1")
AC_SUBST(WITH_DEBUGGER)

dnl
dnl The following new parameters were added to offer
dnl the ability to specify the location of the libxml
dnl library during linking and compilation.
dnl
dnl original work - Mathieu Lacage 30/03/2000
dnl some tweaking - David Härdeman 30/10/2001
dnl

LIBXML_CONFIG_PREFIX=""
LIBXML_SRC=""

AC_ARG_WITH(libxml-prefix,
        [  --with-libxml-prefix=[PFX]		Specify location of libxml config],
	LIBXML_CONFIG_PREFIX=$withval
)
        
AC_ARG_WITH(libxml-include-prefix,
        [  --with-libxml-include-prefix=[PFX]	Specify location of libxml headers],
        LIBXML_CFLAGS="-I$withval"
)

AC_ARG_WITH(libxml-libs-prefix,
        [  --with-libxml-libs-prefix=[PFX]	Specify location of libxml libs],
        LIBXML_LIBS="-L$withval"
)

AC_ARG_WITH(libxml-src,
	[  --with-libxml-src=[DIR]              For libxml thats not installed yet (sets all three above)],
	LIBXML_SRC="$withval"
)

dnl
dnl where is xml2-config
dnl

AC_SUBST(LIBXML_REQUIRED_VERSION)
AC_MSG_CHECKING(for libxml libraries >= $LIBXML_REQUIRED_VERSION) 
if test "x$LIBXML_CONFIG_PREFIX" != "x"
then
	XML_CONFIG=${LIBXML_CONFIG_PREFIX}/bin/xml2-config
else
	XML_CONFIG=xml2-config
fi

dnl
dnl Override other variables if LIBXML_SRC is set
dnl

if test "x$LIBXML_SRC" != "x"
then
	CWD=`pwd`
	if cd $LIBXML_SRC
	then
		SRC_DIR=`pwd`
		XML_CONFIG=${SRC_DIR}/xml2-config
		LIBXML_CFLAGS="-I${SRC_DIR}/include"
		LIBXML_LIBS="-L${SRC_DIR}"
		cd $CWD
	else
		AC_MSG_ERROR([libxml source dir not found (${LIBXML_SRC}), typo?])
	fi
fi

dnl
dnl make sure xml2-config is executable,
dnl test version and init our variables
dnl

AC_DEFUN(VERSION_TO_NUMBER,
[`$1 | sed -e 's/libxml //' | awk 'BEGIN { FS = "."; } { printf "%d", ([$]1 * 1000 + [$]2) * 1000 + [$]3;}'`])
if ${XML_CONFIG} --libs print > /dev/null 2>&1
then
	XMLVERS=`$XML_CONFIG --version`
	if test VERSION_TO_NUMBER(echo $XMLVERS) -ge VERSION_TO_NUMBER(echo $LIBXML_REQUIRED_VERSION)
	then
		LIBXML_LIBS="$LIBXML_LIBS `$XML_CONFIG --libs`"
		LIBXML_CFLAGS="$LIBXML_CFLAGS `$XML_CONFIG --cflags`"
		AC_MSG_RESULT($XMLVERS found)
	else
		AC_MSG_ERROR(Version $XMLVERS found. You need at least libxml2 $LIBXML_REQUIRED_VERSION for this version of libxslt)
	fi
else
	AC_MSG_ERROR([Could not find libxml2 anywhere, check ftp://xmlsoft.org/.])
fi


AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)

#
# Some fun with prelinking :-(
# try to check if there is already an installed shared lib of the same level
#
INSTALLED_XSLT_LIB=""
if test -d $prefix
then
    shared_xslt_lib="$prefix/lib/libxslt.so.$LIBXSLT_MAJOR_VERSION"
    shared_xslt_la="$prefix/lib/libxslt.la"
    if test -f $shared_xslt_lib -a -f $shared_xslt_la
    then
	INSTALLED_XSLT_LIB="-L$libdir -lxslt"
    fi
fi
AC_SUBST(INSTALLED_XSLT_LIB)

dnl
dnl In build tree I use a static version with memory debug enabled
dnl
if test "${LOGNAME}" = "veillard" -a "`pwd`" = "/u/veillard/XSLT" ; then
    LIBXML_LIBS="../../XML/.libs/libxml2.a -lz"
    DV_LINK="1"
    XSLTPROCDV="xsltproc.dv"
   # PYTHONSODV="libxsltmod.so.dv"
fi

AC_SUBST(XSLTPROCDV)
AC_SUBST(PYTHONSODV)
AC_SUBST(XML_CONFIG)
AC_SUBST(LIBXML_LIBS)
AC_SUBST(LIBXML_CFLAGS)
AC_SUBST(PYTHON)
AC_SUBST(PYTHON_VERSION)
AC_SUBST(PYTHON_INCLUDES)
AC_SUBST(PYTHON_SITE_PACKAGES)

XSLT_LIBDIR='-L${libdir}'

case ${host} in
    *-*-solaris*)
        XSLT_LIBDIR="${XSLT_LIBDIR} -R${libdir}"
	;;
esac

XSLT_INCLUDEDIR='-I${includedir}'
XSLT_LIBS="-lxslt $LIBXML_LIBS $M_LIBS"
EXTRA_LIBS="$LIBXML_LIBS $M_LIBS"

AC_SUBST(XSLT_LIBDIR)
AC_SUBST(XSLT_INCLUDEDIR)
AC_SUBST(EXTRA_LIBS)
AC_SUBST(M_LIBS)
AC_SUBST(XSLT_LIBS)

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


AC_OUTPUT([
Makefile
libxslt.pc
libxslt/Makefile
libxslt/xsltconfig.h
libxslt/xsltwin32config.h
breakpoint/Makefile
libexslt/Makefile
libexslt/exsltconfig.h
xsltproc/Makefile
python/Makefile
python/tests/Makefile
tests/Makefile
tests/docs/Makefile
tests/REC1/Makefile
tests/REC2/Makefile
tests/REC/Makefile
tests/general/Makefile
tests/reports/Makefile
tests/extensions/Makefile
tests/namespaces/Makefile
tests/numbers/Makefile
tests/documents/Makefile
tests/xmlspec/Makefile
tests/multiple/Makefile
tests/XSLTMark/Makefile
tests/docbook/Makefile
tests/exslt/Makefile
tests/exslt/common/Makefile
tests/exslt/functions/Makefile
tests/exslt/math/Makefile
tests/exslt/sets/Makefile
tests/exslt/strings/Makefile
tests/exslt/date/Makefile
doc/Makefile
xslt-config
libxslt.spec
])