# Configure template for GNU m4.
# Copyright (C) 1991, 1993, 1994, 2004 Free Software Foundation, Inc.
# Process this file with autoconf to produce a configure script.

AC_INIT(src/m4.c)
AC_CONFIG_HEADER(config.h)
AC_ARG_PROGRAM

PRODUCT=m4
VERSION=1.4.2
AC_DEFINE_UNQUOTED(PRODUCT, "$PRODUCT")
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
AC_SUBST(PRODUCT)
AC_SUBST(VERSION)

AC_PROG_AWK
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_MAKE_SET
AC_PROG_RANLIB

AC_AIX
AC_ISC_POSIX
AC_MINIX
fp_C_PROTOTYPES
AC_C_CONST

AC_CHECK_HEADERS(limits.h memory.h siginfo.h string.h unistd.h)
AC_HEADER_STDC
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T

AC_CHECK_FUNCS(mkstemp sigaction sigaltstack sigstack sigvec strerror tmpfile)
AC_FUNC_ALLOCA
AC_FUNC_VPRINTF
AC_REPLACE_FUNCS(strtol)
AC_MSG_CHECKING(ecvt declaration)
AC_EGREP_HEADER(ecvt, stdlib.h,
  [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_EFGCVT, 2)],
  [AC_MSG_RESULT(no); AC_CHECK_FUNCS(ecvt)])

AC_MSG_CHECKING(if stack overflow is detectable)
# Code from Jim Avera <jima@netcom.com>.
# stackovf.c requires:
#  1. Either sigaction with SA_ONSTACK, or sigvec with SV_ONSTACK
#  2. Either sigaltstack or sigstack
#  3. getrlimit, including support for RLIMIT_STACK
use_stackovf=no
if test "$ac_cv_func_sigaction" = yes || test "$ac_cv_func_sigvec" = yes; then
  if test "$ac_cv_func_sigaltstack" = yes || test "$ac_cv_func_sigstack" = yes; then
    AC_TRY_LINK([#include <sys/time.h>
#include <sys/resource.h>
#include <signal.h>],
      [struct rlimit r; int i; getrlimit (RLIMIT_STACK, &r)
#if (!defined(HAVE_SIGACTION) || !defined(SA_ONSTACK)) \
    && (!defined(HAVE_SIGVEC) || !defined(SV_ONSTACK))
choke me		/* SA_ONSTACK and/or SV_ONSTACK are not defined */
#endif],
      use_stackovf=yes)
  fi
fi
AC_MSG_RESULT($use_stackovf)
if test "$use_stackovf" = yes; then
  AC_DEFINE(USE_STACKOVF)
  STACKOVF=stackovf.${U}o
  AC_SUBST(STACKOVF)
  AC_EGREP_HEADER(rlim_t, sys/resource.h, , AC_DEFINE(rlim_t, int))
  AC_EGREP_HEADER(stack_t, signal.h, , AC_DEFINE(stack_t, struct sigaltstack))
  AC_EGREP_HEADER(sigcontext, signal.h, AC_DEFINE(HAVE_SIGCONTEXT))
fi

AC_MSG_CHECKING(if changeword is wanted)
AC_ARG_ENABLE(changeword,
[  --enable-changeword     enable -W and changeword() builtin],
[if test "$enableval" = yes; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(ENABLE_CHANGEWORD)
else
  AC_MSG_RESULT(no)
fi], [AC_MSG_RESULT(no)])

fp_WITH_DMALLOC

AC_OUTPUT(Makefile doc/Makefile lib/Makefile src/Makefile \
checks/Makefile examples/Makefile,
[test -z "$CONFIG_HEADERS" || date > stamp-h])
