dnl Process this file with autoconf to produce a configure script.
AC_INIT(sid.h)

dnl Use Automake
AM_INIT_AUTOMAKE(resid, 0.13)
LTVERSION=2:1:0

dnl Use C++ for tests.
AC_LANG_CPLUSPLUS

dnl Enable inlining.
AC_ARG_ENABLE(inline,
[  --enable-inline         enable inlining of functions [default=yes]])

if test "$enable_inline" != no; then
  RESID_INLINING=1
  RESID_INLINE=inline
else
  RESID_INLINING=0
  RESID_INLINE=
fi

AC_SUBST(RESID_INLINING)
AC_SUBST(RESID_INLINE)

dnl Checks for programs.
AC_PROG_CXX

dnl Set CXXFLAGS for G++. Use -fno-exceptions if supported.
if test "$GXX" = yes; then
  if test "$ac_test_CXXFLAGS" != set; then
    CXXFLAGS="-g -Wall -O2 -funroll-loops -fomit-frame-pointer -fno-exceptions"
    AC_MSG_CHECKING([whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works])
    AC_TRY_COMPILE([],
                   [int test;],
                   [ AC_MSG_RESULT(yes) ],
                   [ AC_MSG_RESULT(no)
                     CXXFLAGS="-g -Wall -O2 -funroll-loops -fomit-frame-pointer"
                     ])
  fi
fi

AC_PATH_PROG(PERL, perl)

dnl Checks for libraries.

dnl Checks for header files.

dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_SIZEOF(int, 4)

if test $ac_cv_sizeof_int -lt 4; then
  AC_MSG_ERROR([only 32 bit or better CPUs are supported])
fi

AC_CACHE_CHECK([for working bool], ac_cv_cxx_bool,
[AC_TRY_COMPILE(,
[
bool flag;
],
ac_cv_cxx_bool=yes, ac_cv_cxx_bool=no)])

if test $ac_cv_cxx_bool = no; then
  RESID_HAVE_BOOL=0
else
  RESID_HAVE_BOOL=1
fi

AC_SUBST(RESID_HAVE_BOOL)

dnl Checks for library functions.

dnl Libtool

AC_DISABLE_SHARED
AM_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_SUBST(LTVERSION)

AC_ARG_ENABLE(resid-install,
[  --disable-resid-install do not install libresid])
AM_CONDITIONAL(INSTALL_RESID, test x"${enable_resid_install+set}" != xset)

dnl Namespace support
RESID_NAMESPACE=""
AC_ARG_WITH(namespace,
[  --with-namespace=NAMESPACE
                          resid namespace [default=$RESID_NAMESPACE]],
[RESID_NAMESPACE="$withval"]
)

AC_MSG_CHECKING([for ReSID namespace])
AC_MSG_RESULT($RESID_NAMESPACE)
if test "$RESID_NAMESPACE" != ""; then
    RESID_NAMESPACE="#define RESID_NAMESPACE $RESID_NAMESPACE"
fi
AC_SUBST(RESID_NAMESPACE)

AC_OUTPUT(Makefile siddefs.h)
