dnl Process this file with autoconf to produce a configure script for dict.
dnl
dnl Created: Sat Mar  8 15:42:45 1997 by faith@cs.unc.edu
dnl Revised: Sun Jul  5 18:05:55 1998 by faith@acm.org
dnl Copyright 1997, 1998 Rickard E. Faith (faith@acm.org)
dnl
dnl This program is free software; you can redistribute it and/or modify it
dnl under the terms of the GNU General Public License as published by the
dnl Free Software Foundation; either version 1, or (at your option) any
dnl later version.
dnl
dnl This program is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License along
dnl with this program; if not, write to the Free Software Foundation, Inc.,
dnl 675 Mass Ave, Cambridge, MA 02139, USA.
dnl
dnl $Id: configure.in,v 1.2 1998/07/05 22:15:12 faith Exp $
dnl
dnl Flag conventions:
dnl     CFLAGS and LDFLAGS should be settable on the make commandline
dnl             for optimization and stripping.
dnl     WCFLAGS and WLDFLAGS are warnings and stuff that we like (e.g., -pipe)
dnl     XTRACFLAGS, XTRALDFLAGS are for things like dmalloc
dnl     LIBOBJS is an automatically-generated list of extra objects we need
dnl These aren't used for libmaa:
dnl     XCFLAGS and XLDFLAGS are for X11
dnl     YCFLAGS is for yacc
dnl     LCFLAGS is for lex

AC_PREREQ(2.1)
AC_REVISION($Revision: 1.2 $)
AC_INIT(dictfmt.c)
AC_CONFIG_HEADER(config.h)

prefix=/usr
datadir=/usr/lib

echo Configuring for dict-misc
echo .

AC_ARG_WITH(cc,
[  --with-cc               with cc (instead of gcc)],
[
if test "x${withval}" = xyes; then
    CC=cc
fi
])

AC_CANONICAL_HOST
AC_PROG_CC
AC_ISC_POSIX

REALCC="$CC"
if test "$CC" = gcc; then
    CFLAGS='-g -O'
    WCFLAGS='-Wall'
else
    CFLAGS='-g'
fi

local_dmalloc=0

case "$host" in
dnl did include: -Winline
*linux*)
    WCFLAGS="$WCFLAGS -pipe -Wwrite-strings -Wpointer-arith -Wcast-align \
        -Wmissing-prototypes -Wshadow -Wnested-externs -Waggregate-return";;
sparc-sun-sunos*)
    WCFLAGS="$WCFLAGS -pipe";;
esac

AC_ARG_WITH(prof,
[  --with-prof             with prof profiling],
[
if test "x${withval}" = xyes; then
    CFLAGS="$CFLAGS -p"
    LDFLAGS="$LDFLAGS -p"
fi
])

AC_ARG_WITH(gprof,
[  --with-gprof            with gprof profiling],
[
if test "x${withval}" = xyes; then
    CFLAGS="$CFLAGS -pg"
    LDFLAGS="$LDFLAGS -pg"
fi
])

AC_ARG_WITH(dmalloc,
[  --with-dmalloc          with Gray Watson's debugging malloc],
[
if test "x${withval}" = xyes; then
    needs_dmalloc=1
    needs_xmalloc=0
fi
])

AC_ARG_WITH(local-dmalloc,
[  --with-local-dmalloc    with dmalloc built in local source tree],
[
if test "x${withval}" = xyes; then
    needs_dmalloc=1
    local_dmalloc=1
    needs_xmalloc=0
fi
])

AC_ARG_WITH(checker,
[  --with-checker          with Checker support (Linux only)],
[
if test "x${withval}" = xyes; then
    REALCC=checkergcc
fi
])

AC_ARG_WITH(efence,
[  --with-efence           with Electric Fence (by Bruce Perens)],
[
if test "x${withval}" = xyes; then
    REALLIBS="$REALLIBS -lefence"
fi
])

AC_ARG_WITH(insure,
[  --with-insure           with Insure support (from ParaSoft Corp.)],
[
if test "x${withval}" = xyes; then
    REALCC=insight
fi
])

AC_ARG_WITH(purify,
[  --with-purify           with Purify support (from Pure, Inc.)],
[
if test "x${withval}" = xyes; then
    REALCC="purify gcc"
fi
])

dnl Checks for programs.
echo Checking for programs

AC_PROG_INSTALL
AC_PROG_LEX
AC_PROG_YACC
AC_PROG_RANLIB
AC_CHECK_PROGS(DICTZIP,dictzip cat)

echo .
echo Checking for libraries

if test "$local_dmalloc" = 0 -a "$needs_dmalloc" = 1; then
    AC_CHECK_LIB(dmalloc,main,
        REALLIBS="$REALLIBS -ldmalloc"
        XTRACFLAGS="-DDMALLOC_FUNC_CHECK",
    local_dmalloc=1)
fi

if test "$local_dmalloc" = 1; then
    AC_MSG_CHECKING(for dmalloc in local source tree)
    if test -d dmalloc; then
        REALLIBS="$REALLIBS -L./dmalloc -ldmalloc"
        XTRACFLAGS="-DDMALLOC_FUNC_CHECK -I./dmalloc"
        XTRAHEADERS="./dmalloc/dmalloc.h"
        subdirs="$subdirs dmalloc"
        AC_MSG_RESULT(./dmalloc)
    else
        AC_MSG_RESULT(no)
    fi
fi

echo .
echo Checking for header files

AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(unistd.h strings.h getopt.h limits.h)

echo .
echo Checking for system constants

AC_C_CONST
AC_C_INLINE

echo .
echo Making output files

CC="$REALCC"
LIBS="$REALLIBS"

AC_CONFIG_SUBDIRS($subdirs)

AC_SUBST(WCFLAGS)
AC_SUBST(WLDFLAGS)
AC_SUBST(XTRACFLAGS)
AC_SUBST(XTRALDFLAGS)
AC_SUBST(XTRAHEADERS)
AC_OUTPUT(Makefile)

date > stamp-h.in
date > stamp-h
echo .
echo Done
