dnl $Id: configure.in,v 1.42 2008-07-21 18:51:56 spotspot Exp $
dnl Process this file with autoconf to produce a configure script.

AC_INIT(flam3-animate.c)
AM_CONFIG_HEADER(config.h)
AC_ARG_ENABLE(pthread, [  --enable-pthread        compile FLAM3 with threads enabled (default=yes)])
AC_ARG_ENABLE(atomic_ops, [  --enable-atomic-ops     compile FLAM3 with atom ops enabled (default=yes, independently checks for 32 and 64 bit sizes)])
AM_INIT_AUTOMAKE(flam3,"3.1.1")

AC_CONFIG_MACRO_DIR([m4])

# Save CFLAGS from the environment
save_CFLAGS=$CFLAGS

AC_PROG_CC

CFLAGS=$save_CFLAGS

AC_PROG_INSTALL
AC_PROG_MAKE_SET
AM_DISABLE_SHARED
AC_PROG_LIBTOOL
AC_HEADER_STDC
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_CHECK_LIB([z],[deflateInit_],,[AC_MSG_ERROR([zlib is required.])])
AC_CHECK_LIB([png],[png_write_image],,[AC_MSG_ERROR([The png library is required.])])
AC_CHECK_LIB([xml2],[xmlParseFile],,[AC_MSG_ERROR([The xml2 library is required.])])

AC_CHECK_LIBM
AC_SUBST([LIBM])

if test "${enable_atomic_ops}" = "" ; then
  enable_atomic_ops=yes
fi

if test "${enable_atomic_ops}" = "yes" ; then

  AC_MSG_CHECKING([whether $CC knows 32-bit __sync_bool_compare_and_swap()])
  AC_LANG_CONFTEST([#include <stdint.h>
  int main() { uint32_t a = 4;
  __sync_bool_compare_and_swap(&a, 4, 5); }])
  $CC conftest.c $CFLAGS -o conftest > /dev/null 2> /dev/null
  ret=$?
  rm -f conftest.o conftest
  if test $ret -eq 0 ; then
     AC_DEFINE([HAVE_GCC_ATOMIC_OPS], 1, [Have 32-bit __sync_bool_compare_and_swap() and friends.])
     AC_MSG_RESULT([yes])
  else
     AC_MSG_RESULT([no - try specifying CFLAGS=-march={your_arch}])
  fi

  AC_MSG_CHECKING([whether $CC knows 64-bit __sync_bool_compare_and_swap()])
  AC_LANG_CONFTEST([#include <stdint.h>
  int main() { uint64_t a = 4; __sync_bool_compare_and_swap(&a, 4, 5); }])
  $CC conftest.c $CFLAGS -o conftest > /dev/null 2> /dev/null
  ret=$?
  rm -f conftest.o conftest
  if test $ret -eq 0 ; then
     AC_DEFINE([HAVE_GCC_64BIT_ATOMIC_OPS], 1, [Have 64-bit __sync_bool_compare_and_swap() and friends.])
     AC_MSG_RESULT([yes])
  else
     AC_MSG_RESULT([no - try specifying CFLAGS=-march={your_arch}])
  fi
fi

if test "${enable_pthread}" = "" ; then
  enable_pthread=yes
fi

if test "${enable_pthread}" = "yes" ; then
  AC_CHECK_LIB([pthread],[pthread_create],,[AC_MSG_WARN([Pthread library not found - threads disabled.])])
fi
AC_CHECK_LIB([jpeg],[jpeg_start_compress],,[AC_MSG_ERROR([The jpeg library is required.])])
AC_PATH_PROG(XML2_CONFIG,xml2-config, no, $PATH:/bin:/usr/bin:/usr/local/bin)

if test "$XML2_CONFIG" != "no"
then
   CPPFLAGS="`$XML2_CONFIG --cflags` $CPPFLAGS"
fi

AC_OUTPUT([
Makefile
flam3.pc
])
