AC_PREREQ(2.59)
AC_INIT(raul, 0.0.0, [drobilla@connect.carleton.ca])
#AC_CONFIG_HEADER([config.h])
AC_CONFIG_SRCDIR([raul/Mutex.h])
AM_INIT_AUTOMAKE

AC_LANG([C++])

#AC_PROG_CXX
AC_TYPE_SIZE_T
AC_PROG_LIBTOOL

AC_HEADER_STDC
AC_TYPE_INT32_T
AC_TYPE_SIZE_T

AC_FUNC_MALLOC
AC_CHECK_FUNCS([strdup strerror])

AC_CHECK_HEADER([pthread.h], [],
	AC_MSG_ERROR([Raul requires POSIX threads.]))

# Check for debugging flag
debug="no"
AC_ARG_ENABLE(debug,
	[AS_HELP_STRING(--enable-debug, [Enable debugging (false)])],
	[debug="$enableval"])
if test "$debug" = "yes"; then
  CFLAGS="-O0 -g -DDEBUG"
  CXXFLAGS="-O0 -g -DDEBUG"
else
  CFLAGS="$CFLAGS -DNDEBUG"
  CXXFLAGS="$CXXFLAGS -DNDEBUG"
fi

# Check for strict flag
strict="no"
AC_ARG_ENABLE(strict,
	[AS_HELP_STRING(--enable-strict, [Enable strict compiler warnings and errors (false)])],
	[strict="$enableval"])
if test "$strict" = "yes"; then
  CFLAGS="$CFLAGS -std=c99 -pedantic -Wall -Wextra -Wconversion -Winit-self"
  CXXFLAGS="$CXXFLAGS -ansi -pedantic -Wall -Wextra -Wconversion -Winit-self"
fi

# Build unit tests?
build_unit_tests="no"
AC_ARG_ENABLE(unit-tests,
	[AS_HELP_STRING(--enable-unit-tests, [Build unit tests (no) - Developers only])],
	[build_unit_tests="$enableval"])
AM_CONDITIONAL(BUILD_TESTS, [test "$build_unit_tests" = "yes"])

# Check for glibmm
PKG_CHECK_MODULES(GLIBMM, glibmm-2.4)

build_smart_pointers="yes"
AC_ARG_ENABLE(smart_pointers,
	[AS_HELP_STRING(--enable-smart_pointers, [Include smart pointers - requires boost (yes)])],
	[ if test x$enable_smart_pointers = xno ; then build_smart_pointers=no ; fi ])
if test "$build_smart_pointers" = "yes"; then
	AC_CHECK_HEADER([boost/shared_ptr.hpp], [],  
		AC_MSG_ERROR([You need the boost headers package (e.g. libboost-dev)]))

	AC_CHECK_HEADER([boost/weak_ptr.hpp], [],  
		AC_MSG_ERROR([You need the boost headers package (e.g. libboost-dev)]))
	
	AC_CHECK_HEADER([boost/utility.hpp], [],  
		AC_MSG_ERROR([You need the boost headers package (e.g. libboost-dev)]))

	AC_SUBST(BOOST_CFLAGS)
	AC_SUBST(BOOST_LIBS)
fi
AM_CONDITIONAL(WITH_BOOST, [test "$build_smart_pointers" = "yes"])

build_jack="yes"
AC_ARG_ENABLE(jack,
	[AS_HELP_STRING(--enable-jack, [Include JACK audio/midi support (yes)])],
	[ if test x$enable_jack = xno ; then build_jack=no ; fi ])
if test "$build_jack" = "yes"; then
	PKG_CHECK_MODULES(JACK, jack >= 0.102.20, [],
		AC_MSG_ERROR([JACK support requires jack (>= 0.102.20)]))
fi
AM_CONDITIONAL(WITH_JACK, [test "$build_jack" = "yes"])

build_raptor="yes"
AC_ARG_ENABLE(raptor,
	[AS_HELP_STRING(--enable-raptor, [Include Raptor (RDF) serialization support (yes)])],
	[ if test x$enable_raptor = xno ; then build_raptor=no ; fi ])
if test "$build_raptor" = "yes"; then
	PKG_CHECK_MODULES(RAPTOR, raptor >= 1.4.0, [],
		AC_MSG_ERROR([RDF support requires raptor (>= 1.4.0)]))
fi
AM_CONDITIONAL(WITH_RAPTOR, [test "$build_raptor" = "yes"])

build_rasqal="yes"
AC_ARG_ENABLE(rasqal,
	[AS_HELP_STRING(--enable-rasqal, [Include Rasqal (RDF Querying) support (yes)])],
	[ if test x$enable_rasqal = xno ; then build_rasqal=no ; fi ])
if test "$build_rasqal" = "yes"; then
	PKG_CHECK_MODULES(RASQAL, rasqal >= 0.9.11, [],
		AC_MSG_ERROR([RDF query support requires rasqal (>= 0.9.11)]))
fi
AM_CONDITIONAL(WITH_RASQAL, [test "$build_rasqal" = "yes"])

build_liblo="yes"
AC_ARG_ENABLE(liblo,
	[AS_HELP_STRING(--enable-liblo, [Include liblo (OSC) support (yes)])],
	[ if test x$enable_liblo = xno ; then build_liblo=no ; fi ])
if test "$build_liblo" = "yes"; then
	PKG_CHECK_MODULES(LIBLO, liblo >= 0.22, [],
		AC_MSG_ERROR([OSC support requires liblo (>= 0.22)]))
fi
AM_CONDITIONAL(WITH_LIBLO, [test "$build_liblo" = "yes"])

AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([src/Makefile])
AC_CONFIG_FILES([raul/Makefile])
AC_CONFIG_FILES([tests/Makefile])
AC_CONFIG_FILES([doc/Makefile])
AC_CONFIG_FILES([doc/reference.doxygen])
AC_CONFIG_FILES([raul.pc])

AC_OUTPUT

AC_MSG_RESULT([])
AC_MSG_RESULT([**********************************************************************])
AC_MSG_RESULT([Raul build configuration:])
AC_MSG_RESULT([])
AC_MSG_RESULT([Building unit tests: $build_unit_tests])
AC_MSG_RESULT([])
AC_MSG_RESULT([OSC (Liblo) support:                $build_liblo])
AC_MSG_RESULT([RDF Serialization (Raptor) support: $build_raptor])
AC_MSG_RESULT([RDF Querying (Rasqal) support:      $build_rasqal])
AC_MSG_RESULT([Jack support:                       $build_jack])
AC_MSG_RESULT([Smart Pointers (Boost):             $build_smart_pointers])
AC_MSG_RESULT([**********************************************************************])
AC_MSG_RESULT([])