dnl version 2.52 is required for Cygwin libtool support
AC_PREREQ(2.52)

dnl local vars to hold user's preferences --------------------------------
AC_INIT(source/headers/geos.h)
AC_CANONICAL_SYSTEM

dnl -- JTS_PORT: the version of JTS this release is bound to
JTS_PORT=1.7.1

dnl -- Version info for the CAPI
CAPI_INTERFACE_CURRENT=3
CAPI_INTERFACE_REVISION=0
CAPI_INTERFACE_AGE=2

dnl
dnl -- Release versions / C++ library SONAME will use these
dnl -- encoding ABI break at every release
dnl
VERSION_MAJOR=3
VERSION_MINOR=0
VERSION_PATCH=0rc1
VERSION="$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"

CAPI_VERSION_MAJOR=$(($CAPI_INTERFACE_CURRENT-$CAPI_INTERFACE_AGE))
CAPI_VERSION_MINOR=$CAPI_INTERFACE_AGE
CAPI_VERSION_PATCH=$CAPI_INTERFACE_REVISION
CAPI_VERSION="$CAPI_VERSION_MAJOR.$CAPI_VERSION_MINOR.$CAPI_VERSION_PATCH"

AM_INIT_AUTOMAKE(geos, $VERSION, no-define)
AC_CONFIG_HEADERS(source/headers/config.h)
AM_CONFIG_HEADER(source/headers/geos/platform.h)
AC_PROG_CC

dnl use libtool ----------------------------------------------------------
AC_LIBTOOL_DLOPEN
AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL

dnl check for programs ----------------------------------------------------
AC_PROG_CXX
AC_ISC_POSIX

dnl function checks ------------------------------------------------------
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_MEMCMP
AC_FUNC_STRFTIME
AC_FUNC_VPRINTF
AC_FUNC_ALLOCA
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(ieeefp.h)
AC_CHECK_HEADERS(sys/file.h)
AC_CHECK_FUNCS(strchr memcpy)
AC_HEADER_STAT
AC_STRUCT_TM
AC_TYPE_SIZE_T
AC_C_CONST

dnl --------------------------------------------------------------------
dnl - Check for inline and cassert settings
dnl --------------------------------------------------------------------


AC_ARG_ENABLE(inline, [  --disable-inline    Disable inlining],
	[case "${enableval}" in
		yes) enable_inline=true ;;
		no)  enable_inline=false ;;
		*) AC_MSG_ERROR(bad value ${enableval} for --enable-inline);;
	esac],
	[enable_inline=true]
)

AC_ARG_ENABLE(cassert, [  --disable-cassert   Disable assertion checking],
	[case "${enableval}" in
		yes) enable_cassert=true ;;
		no)  enable_cassert=false ;;
		*) AC_MSG_ERROR(bad value ${enableval} for --enable-cassert);;
	esac],
	[enable_cassert=true]
)

INLINE_FLAGS=
AC_SUBST(INLINE_FLAGS)
if test x"$enable_inline" = xtrue; then
	INLINE_FLAGS="-DGEOS_INLINE"
	CXXFLAGS="$CXXFLAGS $INLINE_FLAGS"
fi

if test x"$enable_cassert" = xfalse; then
	CXXFLAGS="$CXXFLAGS -DNDEBUG"
fi

dnl --------------------------------------------------------------------
dnl - Append default C++ and C flags 
dnl --------------------------------------------------------------------

# Set default CXXFLAGS and CFLAGS if not set by the user
# -pedantic: ISO does not support long long
# we add -Wno-long-long to avoid those messages
CXXFLAGS="${CXXFLAGS} -Wall -ansi -pedantic -Wno-long-long"
CFLAGS="${CFLAGS} -Wall -ansi -pedantic -Wno-long-long"

dnl --------------------------------------------------------------------
dnl - Look for a 64bit integer (do after CFLAGS is set)
dnl --------------------------------------------------------------------

dnl Find a working 64bit integer
PGAC_TYPE_64BIT_INT([int64_t])
if test x"$HAVE_INT64_T_64" = x"no" ; then
  PGAC_TYPE_64BIT_INT([long int])
  if test x"$HAVE_LONG_INT_64" = x"no" ; then
    PGAC_TYPE_64BIT_INT([long long int])
  fi
fi


dnl --------------------------------------------------------------------
dnl - check for swig 
dnl --------------------------------------------------------------------

AC_ARG_ENABLE(swig, [  --disable-swig    Disable build of swig wrappers],
	[case "${enableval}" in
		yes) use_swig=true ;;
		no)  use_swig=false ;;
		*) AC_MSG_ERROR(bad value ${enableval} for --enable-swig) ;;
	esac],
	[use_swig=true]
)

if test x"$use_swig" = xtrue; then
	AC_PROG_SWIG(1.3.28)
	if test x"$SWIG" = x; then
		use_swig=false
	fi
fi

if test x"$use_swig" = xtrue; then
	SWIG_ENABLE_CXX
fi


AM_CONDITIONAL(ENABLE_SWIG, [ test x"$use_swig" = xtrue ])
AC_SUBST(SWIG)

dnl --------------------------------------------------------------------
dnl - check for python 
dnl --------------------------------------------------------------------

AC_ARG_ENABLE(python, [  --enable-python    Enable build of python module],
	[case "${enableval}" in
		yes) use_python=true ;;
		no)  use_python=false ;;
		*) AC_MSG_ERROR(bad value ${enableval} for --enable-python) ;;
	esac],
	[use_python=false]
)

