#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.59)
AC_INIT(librcsc, 1.3.2, akky@users.sourceforge.jp)
AC_CONFIG_SRCDIR([config.h.in])
#AM_CONFIG_HEADER([config.h])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR([config])

# ----------------------------------------------------------
AM_INIT_AUTOMAKE

# it is necessary to check c++ header files.
AC_LANG([C++])

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
#AC_PROG_RANLIB
#AC_PROG_LIBTOOL

# Checks for libraries.
AC_CHECK_LIB([m], [cos],
             [LIBS="-lm $LIBS"],
             [AC_MSG_ERROR([*** -lm not found! ***])])
libz="yes"
AC_CHECK_LIB([z], [deflate],
             [AC_DEFINE([HAVE_LIBZ], [1],
                        [Define to 1 if you have the `z' library (-lz).])
              LIBS="-lz $LIBS"],
             [libz="no"])

# Checks for header files.
AC_CHECK_HEADERS([arpa/inet.h])
AC_CHECK_HEADERS([fcntl.h],
                 break,
                 [AC_MSG_ERROR([*** fcntl.h not found ***])])
AC_CHECK_HEADERS([netinet/in.h],
                 break,
                 [AC_MSG_ERROR([*** netinet/in.h not found ***])])
AC_CHECK_HEADERS([netdb.h],
                 break,
                 [AC_MSG_ERROR([*** netdb.h not found ***])])
AC_CHECK_HEADERS([sys/socket.h],
                 break,
                 [AC_MSG_ERROR([*** sys/socket.h not found ***])])
AC_CHECK_HEADERS([sys/time.h],
                 break,
                 [AC_MSG_ERROR([*** sys/time.h not found ***])])
AC_CHECK_HEADERS([unistd.h],
                 break,
                 [AC_MSG_ERROR([*** unistd.h not found ***])])

AX_BOOST_BASE([1.32.0])
CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS"
LDFLAGS="$LDFLAGS $BOOST_LDFLAGS"

# Checks for types.
AC_CHECK_TYPES(socklen_t,,
               AC_DEFINE(socklen_t, int, [Define missing socklen_t.]), [
#if HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include <sys/socket.h>])

# To avoid WARNING, put AC_PROG_LIBTOOL after AC_CHECK_HEADERS.
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)

# Checks for typedefs, structures, and compiler characteristics.
AC_HEADER_STDBOOL
AC_C_CONST
AC_C_INLINE
##AC_TYPE_INT32_T
AC_TYPE_SIZE_T
AC_HEADER_TIME

# Checks for library functions.
AC_HEADER_STDC
AC_FUNC_MALLOC
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STRTOD
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([floor inet_addr getaddrinfo gethostbyname gettimeofday])
AC_CHECK_FUNCS([memset pow rint select socket sqrt strerror strtol])

# building switches

# librcsc_agent
AC_ARG_ENABLE(agent,
              AC_HELP_STRING([--enable-agent],
                              [build librcsc_agent (default=yes)]))
if test "x$enable_agent" = "xno"; then
#  echo "not build librcsc_agent"
  AM_CONDITIONAL(BUILD_AGENT, [test "1" = "0"])
else
  AC_MSG_NOTICE(build librcsc_agent)
  AM_CONDITIONAL(BUILD_AGENT, [test "1" = "1"])
fi

#example code
AC_SUBST(EXAMPLE)
AC_ARG_ENABLE(example,
              AC_HELP_STRING([--enable-example],
                             [build Example code (default=no)]))
EXAMPLE=""
if test "x$enable_example" = "xyes"; then
  EXAMPLE="test_result_writer test_loader test_gzifstream test_gzofstream test_param"
  echo "build example code"
fi

# check external tools
AC_CHECK_PROG([DOXYGEN], [doxygen], [yes], [no])
AM_CONDITIONAL(DOXYGEN, test x$DOXYGEN = xyes)
AC_CHECK_PROG([HAVE_DOT], [dot], [YES], [NO])

AC_CONFIG_FILES([Doxyfile
                 librcsc.spec
                 Makefile
                 rcsc/Makefile
								 rcsc/ann/Makefile
                 rcsc/geom/Makefile
                 rcsc/gz/Makefile
                 rcsc/monitor/Makefile
                 rcsc/net/Makefile
                 rcsc/param/Makefile
                 rcsc/rcg/Makefile
                 rcsc/util/Makefile
                 rcsc/common/Makefile
                 rcsc/player/Makefile
                 rcsc/action/Makefile
                 rcsc/formation/Makefile
                 rcsc/coach/Makefile
                 rcsc/trainer/Makefile
                 example/Makefile
                 src/Makefile])

AC_OUTPUT
