AC_PREREQ(2.50)
AC_INIT(lcm/lcm.h)
AM_CONFIG_HEADER(config.h)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE(lcm, 0.3.1)
AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC
AM_PATH_GLIB_2_0(,,[AC_MSG_ERROR([LCM requires GLib >= 2.0])],gthread)
AC_PATH_PROGS(JAR, [jar])
AC_PATH_PROGS(JAVAC, [javac])

dnl ---------------------------------------------------------------------------
dnl When making a release:
dnl  1. If the library source code has changed at all since the last release,
dnl     then increment REVISION.
dnl  2. If the interface has been changed since the last release, increment
dnl     CURRENT, and set REVISION to 0.
dnl  3. If the interface changes consist solely of additions, increment AGE.
dnl  4. If the interface has removed or changed elements, set AGE to 0.
dnl ---------------------------------------------------------------------------
LIBLCM_AGE=0
LIBLCM_REVISION=8
LIBLCM_CURRENT=1
AC_SUBST(LIBLCM_AGE)
AC_SUBST(LIBLCM_REVISION)
AC_SUBST(LIBLCM_CURRENT)
LIBLCM_VERSION_INFO=$LIBLCM_CURRENT:$LIBLCM_REVISION:$LIBLCM_AGE
AC_SUBST(LIBLCM_VERSION_INFO)

AM_DISABLE_STATIC
AM_PROG_LIBTOOL

# link against the socket and nsl libraries if needed
LIB_SOCKET_NSL

# nanosleep might need special linkage
AC_SEARCH_LIBS([nanosleep], [rt])

# inet_aton might need special linkage
AC_SEARCH_LIBS([inet_aton],[resolv])

dnl ------------------
dnl Python support
dnl ------------------
AC_ARG_WITH(python,
            [AS_HELP_STRING([--without-python],
             [Do not compile lcm-python bindings even if Python is available])],
            [], [with_python=yes])

AS_IF([test "x$with_python" != xno],
      [AC_PYTHON_DEVEL
       AM_PATH_PYTHON([2.3],, [:])
       AM_CONDITIONAL([HAVE_PYTHON], [test "x$pythonexists" = xyes])],
      [AM_CONDITIONAL([HAVE_PYTHON], FALSE)])

pylcmexecdir="$pyexecdir/$PACKAGE"
AC_SUBST(pylcmexecdir)

AC_ARG_WITH(java,
            [AS_HELP_STRING([--without-java],
                [Do not compile lcm-java bindings even if Java is available])],
            [], [with_java=yes])
dnl ------------------
dnl Java support
dnl ------------------
if test "x$with_java" = xno -o "x$JAR" = x -o "x$JAVAC" = x; then
    AC_MSG_WARN([Java support disabled])
else
    JAVA_FOUND="yes"
fi

AM_CONDITIONAL(HAVE_JAVA, test "x$JAVA_FOUND" = "xyes")
java_apiversion="1.0"
jardir="$datadir/java"
AC_SUBST(jardir)
INSTALLED_CLASSPATH=\${jardir}/lcm${apiversion}-${VERSION}.jar
AC_SUBST(INSTALLED_CLASSPATH)
AC_SUBST(java_apiversion)

dnl -------------------------------------------------
dnl Maybe the user doesn't want to build the examples
dnl -------------------------------------------------
AC_ARG_WITH(examples,
            [AS_HELP_STRING([--without-examples], [Do not compile examples])],
            [], [with_examples=yes])
AM_CONDITIONAL(WITH_EXAMPLES,[test "x$with_examples" = xyes])

dnl ---------------------------------------------------------------------------
dnl i18n support
dnl ---------------------------------------------------------------------------
ALL_LINGUAS=""

dnl The gettext domain of the library
GETTEXT_PACKAGE=${PACKAGE}
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[The gettext domain for the library])
AC_SUBST(GETTEXT_PACKAGE)
AM_GNU_GETTEXT([external])
AM_GNU_GETTEXT_VERSION(0.14.3)

AM_ICONV()

GTK_DOC_CHECK([1.4])

dnl ---------------------------------------------------------------------------
dnl Warnings
dnl ---------------------------------------------------------------------------
if test "x$GCC" = "xyes"; then
    AM_CFLAGS="$AM_CFLAGS -g -std=gnu99 -Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_REENTRANT -Wno-unused-parameter -Wno-format-zero-length -Wshadow"
    AC_SUBST(AM_CFLAGS)
fi

AC_OUTPUT([
  Makefile
  lcm/Makefile
  lcm/lcm.pc
  liblcm-test/Makefile
  lcm-logger/Makefile
  lcmgen/Makefile
  lcm-java/Makefile
  lcm-java/lcm-java.pc
  lcm-python/Makefile
  examples/Makefile
  docs/Makefile
  docs/reference/Makefile
  m4/Makefile
  po/Makefile.in
  m4macros/Makefile
])

if test "x$JAVA_FOUND" = "xyes"; then
    JAVA_STR="Enabled"
else
    JAVA_STR="Disabled"
fi

if test "$pythonexists" = "yes"; then
    PYTHON_STR="Enabled"
else
    PYTHON_STR="Disabled"
fi

echo "

Configuration (LCM):

	Source code location:  ${srcdir}
	Compiler:              ${CC}
	Java Support:          ${JAVA_STR}
	Python Support:        ${PYTHON_STR}
"
