# Process this file with autoconf to produce a configure script.
AC_INIT([src/goo], [.3])
AC_CONFIG_HEADER([c/config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
GOO_CHECK_EXE_SUFFIX

# Checks for libraries.
GOO_CHECK_GC_LIB

AC_SEARCH_LIBS(log, m, , AC_MSG_ERROR([Unable to find math library]))
AC_SEARCH_LIBS(dlopen, dl, AC_DEFINE(HAVE_DLOPEN, 1), AC_DEFINE(HAVE_DLOPEN, 0))

# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS([errno.h fcntl.h memory.h stdlib.h string.h unistd.h])

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

# Checks for library functions.
AC_FUNC_ALLOCA
AC_FUNC_MMAP
AC_TYPE_SIGNAL
AC_CHECK_FUNCS([ftruncate memset mkdir munmap pow putenv select setenv sqrt strerror])


THREADKIND=no
AC_MSG_CHECKING(for --with-threads)
AC_ARG_WITH(threads, [--with-threads[=DIRECTORY] Compile GOO to support threads], [
AC_MSG_RESULT($withval)
if test -d "$withval"
then LDFLAGS="$LDFLAGS -L$withval"
fi
AC_DEFINE(_REENTRANT)
AC_MSG_CHECKING([whether the compiler supports thread-local variables])
AC_TRY_COMPILE([],
[__thread int testvar;], [
AC_DEFINE(HAVE_THREAD_LOCAL_VARIABLE)
AC_MSG_RESULT([yes])], AC_MSG_RESULT([no]))
AC_CHECK_LIB(pthread, pthread_create, [
AC_DEFINE(WITH_THREADS)
AC_DEFINE(HAVE_POSIX_THREAD)
LIBS="-lpthread $LIBS"
THREADKIND=posix
], [
AC_MSG_ERROR([Unable to find thread library])
])
], AC_MSG_RESULT([no]))
AC_SUBST(THREADKIND)

AC_OUTPUT(Makefile c/Makefile src/Makefile doc/Makefile emacs/Makefile)
