# Copyright 2011 Jeffrey Kegler
# This file is part of Marpa::R2.  Marpa::R2 is free software: you can
# redistribute it and/or modify it under the terms of the GNU Lesser
# General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# Marpa::R2 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser
# General Public License along with Marpa::R2.  If not, see
# http://www.gnu.org/licenses/.

dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)

dnl ***********************************
dnl *** include special marpa macros ***
dnl ***********************************

m4_define(marpa_configure_in)

# Making releases:
#   marpa_micro_version += 1;
#   marpa_interface_age += 1;
#   marpa_binary_age += 1;
# if any functions have been added, set marpa_interface_age to 0.
# if backwards compatibility has been broken,
# set marpa_binary_age _and_ marpa_interface_age to 0.
#
m4_define([marpa_major_version], [1])
m4_define([marpa_minor_version], [1])
m4_define([marpa_micro_version], [0])
m4_define([marpa_interface_age], [100])
m4_define([marpa_binary_age],
          [m4_eval(100 * marpa_minor_version + marpa_micro_version)])
m4_define([marpa_version],
          [marpa_major_version.marpa_minor_version.marpa_micro_version])

# libtool version related macros
m4_define([marpa_lt_release], [marpa_major_version.marpa_minor_version])
m4_define([marpa_lt_current],
          [m4_eval(100 * marpa_minor_version + marpa_micro_version - marpa_interface_age)])
m4_define([marpa_lt_revision], [marpa_interface_age])
m4_define([marpa_lt_age], [m4_eval(marpa_binary_age - marpa_interface_age)])
m4_define([marpa_lt_current_minus_age],
          [m4_eval(marpa_lt_current - marpa_lt_age)])

# if the minor version number is odd, then we want debugging.  Otherwise
# we only want minimal debugging support.
m4_define([marpa_debug_default],
          [m4_if(m4_eval(marpa_minor_version % 2), [1], [yes], [minimum])])dnl

AC_INIT([marpa], [marpa_version],
    [http://rt.cpan.org/NoAuth/Bugs.html?Dist=Marpa])

AC_CONFIG_MACRO_DIR([m4])

AM_INIT_AUTOMAKE([foreign])

# Specify a configuration file
AC_CONFIG_HEADERS([config.h])

MARPA_MAJOR_VERSION=marpa_major_version
MARPA_MINOR_VERSION=marpa_minor_version
MARPA_MICRO_VERSION=marpa_micro_version
MARPA_INTERFACE_AGE=marpa_interface_age
MARPA_BINARY_AGE=marpa_binary_age
MARPA_VERSION=marpa_version

AC_SUBST(MARPA_MAJOR_VERSION)
AC_SUBST(MARPA_MINOR_VERSION)
AC_SUBST(MARPA_MICRO_VERSION)
AC_SUBST(MARPA_VERSION)
AC_SUBST(MARPA_INTERFACE_AGE)
AC_SUBST(MARPA_BINARY_AGE)

AC_DEFINE(MARPA_MAJOR_VERSION, [marpa_major_version],
	  [Define to the MARPA major version])
AC_DEFINE(MARPA_MINOR_VERSION, [marpa_minor_version],
	  [Define to the MARPA minor version])
AC_DEFINE(MARPA_MICRO_VERSION, [marpa_micro_version],
	  [Define to the MARPA micro version])
AC_DEFINE(MARPA_INTERFACE_AGE, [marpa_interface_age],
	  [Define to the MARPA interface age])
AC_DEFINE(MARPA_BINARY_AGE, [marpa_binary_age],
	  [Define to the MARPA binary age])

# libtool versioning
LT_RELEASE=marpa_lt_release
LT_CURRENT=marpa_lt_current
LT_REVISION=marpa_lt_revision
LT_AGE=marpa_lt_age
LT_CURRENT_MINUS_AGE=marpa_lt_current_minus_age
AC_SUBST(LT_RELEASE)
AC_SUBST(LT_CURRENT)
AC_SUBST(LT_REVISION)
AC_SUBST(LT_AGE)
AC_SUBST(LT_CURRENT_MINUS_AGE)

dnl declare --enable-* args and collect ac_help strings
AC_ARG_ENABLE(debug,
              AS_HELP_STRING([--enable-debug=@<:@no/minimum/yes@:>@],
                             [turn on debugging @<:@default=marpa_debug_default@:>@]),,
              enable_debug=marpa_debug_default)

LT_INIT([pic-only])

# Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_LN_S

# Checks for header files.
AC_CHECK_HEADERS([inttypes.h stddef.h stdint.h stdlib.h string.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_TYPE_SIZE_T

if test x"$GCC" = xyes; then
  WARNING_CFLAGS="-Wall \
    -Wextra \
    -Wpointer-arith \
    -Wstrict-prototypes \
    -Wwrite-strings \
    -Wdeclaration-after-statement \
    -Wshadow \
    -Winline \
    -Wmissing-declarations \
    -Wconversion \
    -ansi -pedantic"
fi

AC_SUBST(WARNING_CFLAGS)
AC_C_INLINE

PKG_PROG_PKG_CONFIG([0.22])
PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.22.0] )

AC_CONFIG_FILES([Makefile] [marpa.h:marpa.h.in:proto.h.in])
AC_OUTPUT