m4_define([clutk_major_version], [0])
m4_define([clutk_minor_version], [3])
m4_define([clutk_micro_version], [30])

m4_define([clutk_api_version],
          [clutk_major_version.clutk_minor_version])
m4_define([clutk_version],
          [clutk_major_version.clutk_minor_version.clutk_micro_version])

m4_define([clutk_interface_age], [0])
m4_define([clutk_binary_age],
          [m4_eval(100 * clutk_minor_version + clutk_micro_version)])

AC_PREREQ(2.59)

AC_INIT([clutk],
        [clutk_version],
        [https://bugs.launchpad.net/avani])
AC_CONFIG_SRCDIR([clutk/clutk.h])
AC_CONFIG_MACRO_DIR([build/autotools])

AM_CONFIG_HEADER([config.h])

AM_INIT_AUTOMAKE([1.9])

CLUTK_MAJOR_VERSION=clutk_major_version
CLUTK_MINOR_VERSION=clutk_minor_version
CLUTK_MICRO_VERSION=clutk_micro_version
CLUTK_VERSION=clutk_version
AC_SUBST(CLUTK_MAJOR_VERSION)
AC_SUBST(CLUTK_MINOR_VERSION)
AC_SUBST(CLUTK_MICRO_VERSION)
AC_SUBST(CLUTK_VERSION)

m4_define([lt_current],
          [m4_eval(100 * clutk_minor_version + clutk_micro_version - clutk_interface_age)])
m4_define([lt_revision], [clutk_interface_age])
m4_define([lt_age], [m4_eval(clutk_binary_age - clutk_interface_age)])
CLUTK_LT_CURRENT=lt_current
CLUTK_LT_REV=lt_revision
CLUTK_LT_AGE=lt_age
CLUTK_LT_VERSION="$CLUTK_LT_CURRENT:$CLUTK_LT_REV:$CLUTK_LT_AGE"
CLUTK_LT_LDFLAGS="-version-info $CLUTK_LT_VERSION"

AC_SUBST(CLUTK_LT_VERSION)
AC_SUBST(CLUTK_LT_LDFLAGS)

dnl ===========================================================================

# Checks for programs
AC_PROG_CC
AM_PROG_CC_C_O
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])

# Checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h stdlib.h string.h unistd.h])

# Checks for typedefs, structures and compiler charecteristics
AC_C_CONST

# Checks for library functions
AC_FUNC_MALLOC
AC_FUNC_MMAP
AC_CHECK_FUNCS([memset munmap strcasecmp strdup])

AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal])

PKG_CHECK_MODULES(CLUTTER, clutter-x11-1.0 >= 0.1.5)
AC_SUBST(CLUTTER_CFLAGS)
AC_SUBST(CLUTTER_LIBS)

PKG_CHECK_MODULES(CLUTTER_GTK, clutter-gtk-0.10 >= 0.10.0)
AC_SUBST(CLUTTER_GTK_CFLAGS)
AC_SUBST(CLUTTER_GTK_LIBS)

PKG_CHECK_MODULES(CAIRO, cairo >= 1.8.8)
AC_SUBST(CAIRO_CFLAGS)
AC_SUBST(CAIRO_LIBS)

PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.14)
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)

AC_CHECK_LIB(GLEW, glewInit, , AC_MSG_ERROR([GLEW not found]),[])
AC_CHECK_HEADER(GL/glew.h, , AC_MSG_ERROR([glew header files are required]))

dnl ===========================================================================

if test "x$GCC" = "xyes"; then
  GCC_FLAGS="-g -Wall"
fi
AC_SUBST(GCC_FLAGS)

# use strict compiler flags only on development releases
m4_define([maintainer_flags_default], [m4_if(m4_eval(clutk_micro_version % 2), [1], [yes], [no])])
AC_ARG_ENABLE([maintainer-flags],
              [AC_HELP_STRING([--enable-maintainer-flags=@<:@no/yes@:>@],
                              [Use strict compiler flags @<:@default=no@:>@])],
              [],
              [enable_maintainer_flags=maintainer_flags_default])

MAINTAINER_CFLAGS=""
AS_IF([test "x$enable_maintainer_flags" = "xyes" && test "x$GCC" = "xyes"],
      [
        MAINTAINER_CFLAGS="-Werror -Wall -Wcast-align -Wno-uninitialized -Wempty-body -Wformat-security -Winit-self"
      ]
)

AC_SUBST(MAINTAINER_CFLAGS)

dnl = GObject introspection check =============================================

GOBJECT_INTROSPECTION_CHECK([0.6.3])

dnl = GTK Doc Check ===========================================================

GTK_DOC_CHECK([1.8])

dnl =  local install for distcheck and stand-alone running ====================
with_localinstall="no"
AC_ARG_ENABLE(localinstall,
              AS_HELP_STRING([--enable-localinstall],
                             [Install all of the files locally instead of in system directories (for distcheck)]),
              with_localinstall=$enableval,
              with_localinstall=no)

AM_CONDITIONAL([HAVE_LOCALINSTALL], [test "x$with_localinstall" = "xyes"])

dnl ===========================================================================

SHAVE_INIT([build/autotools], [enable])

AC_CONFIG_FILES([
  Makefile
  build/Makefile
  build/autotools/Makefile
  build/autotools/shave-libtool
  build/autotools/shave
  data/Makefile
  data/shaders/Makefile
  clutk/Makefile
  doc/Makefile
  doc/reference/Makefile
  doc/reference/clutk/Makefile
  tests/Makefile
  vapi/Makefile
  clutk.pc
])

AC_OUTPUT

echo ""
echo " Clutk $VERSION"
echo " ==============================="
echo ""
echo " Prefix                   : ${prefix}"
echo " Localinstall             : ${with_localinstall}"
echo ""
echo " Documentation            : ${enable_gtk_doc}"
echo " Build introspection data : ${enable_introspection}"
echo ""
