dnl Run `aclocal' to create macro file (if missing).
dnl Run `automake -a -c -i' to copy macro files (if missing).
dnl Run `autoconf' to create `configure' script.

AC_INIT(src/sidtune.cpp)
AC_CONFIG_AUX_DIR(scripts)
AM_INIT_AUTOMAKE(libsidplay, 1.36.54)
LIBVERSION=1:3:0
AC_SUBST(LIBVERSION)dnl libtool-style version

AC_CANONICAL_HOST
AC_PREFIX_DEFAULT(/usr)

AC_PROG_CXX
AC_LANG_CPLUSPLUS

dnl Check whether the compiler has bool.
SID_CHECK_BOOL

dnl Check for nothrow allocator.
SID_CHECK_EXCEPTIONS

dnl Check whether ios::binary is ios::bin.
SID_CHECK_IOS_BIN

AC_C_BIGENDIAN
if test $ac_cv_c_bigendian = yes; then
    SID_SUBST(SID_WORDS_ENDIANESS,SID_WORDS_BIGENDIAN)
else
    SID_SUBST(SID_WORDS_ENDIANESS,SID_WORDS_LITTLEENDIAN)
fi  
  
AC_CHECK_SIZEOF(char)
AC_CHECK_SIZEOF(short int)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long int)

dnl SID_SUBST(SID_SIZEOF_CHAR,$ac_cv_sizeof_char)
dnl SID_SUBST(SID_SIZEOF_SHORT_INT,$ac_cv_sizeof_short_int)
dnl SID_SUBST(SID_SIZEOF_INT,$ac_cv_sizeof_int)
dnl SID_SUBST(SID_SIZEOF_LONG_INT,$ac_cv_sizeof_long_int)

if test $ac_cv_sizeof_long_int -lt 4; then
  AC_MSG_ERROR([platform unsupported: sizeof(long int) < 4]);
fi

AC_HEADER_STDC

AC_CHECK_FUNC(strncasecmp,[SID_SUBST_DEF(SID_HAVE_STRNCASECMP)],
    [SID_SUBST_UNDEF(SID_HAVE_STRNCASECMP)])
AC_CHECK_FUNC(strnicmp,[SID_SUBST_DEF(SID_HAVE_STRNICMP)],
    [SID_SUBST_UNDEF(SID_HAVE_STRNICMP)])
AC_CHECK_FUNC(stricmp,[SID_SUBST_DEF(SID_HAVE_STRICMP)],
    [SID_SUBST_UNDEF(SID_HAVE_STRICMP)])
AC_CHECK_FUNC(strcasecmp,[SID_SUBST_DEF(SID_HAVE_STRCASECMP)],
    [SID_SUBST_UNDEF(SID_HAVE_STRCASECMP)])

AC_CHECK_HEADER(unistd.h,[SID_SUBST_DEF(SID_HAVE_UNISTD_H)],
    [SID_SUBST_UNDEF(SID_HAVE_UNISTD_H)])
AC_CHECK_HEADER(sys/stat.h,[SID_SUBST_DEF(SID_HAVE_SYS_STAT_H)],
    [SID_SUBST_UNDEF(SID_HAVE_SYS_STAT_H)])
AC_CHECK_HEADER(sys/types.h,[SID_SUBST_DEF(SID_HAVE_SYS_TYPES_H)],
    [SID_SUBST_UNDEF(SID_HAVE_SYS_TYPES_H)])

AC_CHECK_HEADER(sstream,[SID_SUBST_DEF(SID_HAVE_SSTREAM)],
    [SID_SUBST_UNDEF(SID_HAVE_SSTREAM)])

AC_SYS_LONG_FILE_NAMES
if test $ac_cv_sys_long_file_names = yes; then
    SID_SUBST_DEF(SID_HAVE_LONG_FILE_NAMES)
else
    SID_SUBST_UNDEF(SID_HAVE_LONG_FILE_NAMES)
fi

dnl Initialize libtool.
dnl AM_DISABLE_STATIC
SID_PROG_LIBTOOL
AC_SUBST(CXXFLAGS)

AC_ARG_ENABLE(optfixpoint,[  --enable-optfixpoint    whether to optimize fixed-point calculations])
if test "$enable_optfixpoint" = yes; then
    SID_SUBST_DEF(DIRECT_FIXPOINT)
    AC_MSG_WARN([DIRECT_FIXPOINT enabled.])
else
    SID_SUBST_UNDEF(DIRECT_FIXPOINT)
fi
AC_ARG_ENABLE(optendian,[  --enable-optendian      whether to optimize big/little-endian conversion])
if test "$enable_optendian" = yes; then
    SID_SUBST_DEF(OPTIMIZE_ENDIAN_ACCESS)
    AC_MSG_WARN([OPTIMIZE_ENDIAN_ACCESS enabled.])
else
    SID_SUBST_UNDEF(OPTIMIZE_ENDIAN_ACCESS)
fi

AC_OUTPUT(Makefile src/compconf.h src/libcfg.h src/Makefile)

