dnl Process this file with autoconf to produce a configure script.
AC_INIT(xdkcal.c)
AM_INIT_AUTOMAKE(xdkcal,0.9d)
AM_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC

dnl Checks for header files.
AC_PATH_XTRA
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)

CFLAGS="$CFLAGS $X_CFLAGS"
LIBS="$LIBS $X_PRE_LIBS -lX11 $X_EXTRA_LIBS $X_LIBS"

dnl Checks for libraries.
AC_CHECK_LIB(X11, XOpenDisplay,
  [LDFLAGS="$LDFLAGS -lX11"])

AC_CHECK_LIB(Xext, XShapeCombineMask,
  [LDFLAGS="$LDFLAGS -lXext" ; AC_DEFINE(HAVE_LIBXEXT)])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_STRUCT_TM

dnl debug option
AC_MSG_CHECKING(if --enable-debug option specified)
AC_ARG_ENABLE(debug,
        [  --enable-debug          Build a debugging version.],
        [ts_cv_debug="yes"], [ts_cv_debug="no"])
if test "$ts_cv_debug" = yes; then
        AC_DEFINE(DEBUG)
        OPTFLAG=${OPTFLAG-"-g"}
fi
AC_MSG_RESULT($ts_cv_debug)

AC_SUBST(OPTFLAG)
OPTFLAG=${OPTFLAG-"-O"}

dnl Check if X_LOCALE definition is necessary
AC_MSG_CHECKING(need -DX_LOCALE)

AC_TRY_RUN([
#include <stdio.h>
#include <locale.h>

int
main ()
{
  return setlocale (LC_ALL, "${with_locale}") == NULL;
}],
need_x_locale=no,
need_x_locale=yes)
AC_MSG_RESULT($need_x_locale)

if test $need_x_locale = yes; then
  AC_DEFINE(X_LOCALE)
fi

dnl Checks for library functions.
AC_FUNC_STRFTIME
AC_CHECK_FUNCS(mktime regcomp)

AC_OUTPUT([Makefile])
