dnl Configure system for OpenAmulet - Rodolphe Ortalo
dnl $Id:  $
dnl Process this file with autoconf to produce a configure script.

AC_INIT(header/amulet.h)

dnl === Library package version and name ===
dnl We want the definition of 'PACKAGE' and 'VERSION' macros
AM_INIT_AUTOMAKE(open-amulet,4.3.1)

dnl Use '--enable-maintainer-mode' if you change config. or build files
AM_MAINTAINER_MODE

dnl ========================================================================
dnl Set some defaults

if test "x$CXXFLAGS" = x; then
  CXXFLAGS="-O2"
fi

dnl ========================================================================
dnl Checks for C features first (before selecting C++)

AC_PROG_CC
AC_HEADER_STDC


dnl ========================================================================
dnl Checks for programs and set languages

AC_PROG_CXX
AC_LANG_CPLUSPLUS
AC_PROG_LN_S

dnl Turn off building of static libraries by default due to the
dnl size of the final library and executables. You can turn it
dnl on again with --enable-static.
AM_DISABLE_STATIC
AM_PROG_LIBTOOL

dnl ========================================================================
dnl User selectable options

AC_ARG_ENABLE(release,
[  --disable-release       Build the standard release version (default=enable)],
[case "${enableval}" in
  yes) release=true ;;
  no)  release=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-release) ;;
esac],[release=true])

AM_CONDITIONAL(BUILD_release, test x$release = xtrue)

AC_ARG_ENABLE(develop,
[  --disable-develop       Build the development version (default=enable)],
[case "${enableval}" in
  yes) develop=true ;;
  no)  develop=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-develop) ;;
esac],[develop=true])

AM_CONDITIONAL(BUILD_develop, test x$develop = xtrue)

AC_ARG_ENABLE(ggi,
[  --enable-ggi            Use GEM-on-GGI: EXPERIMENTAL! (default=disable)],
[case "${enableval}" in
  yes) ggi=true ;;
  no)  ggi=false ;;
  *) AC_MSG_ERROR(bad value ${enableval} for --enable-ggi) ;;
esac],[ggi=false])

AM_CONDITIONAL(USE_ggi, test x$ggi = xtrue)

dnl ========================================================================
dnl Checks for libraries

dnl === check for -lX11 ===

AC_PATH_XTRA()

dnl === check for -lm ===

AC_CHECK_LIB(m,cos,math_lib=yes LIBS="$LIBS -lm")

dnl Warn eventually

if test "$math_lib" != yes; then
  AC_MSG_WARN([
   *?*?*?* You need the math. library (-lm) to use OpenAmulet *?*?*?*])
fi

dnl ========================================================================
dnl Checks for header files.

dnl ========================================================================
dnl Checks for typedefs, structures, and compiler characteristics.

AC_MSG_CHECKING([if c++ supports bool])
AC_TRY_COMPILE([],[bool b = true; return false;],[my_res="yes"
],[my_res="no"
AC_DEFINE(NEED_BOOL)])
AC_MSG_RESULT($my_res)

dnl ========================================================================
dnl Checks for library functions.

dnl TODO: See if there are some portability problems in amulet...

dnl Checks if we need a cast for socket functions (Solaris <= 2.5)

AC_MSG_CHECKING([if cast needed for sockets])
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],[short i; send(1, &i, 2, 0);],[my_res="none"
AC_DEFINE(SOCK_BUFFER_CAST,[])
],[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],[short i; send(1, (char*)&i, 2, 0);],[my_res="to char*"
AC_DEFINE(SOCK_BUFFER_CAST,[(char*)])
],AC_MSG_ERROR([Unable to provide suitable net files!]))])
AC_MSG_RESULT($my_res)

dnl ========================================================================
dnl Finally add some flags

dnl Prepare compilation and link flags NOW!
dnl Change (ie: move to Makefile.am) if not needed on Unix someday. ;-)
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
LIBS="$LIBS $X_EXTRA_LIBS $X_LIBS -lX11"

CPPFLAGS="$CPPFLAGS -DGCC -DMEMORY"

AMULET_DEVELOP_FLAGS="-DDEBUG"
AC_SUBST(AMULET_DEVELOP_FLAGS)

dnl ========================================================================
dnl Write output

dnl We don't use a config header file in fact (yet)...
dnl AM_CONFIG_HEADER(config.h)

AC_OUTPUT(
Makefile
header/Makefile
header/amulet/Makefile
header/amulet/impl/Makefile
source/Makefile
source/gem/Makefile
source/gem/X/Makefile
source/gem/ggi/Makefile
source/gem/mac/Makefile
source/gem/win32/Makefile
source/object/Makefile
source/opal/Makefile
source/opal/objects/Makefile
source/inter/Makefile
source/utils/Makefile
source/debug/Makefile
source/widgets/Makefile
source/widgets/objects/Makefile
source/anim/Makefile
source/gesture/Makefile
source/scripting/Makefile
source/net/Makefile
data/Makefile
data/images/Makefile
data/images/scripting/Makefile
test/Makefile
test/gem/Makefile
test/gem/config/Makefile
test/gem/gem.cmu/Makefile
test/object/Makefile
test/opal/Makefile
test/inter/Makefile
test/gesture/Makefile
test/anim/Makefile
test/utils/Makefile
test/widgets/Makefile
test/timing/Makefile
test/net/Makefile
)