if test x"$use_python" = xtrue; then
	dnl Check for Python 
	SWIG_PYTHON

	if test x"$PYTHON" = "x"; then
		use_python=false
	fi
	
	AC_SUBST(PYTHON)
	AC_SUBST(SWIG_PYTHON_CPPFLAGS)
	AC_SUBST(SWIG_PYTHON_OPT)
fi

AM_CONDITIONAL(ENABLE_PYTHON, [test x"$use_python" = xtrue])


dnl --------------------------------------------------------------------
dnl - check for ruby 
dnl --------------------------------------------------------------------

AC_ARG_ENABLE(ruby, [  --enable-ruby    Enable build of ruby module],
	[case "${enableval}" in
		yes) use_ruby=true ;;
		no)  use_ruby=false ;;
		*) AC_MSG_ERROR(bad value ${enableval} for --enable-ruby) ;;
	esac],
	[use_ruby=false]
)

if test x"$use_ruby" = xtrue; then
	dnl Check for Ruby 
	AC_RUBY_DEVEL

	if test x"$RUBY" = x; then
		use_ruby=false
	fi

fi
AM_CONDITIONAL(ENABLE_RUBY, [ test x"$use_ruby" = xtrue ])


dnl --------------------------------------------------------------------
dnl - check for boost 
dnl --------------------------------------------------------------------

dnl -- AX_BOOST(1.32)
dnl -- if test "x$ax_cv_boost_unit_test_framework" = "xyes"; then
dnl -- 	use_boost_utf=yes
dnl -- else
dnl -- 	use_boost_utf=no
dnl -- fi
dnl -- AM_CONDITIONAL(ENABLE_BOOST_UTF, [test "x$use_boost_utf" = "xyes"])

dnl things to substitute in output ----------------------------------------
AC_SUBST(VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH INTERFACE_CURRENT INTERFACE_REVISION INTERFACE_AGE JTS_PORT CAPI_VERSION CAPI_VERSION_MAJOR CAPI_VERSION_MINOR CAPI_VERSION_PATCH CAPI_INTERFACE_CURRENT CAPI_INTERFACE_REVISION CAPI_INTERFACE_AGE)

dnl output stuff ----------------------------------------------------------

AC_OUTPUT([
	Makefile 
	capi/Makefile
	capi/geos_c.h
	doc/Doxyfile
	doc/Makefile
	macros/Makefile
	source/Makefile 
	source/algorithm/Makefile
	source/geom/Makefile
	source/geom/util/Makefile
	source/geomgraph/Makefile
	source/geomgraph/index/Makefile
	source/headers/Makefile
	source/headers/geos/Makefile
	source/headers/geos/algorithm/Makefile
	source/headers/geos/geom/Makefile
	source/headers/geos/geom/util/Makefile
	source/headers/geos/geomgraph/Makefile
	source/headers/geos/geomgraph/index/Makefile
	source/headers/geos/index/Makefile
	source/headers/geos/index/bintree/Makefile
	source/headers/geos/index/chain/Makefile
	source/headers/geos/index/quadtree/Makefile
	source/headers/geos/index/strtree/Makefile
	source/headers/geos/index/sweepline/Makefile
	source/headers/geos/io/Makefile
	source/headers/geos/noding/Makefile
	source/headers/geos/noding/snapround/Makefile
	source/headers/geos/operation/Makefile
	source/headers/geos/operation/buffer/Makefile
	source/headers/geos/operation/distance/Makefile
	source/headers/geos/operation/linemerge/Makefile
	source/headers/geos/operation/overlay/Makefile
	source/headers/geos/operation/polygonize/Makefile
	source/headers/geos/operation/predicate/Makefile
	source/headers/geos/operation/relate/Makefile
	source/headers/geos/operation/valid/Makefile
	source/headers/geos/planargraph/Makefile
	source/headers/geos/planargraph/algorithm/Makefile
	source/headers/geos/precision/Makefile
	source/headers/geos/simplify/Makefile
	source/headers/geos/util/Makefile
	source/headers/geos/version.h
	source/index/Makefile
	source/index/bintree/Makefile
	source/index/chain/Makefile
	source/index/quadtree/Makefile
	source/index/strtree/Makefile
	source/index/sweepline/Makefile
	source/io/Makefile
	source/noding/Makefile
	source/noding/snapround/Makefile
	source/operation/Makefile
	source/operation/buffer/Makefile
	source/operation/distance/Makefile
	source/operation/linemerge/Makefile
	source/operation/overlay/Makefile
	source/operation/polygonize/Makefile
	source/operation/predicate/Makefile
	source/operation/relate/Makefile
	source/operation/valid/Makefile
	source/planargraph/Makefile
	source/precision/Makefile
	source/simplify/Makefile
	source/util/Makefile
	swig/Makefile
	swig/python/Makefile
	swig/python/tests/Makefile
	swig/ruby/Makefile
	swig/ruby/test/Makefile
	tests/Makefile
	tests/bigtest/Makefile
	tests/unit/Makefile
	tests/tut/Makefile
	tests/xmltester/Makefile
	tools/Makefile
	tools/geos-config
	])



dnl -- echo "---------------------------------------"
dnl -- echo "Boost UTF: $use_boost_utf"
echo "Swig: $use_swig"
echo "Python: $use_python"
echo "Ruby: $use_ruby"
dnl -- echo "---------------------------------------"

