#                                               -*- Autoconf -*-
# Process this file with autoconf to produce a configure script.

AC_PREREQ(2.56)
AC_INIT(libsadie, 5.0.rc1, mehldau@earthlink.net)
AM_CONFIG_HEADER([config.h])
AC_CONFIG_SRCDIR([src/control.c])
AM_INIT_AUTOMAKE
AC_DEFINE([SADIE_UNIX], 1,
          [Define as 1 for any flavor of Unix (including Linux and OS X).])

# Checks for programs.
AC_PROG_CC
AC_PROG_LIBTOOL

# Checks for libraries.
AC_CHECK_LIB(m,cos)

# Checks for header files.
AC_PATH_X
AC_HEADER_STDC
AC_CHECK_HEADERS([inttypes.h limits.h math.h setjmp.h stdio.h stdlib.h string.h time.h])

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

# Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MALLOC

# Special check for Debug Malloc support.
AM_WITH_DMALLOC

# Tcl/Tk support.
AC_MSG_CHECKING([whether to support Tcl/Tk])
AC_ARG_WITH([tcltk],
             AC_HELP_STRING([--with-tcltk],
                            [use external libraries for Tcl/Tk support (default yes)]))
AC_MSG_RESULT($with_tcltk)
if test "x$with_tcltk" != "xno" ; then
  AC_CHECK_HEADER([tcl.h], [],
                  [trees_old_CPPFLAGS="${CPPFLAGS}"
                   trees_includedir=`exec echo ${prefix}`/include
                   for tcldir in "${trees_includedir}/tcl8.4" "${oldincludedir}/tcl8.4" "${trees_includedir}/tcl8.3" "${oldincludedir}/tcl8.3" "${trees_includedir}" "${oldincludedir}" ; do
                     CPPFLAGS="${trees_old_CPPFLAGS} -I${tcldir}"
                     unset ac_cv_header_tcl_h
                     AC_MSG_NOTICE([looking for tcl.h in ${tcldir}])
                     AC_CHECK_HEADER([tcl.h], [break], [CPPFLAGS="${trees_old_CPPFLAGS}"])
                   done])
  AC_CHECK_HEADER([tk.h], [],
                  [AC_MSG_ERROR([cannot find the Tk header file])])
  AC_SEARCH_LIBS(Tcl_GetVersion, [tcl8.4 tcl8.3 tcl], [],
                 [AC_MSG_ERROR([cannot find the libtcl library needed for Tcl scripting support])])
  AC_SEARCH_LIBS(Tk_MainEx, [tk8.4 tk8.3 tk], [],
                 [AC_MSG_ERROR([cannot find the libtk library needed for Tk graphics support])])
  AC_DEFINE([SADIE_TCL], 1,
            [Define as 1 to use the libtcl library for Tcl scripting support.])
fi
AM_CONDITIONAL(TCLTK, test "x$with_tcltk" != "xno")

# TIFF support (depends on external libtiff).
AC_MSG_CHECKING([whether to support TIFF files])
AC_ARG_WITH([tiff],
             AC_HELP_STRING([--with-tiff=PATH],
                            [use the libtiff library (at the optional PATH)]))
AC_MSG_RESULT($with_tiff)
if test "x$with_tiff" != "xno" && test "x$with_tiff" != "x"; then
  if test "x$with_tiff" != "xyes"; then
    CPPFLAGS="${CPPFLAGS} -I${with_tiff}/include"
    LDFLAGS="${LDFLAGS} -L${with_tiff}/lib"
  fi
  AC_CHECK_LIB(tiff, TIFFGetVersion, [],
               [AC_MSG_ERROR([cannot find the libtiff library needed for TIFF file support])])
  AC_DEFINE([SADIE_LIBTIFF], 1,
            [Define as 1 to use the libtiff library for TIFF file support.])
fi
AM_CONDITIONAL(TIFF, test "x$with_tiff" != "xno" && test "x$with_tiff" != "x")

# JPEG support (depends on external libjpeg).
AC_MSG_CHECKING([whether to support JPEG files])
AC_ARG_WITH([jpeg],
             AC_HELP_STRING([--with-jpeg=PATH],
                            [use the libjpeg library (at the optional PATH)]))
AC_MSG_RESULT($with_jpeg)
if test "x$with_jpeg" != "xno" && test "x$with_jpeg" != "x"; then
  if test "x$with_jpeg" != "xyes"; then
    CPPFLAGS="${CPPFLAGS} -I${with_jpeg}/include"
    LDFLAGS="${LDFLAGS} -L${with_jpeg}/lib"
  fi
  AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, [],
               [AC_MSG_ERROR([cannot find the libjpeg library needed for JPEG file support])])
  AC_DEFINE([SADIE_LIBJPEG], 1,
            [Define as 1 to use the libjpeg library for JPEG file support.])
fi
AM_CONDITIONAL(JPEG, test "x$with_jpeg" != "xno" && test "x$with_jpeg" != "x")

AC_OUTPUT([Makefile
           src/Makefile])
