dnl
dnl  TinyFugue - programmable mud client
dnl  Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2004, 2005, 2006-2007 Ken Keys
dnl
dnl  TinyFugue (aka "tf") is protected under the terms of the GNU
dnl  General Public License.  See the file "COPYING" for details.
dnl
dnl  DO NOT EDIT THIS FILE.
dnl  Any configuration changes should be made to the unix/Config file.
dnl

AC_REVISION($Id: configure.in,v 35000.61 2007/01/13 23:12:35 kkeys Exp $)

dnl Note: autoconf uses <<EOF, so we use <<END instead.

dnl ### Initialization variables.

AC_INIT(src/tf.h)

SOCKS=''
OTHER_OBJS=""
TFVER=`sed -ne 's/^TFVER=\(.*\)/\1/p' src/vars.mak`
TFVERSION=`sed -n -e '/Fugue version/s/^.*"\(.*\)".*$/\1/p' src/main.c`

AC_CONFIG_HEADER(src/tfconfig.h)

AC_PREFIX_DEFAULT(`
    if test -w /usr/local/bin && test -w /usr/local/share; then
	echo "/usr/local"
    elif uname -s | egrep BeOS >/dev/null 2>&1; then
	# prefix according to Steven Black <steven@be.com>
	echo "$HOME/config"
    else
	echo "$HOME"
    fi
`)

AC_SUBST(TFVERSION)
AC_MSG_NOTICE([Configuring $TFVERSION])

# User installation options
AC_ARG_ENABLE(version,
[  --enable-version        insert version number into names of installed files
                          (equivalent to --program-suffix=\"-${TFVER}\")],
    , enable_version=default)
AC_ARG_ENABLE(symlink,
[  --enable-symlink[=NAME] make a symlink NAME to the executable
                          [NAME=BINDIR/tf]],
    , enable_symlink=default)
AC_ARG_ENABLE(core,
[  --enable-core           enable debugging core files],
    , enable_core=default)

AC_ARG_ENABLE(ssl,
[  --disable-ssl           disable SSL support],
    , enable_ssl=yes)
AC_ARG_ENABLE(getaddrinfo,
[  --enable-getaddrinfo    enable getaddrinfo() (if configure complains)
  --disable-getaddrinfo   disable getaddrinfo() (implies --disable-inet6)],
    , enable_getaddrinfo=default)
AC_ARG_ENABLE(inet6,
[  --disable-inet6         disable IPv6 support],
    , enable_inet6=yes)
AC_ARG_ENABLE(termcap,
[  --disable-termcap       use hardcoded vt100 codes instead of termcap
  --enable-termcap=LIB    enable termcap with library LIB (e.g., "ncurses")
                          (needed only if configure guesses incorrectly)],
    , enable_termcap=default)
AC_ARG_ENABLE(256colors,
[  --disable-256colors     disable 256 color support (may reduce memory use)],
    , enable_256colors=yes)
AC_ARG_ENABLE(mailcheck,
[  --disable-mailcheck     disable mail checking
  --enable-mailcheck=DIR  enable checking for mail in directory DIR
                          (needed only if configure guesses incorrectly)],
    , enable_mailcheck=yes)

# User feature options
AC_ARG_ENABLE(history,
[  --disable-history       disable /recall and other history features],
    , enable_history=yes)
AC_ARG_ENABLE(process,
[  --disable-process       disable /quote and /repeat],
    , enable_process=yes)
AC_ARG_ENABLE(float,
[  --disable-float         disable floating point arithmetic and functions],
    , enable_float=yes)
AC_ARG_ENABLE(widechar,
[  --disable-widechar      disable wide character support (UTF-8)],
    , enable_widechar=yes)

AC_ARG_WITH(incdirs,
[  --with-incdirs=DIRS     search for include files in DIRS])
AC_ARG_WITH(libdirs,
[  --with-libdirs=DIRS     search for libraries in DIRS])
AC_ARG_WITH(inclibdirs,
[  --with-inclibdirs=DIRS  same as --with-incdirs=DIRS --with-libdirs=DIRS])
AC_ARG_WITH(inclibpfx,
[  --with-inclibpfx=DIRS   same, but appends '/include' and '/lib'])
AC_ARG_WITH(incdir) dnl because I never remember if it's singular or plural
AC_ARG_WITH(libdir) dnl because I never remember if it's singular or plural
AC_ARG_WITH(inclibdir) dnl because I never remember if it's singular or plural


# Developer options
# --enable-development implies --enable-core --disable-symlink
AC_ARG_ENABLE(development, , , enable_development=default)
AC_ARG_ENABLE(dmalloc, , , enable_dmalloc=no)

AC_MSG_NOTICE([])

if test "$enable_development" = "default"; then
    if test -d CVS; then
	enable_development=yes
    else
	enable_development=no
    fi
fi

if test "$enable_development" = "yes"; then
    AC_MSG_NOTICE([Development version.])
elif echo $TFVERSION | egrep "alpha" >/dev/null 2>&1; then
cat <<END
This is an alpha version, and so may not be fully tested on some platforms.
With the new features comes the possibility of new bugs.  If you don't want
to deal with this, get the latest stable or gamma version.

END
fi

if test "$enable_core" = "default"; then
    enable_core=$enable_development
fi

if test "$enable_version" = "default"; then
    enable_version=$enable_development
fi

if test "$enable_development" = "yes"; then
    if test "$enable_symlink" = "default"; then
	enable_symlink=no
    fi
    if test -z "${CC}"; then
	AC_CHECK_PROGS(CC, tfcc gcc-anal)
    fi
else
    AC_DEFINE(NDEBUG)
fi

if test "$enable_core" = "yes"; then
    AC_MSG_NOTICE([Core dumps enabled.])
    CFLAGS="${CFLAGS} -g"
    STRIP=":"
else
    AC_MSG_NOTICE([Core dumps disabled.])
    AC_DEFINE(DISABLE_CORE)
fi


dnl XXX option: TTYDRIVER


UNAME=`{ uname -s && uname -v && uname -r || uname -a; } 2>/dev/null`
UNAME=`echo $UNAME`  # remove newlines
AC_SUBST(UNAME)
#AC_CYGWIN

dnl ########### programs ############

AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
dnl XXX STD_C=1, if compiler is standard

dnl XXX
dnl ${CC} ${CCFLAGS} -c symtest.c >symtest.out 2>&1 || {
dnl     echo
dnl     cat symtest.out
dnl     echo
dnl     echo "## The messages above indicate one of these configuration problems:"
dnl     echo "##   1. the compiler is not installed correctly;"
dnl     echo "##   2. you do not have permission to execute the compiler; or"
dnl     echo "##   3. CCFLAGS='${CCFLAGS}' in unix/Config is invalid."
dnl     echo "## In any case, this is a local problem that can only be"
dnl     echo "## solved by you or a system administrator, so don't ask me."
dnl     echo
dnl     exit 1
dnl }

dnl XXX AC_AIX

AC_PROG_MAKE_SET

##if test "$enable_core" = "no"; then
##    AC_CHECK_PROG(STRIP, strip, strip, :)
##fi
AC_SUBST(STRIP)

AC_CHECK_PROG(RANLIB, ranlib, ranlib, :)


dnl ########### compiler characteristics ############

AC_CHECK_SIZEOF(short)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)

if test "$GCC" = "yes"; then
    # gcc may generate a warning for "inline", so use "__inline__" instead.
    AC_MSG_CHECKING([for inline])
    AC_MSG_RESULT([yes])
    AC_DEFINE(inline, __inline__)
else
    AC_C_INLINE
fi


dnl ########### libraries ############

dnl ### Library testing.
dnl # If libfoo.a make references to libbar.a, the order must be "-lfoo -lbar".
dnl # So we test incrementally, building the list from right to left.
dnl # Dynix/ptx needs: -lsocket -linet -lnsl
dnl # SysV needs: -lsocket -lnsl


dnl TF_DIRS(src, dst[, prefix[, suffix]])
AC_DEFUN(TF_DIRS, [
    if test "${$1}" != "no" && test "${$1}" != ""; then
        for dir in ${$1}; do
            $2="${$2} $3${dir}$4"
        done
    fi
])

TF_DIRS(with_incdirs, CPPFLAGS, -I)
TF_DIRS(with_incdir, CPPFLAGS, -I)
TF_DIRS(with_inclibdirs, CPPFLAGS, -I)
TF_DIRS(with_inclibdir, CPPFLAGS, -I)
TF_DIRS(with_inclibpfx, CPPFLAGS, -I, /include)

LIBDIRS=""
TF_DIRS(with_libdirs, LIBDIRS, -L)
TF_DIRS(with_libdir, LIBDIRS, -L)
TF_DIRS(with_inclibdirs, LIBDIRS, -L)
TF_DIRS(with_inclibdir, LIBDIRS, -L)
TF_DIRS(with_inclibpfx, LIBDIRS, -L, /lib)

dnl Must append LIBDIRS to LDFLAGS now so it's present for AC_CHECK_LIB.
dnl (LIBDIRS will not work in the OTHER-LIBRARIES argument of AC_CHECK_LIB
dnl on all platforms since it will _follow_ the -l option for the library
dnl being tested.)
LDFLAGS="$LDFLAGS $LIBDIRS"


AC_SEARCH_LIBS(select, bsd, ,
    AC_MSG_ERROR([TF can not work without select().]))

dnl # gethostbyname may not be in default libraries.
dnl # QNX keeps gethostbyname in lsocket.
AC_SEARCH_LIBS(gethostbyname, bsd nsl_s nsl resolv socket, ,
    AC_MSG_WARN([Host name resolution will not be available.]))

dnl ### If -linet exists, assume we need it.
AC_CHECK_LIB(inet, main)

dnl ### If -lnet exists, assume we need it.
AC_CHECK_LIB(net, main)

dnl ## If we haven't found connect(), look for -lsocket.
dnl ## Note: on IRIX 5, -lsocket exists, but we mustn't use its gethostbyname().
AC_SEARCH_LIBS(connect, socket)


dnl XXX --enable-socks
dnl if test "$enable_socks" != "no" ; then
dnl     # SOCKS uses res_init(), so we need -lresolv if there is one.
dnl     AC_SEARCH_LIBS(res_init, resolv)
dnl     AC_SEARCH_LIBS(XXX, socks5 "-lsocks5 -L/usr/local/lib" \
dnl 	socks "-lsocks -L/usr/local/lib")
dnl     AC_CHECK_HEADERS(socks.h) dnl -I/usr/local/include
dnl     echo "#define SOCKS ${SOCKS}" >&4
dnl     if test -n "$SOCKS_NONBLOCK" ; then
dnl         echo "#define SOCKS_NONBLOCK" >&4
dnl     fi
dnl fi


dnl ### I'm guessing setlocale() is in libintl on some systems, if not in libc.
AC_SEARCH_LIBS(setlocale, intl, ,
    AC_MSG_WARN([Locales will not be supported.]))

dnl ### OpenSSL
if test "$enable_ssl" = "yes"; then
    ok=0
    old_LIBS="$LIBS"
    old_CFLAGS="$CFLAGS"
    old_CPPFLAGS="$CPPFLAGS"
    while true; do
	dnl -lssl needs -lcrypto
	dnl Try in default locations first, then /usr/local/ssl, then try the
        dnl GnuTLS compatibility layer
	LIBS="$LIBS -lssl -lcrypto"
	AC_MSG_CHECKING([for libcrypto and libssl])
	AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([yes]),
	    CFLAGS="$CFLAGS -L/usr/local/ssl/lib";
	    CPPFLAGS="-I/usr/local/ssl/include $CPPFLAGS";
	    AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([/usr/local/ssl]),
		LIBS="$old_LIBS -lgnutls-openssl"
		CFLAGS="$old_CFLAGS"
		CPPFLAGS="$old_CPPFLAGS"
		AC_TRY_LINK_FUNC(SSL_new, AC_MSG_RESULT([gnutls]),
		    AC_MSG_RESULT([no]); break)))
	dnl Red Hat 9 and Yellow Dog Linux have ssl.h in a standard place,
	dnl but it depends on krb5.h which isn't in a standard place.
	AC_MSG_CHECKING(for ssl kerberos dependency)
	if test -r /usr/kerberos/include/krb5.h; then
	    AC_MSG_RESULT([yes])
	    CPPFLAGS="-I/usr/kerberos/include $CPPFLAGS"
	else
	    AC_MSG_RESULT([no])
	fi
	AC_CHECK_HEADER(openssl/ssl.h, ok=1,
	    [AC_CHECK_HEADERS([gnutls/openssl.h], [ok=1])])
	if test "$ok" = "1"; then
	    AC_DEFINE(HAVE_SSL)
            AC_CHECK_FUNCS(ERR_peek_error)
	fi
	break
    done
    if test "$ok" = "0"; then
	AC_MSG_RESULT([ssl support will not be enabled.])
	LIBS="$old_LIBS"
	CFLAGS="$old_CFLAGS"
	CPPFLAGS="$old_CPPFLAGS"
    fi
fi

dnl ### test termcap.
dnl # At least one system (Red Hat Linux) has a broken ncurses and a working
dnl # termcap, so we try termcap before ncurses.

terminal_hardcode="TERM_vt100";

dnl # Cygwin may not have termcap at all, but it only supports ANSI emulation
dnl # anyway, so we hardcode that (unless it was overridden).
if test "$CYGWIN" = "yes"; then
    terminal_hardcode="TERM_ansi";
    if test "$enable_termcap" = "default"; then
	enable_termcap="no";
    fi
fi

if test "$enable_termcap" = "default"; then
    enable_termcap="yes";
fi

if test "$enable_termcap" = "no"; then
    AC_DEFINE_UNQUOTED(HARDCODE, $terminal_hardcode)
else
    if test "$enable_termcap" = "yes"; then enable_termcap=""; fi
    AC_SEARCH_LIBS(tgetent, $enable_termcap termcap ncurses curses,
	AC_DEFINE(TERMCAP)
    ,
	AC_DEFINE_UNQUOTED(HARDCODE, $terminal_hardcode)
	AC_MSG_WARN([Hardcoding terminal codes.]))
fi
dnl XXX check for debian linux's broken termcap


if test "$enable_256colors" = "yes"; then
    AC_DEFINE(NCOLORS, 256)
fi


if test "$enable_float" = "yes"; then
    AC_SEARCH_LIBS(sqrt, m)
fi

if test "$enable_widechar" = "yes"; then
    AC_CHECK_HEADERS(wchar.h wctype.h)
fi

AC_CHECK_LIB(z, inflate)

AC_CHECK_LIB(pcre, pcre_compile, :, [
    AC_MSG_NOTICE([Note: will use old copy of pcre distributed with tf]);
    PCRE=pcre; LDFLAGS="${LDFLAGS} -Lpcre-2.08"; ])
AC_SUBST(PCRE)


dnl ########### headers ############

AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h memory.h sys/select.h)
AC_HEADER_SYS_WAIT

dnl ### For optional language support.
AC_CHECK_HEADERS(locale.h, ,
    AC_MSG_WARN([Locales will not be supported.]))

dnl ### Find pwd.h
AC_CHECK_HEADERS(pwd.h, ,
AC_MSG_WARN([Filename '~user' expansion will not be supported.]))

dnl ### Find zlib.h
AC_CHECK_HEADERS(zlib.h)


dnl TF_SEARCH_HEADERS(SYMBOL, HEADERS... [, DO-IF-FOUND [, DO-IF-NOT-FOUND]])
dnl Searches for each header in HEADERS, and defines SYMBOL to the first one
dnl found.
AC_DEFUN(TF_SEARCH_HEADERS, [
    found=0;
    for f in $2; do
	AC_CHECK_HEADERS($f,
	    AC_DEFINE_UNQUOTED($1, <$f>)
	    found=1
	    break)
	if test $found -eq 1; then break; fi
    done
    if test $found -eq 1; then
	:; $3
    else
	:; $4
    fi
    unset found
])


dnl ### Find internet structure header
TF_SEARCH_HEADERS(NETINET_IN_H, netinet/in.h sys/in.h sys/netinet/in.h, ,
AC_MSG_WARN([I will use my own internet structures.  Good luck.]))

dnl ### Find internet address header
TF_SEARCH_HEADERS(ARPA_INET_H, arpa/inet.h sys/inet.h)

dnl ### Find nameser header
dnl TF_SEARCH_HEADERS(NAMESER_H, arpa/nameser.h nameser.h)

dnl ### Find netdb header
TF_SEARCH_HEADERS(NETDB_H, netdb.h sys/netdb.h, ,
    AC_MSG_ERROR([can't find netdb.h]))

AC_CACHE_CHECK([whether struct sockaddr has sa_len], tf_cv_sa_len,
    AC_TRY_COMPILE([
#include<sys/types.h>
#include <sys/socket.h>],
        [struct sockaddr sa; return sa.sa_len;],
        tf_cv_sa_len=yes,
	tf_cv_sa_len=no))

if test "${tf_cv_sa_len}" = "yes"; then
    AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
fi


dnl ### Figure out which terminal driver to use.

AC_CHECK_HEADERS(termios.h termio.h sgtty.h, break)

dnl # Some brain damaged systems (Xenix) need <sys/ptem.h> for struct winsize.
AC_EGREP_HEADER([struct winsize], sys/ptem.h, AC_DEFINE(NEED_PTEM_H))


dnl ########### typedefs ############

dnl TF_CHECK_TYPE(TYPE, DEFAULT [, OTHER_HEADERS])
dnl ...because AC_CHECK_TYPE doesn't have OTHER_HEADERS
AC_DEFUN(TF_CHECK_TYPE,
[AC_REQUIRE([AC_HEADER_STDC])dnl
AC_MSG_CHECKING(for $1)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_EGREP_CPP(dnl
changequote(<<,>>)dnl
<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
changequote([,]), [
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif
$3
], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
AC_MSG_RESULT($ac_cv_type_$1)
if test $ac_cv_type_$1 = no; then
  AC_DEFINE($1, $2)
fi
])


AC_TYPE_SIGNAL
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_TYPE(time_t, long)
TF_CHECK_TYPE(socklen_t, int, [
#include <sys/types.h>
#include <sys/socket.h>
])


dnl ########### structures ############


dnl ########### functions ############

dnl # SCO keeps strftime() in -lintl
AC_FUNC_STRFTIME

dnl # h_errno is a variable, not a function.  But AC_CHECK_FUNCS only checks
dnl # that the symbol is defined, so this works.
AC_CHECK_FUNCS(h_errno)

dnl # required standard functions
AC_CHECK_FUNCS(strstr strtol, ,
    AC_MSG_ERROR([Missing required standard function.]))
dnl # optional functions
AC_CHECK_FUNCS(bcopy bzero connect fileno getcwd \
    gethostname gethostbyname getipnodebyname \
    getpwnam gettimeofday getwd hstrerror index inet_aton)

if test "$enable_getaddrinfo" = "default"; then
    if test `uname -s` = 'Darwin'; then
	AC_MSG_WARN([getaddrinfo() may be broken, so IPv6 support is disabled.  Use --enable-getaddrinfo to override.])
	enable_getaddrinfo=no
    else
	enable_getaddrinfo=yes
    fi
fi
if test "$enable_getaddrinfo" = "no"; then
    enable_inet6=no
else
    AC_CHECK_FUNCS(getaddrinfo gai_strerror)
fi

AC_CHECK_FUNCS(kill memcpy memset raise setlocale setrlimit sigaction \
    srand srandom \
    strcasecmp strchr strcmpi strcspn strerror stricmp strtod tzset waitpid)

dnl # override a few values
if test "$CYGWIN" = "yes"; then
    AC_DEFINE(HAVE_H_ERRNO, [0  /* h_errno is broken in cygwin32 b18. */])
fi

if test "$enable_inet6" = "yes"; then
    AC_MSG_CHECKING([for IPv6 address structure])
    for type in in6_addr in_addr6; do
	AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>
#include NETINET_IN_H
],
	    [
#ifndef AF_INET6
# error AF_INET6 not defined
#endif
	    struct ${type} foo;
	    ],
	    AC_DEFINE_UNQUOTED(IN6_ADDR, $type)
	    AC_MSG_RESULT([$type])
	    break)
    done
fi


dnl ########### system services ############

dnl # These should come after AC_PROG_CC.
AC_EXEEXT
AC_OBJEXT

dnl ### Find mail directory by looking at $MAIL, then in the usual places.
if test "$enable_mailcheck" = "no"; then
    MAILDIR=""
elif test "$enable_mailcheck" = "yes"; then
    AC_MSG_CHECKING([location of mail directory])
    if test -n "$MAIL" ; then
        # Not every system has dirname.  sigh.
        changequote(, )dnl We need brackets for the regexp.
        MAILDIR=`echo $MAIL | sed 's;/[^/]*$;;'`
        changequote([, ])dnl Restore bracket quotes.
    elif test -d /usr/spool/mail ; then
        MAILDIR="/usr/spool/mail"
    elif test -d /var/spool/mail ; then
        MAILDIR="/var/spool/mail"
    elif test -d /usr/mail ; then
        MAILDIR="/usr/mail"
    elif test -d /var/mail ; then
        MAILDIR="/var/mail"
    else
	MAILDIR=""
    fi
    AC_MSG_RESULT([${MAILDIR-(none)}])
else
    MAILDIR="$enable_mailcheck"
fi
if test -n "$MAILDIR"; then
    AC_DEFINE_UNQUOTED(MAILDIR, "$MAILDIR")
fi


dnl ### Figure out names of executable, library directory, and symlink.

if test "$enable_version" != "no" && test "$program_suffix" = "NONE"; then
    program_suffix="-${TFVER}"
fi

dnl The "right" way of using program_transform_name, program_prefix, and
dnl program_suffix expects you to use AC_ARG_PROGRAM here and do transformation
dnl in the Makefile, but we want the values now, so we do it ourselves.
EXENAME="tf" PROGNAME="tf"
test "${program_prefix}" != "NONE" && EXENAME="${program_prefix}${EXENAME}"
test "${program_suffix}" != "NONE" && EXENAME="${EXENAME}${program_suffix}"
if test "${program_transform_name}" != "NONE"; then
    EXENAME=`echo "${EXENAME}" | sed "${program_transform_name}"`
fi
LIBNAME="${PROGNAME}-lib"

if test "$enable_symlink" = "no"; then
    SYMLINK=""
elif test "$enable_symlink" = "yes"; then
    SYMLINK='${bindir}/tf'
else
    SYMLINK="$enable_symlink"
fi

AC_SUBST(EXENAME)
AC_SUBST(PROGNAME)
AC_SUBST(LIBNAME)
AC_SUBST(SYMLINK)


dnl ### man page

dnl if test "$enable_manpage" = "yes"; then
dnl     MANPAGE='${mandir}/man1/${EXENAME}.1'
dnl     MANTYPE='nroff'
dnl else
dnl     MANPAGE=''
dnl     MANTYPE=''
dnl fi
dnl AC_SUBST(MANPAGE)
dnl AC_SUBST(MANTYPE) dnl XXX


dnl ########### output ############


dnl ########### end ############


dnl # XXX
dnl ### Sanity check for filenames (some people do pretty stupid things)
dnl # The "${SYMLINK}/" is just to make the grep return false if SYMLINK is empty.
dnl #
dnl #if echo "$TF"          | egrep "^[^/]" >/dev/null 2>&1 ||
dnl #   echo "$LIBDIR"      | egrep "^[^/]" >/dev/null 2>&1 ||
dnl #   echo "${SYMLINK}/"  | egrep "^[^/]" >/dev/null 2>&1
dnl #then
dnl #   echo "Don't install files with relative paths or '~'."
dnl #   echo "Edit unix/Config and try again."
dnl #   exit 2
dnl #fi
dnl #
dnl ## Don't allow installation in the build tree (people have actually tried this).
dnl ## The cd;pwd is needed to normalize the directory name in case of links, etc.
dnl #
dnl #DIR1=`echo $TF      | sed 's;/[^/]*$;;'`
dnl #DIR1=`cd $DIR1 && pwd`
dnl #DIR2=`echo $LIBDIR  | sed 's;/[^/]*$;;'`
dnl #DIR2=`cd $DIR2 && pwd`
dnl #DIR3=`echo $SYMLINK | sed 's;/[^/]*$;;'`
dnl #DIR3=`cd $DIR3 && pwd`
dnl #
dnl #if test -z "$DIR1"  || test -z "$DIR2"  || test -z "$DIR3" ; then
dnl #    echo "Error in directory."
dnl #    exit 1;
dnl #fi
dnl #
dnl #DIR1=`cd $DIR1 && pwd || { echo "Error in directory $DIR1."; false; }`
dnl #
dnl #BUILDTREE=`cd .. && pwd`
dnl #if echo "${DIR1}/" | egrep "^${BUILDTREE}/" >/dev/null 2>&1 ||
dnl #   echo "${DIR2}/" | egrep "^${BUILDTREE}/" >/dev/null 2>&1 ||
dnl #   echo "${DIR3}/" | egrep "^${BUILDTREE}/" >/dev/null 2>&1
dnl #then
dnl #    echo
dnl #    echo 'You can not install files in the build tree,'
dnl #    echo "${BUILDTREE}."
dnl #    echo 'Edit unix/Config and try again.'
dnl #    exit 2
dnl #fi
dnl #
dnl # Too many people have renamed the distribution directory to "$HOME/tf", and
dnl # then wondered why they couldn't install the executable as "$HOME/tf".
dnl #if test -d "${TF}" ; then
dnl #    echo "\"${TF}\" is a directory; you can not install the executable"
dnl #    echo 'with the same name.  Either rename the directory, or choose a'
dnl #    echo 'different name for the executable.'
dnl #    exit 1
dnl #fi


MODE=755
AC_SUBST(MODE)




dnl ### Make sure the PATH is sane.
dnl # Ideally, this should be done before the compiler check.  But a compiler
dnl # found now in the extended PATH won't be found in src/Makefile, because it
dnl # won't inherit this PATH.
PATH="$PATH:/bin:/usr/bin:/usr/local/bin:/usr/ucb:/usr/local:/usr/lbin:/etc:/usr/new:/usr/new/bin:/usr/nbin:/usr/ccs/bin"


if test "$enable_dmalloc" = "yes"; then
    CPPFLAGS="$CPPFLAGS -DUSE_DMALLOC"
    OTHER_OBJS="$OTHER_OBJS dmalloc.o"
fi

dnl ### write variables

if test "$enable_inet6"   = "yes"; then AC_DEFINE(ENABLE_INET6)  fi
if test "$enable_history" = "no"; then AC_DEFINE(NO_HISTORY)  fi
if test "$enable_process" = "no"; then AC_DEFINE(NO_PROCESS)  fi
if test "$enable_float"   = "no"; then AC_DEFINE(NO_FLOAT)    fi
if test "$enable_widechar" = "yes"; then AC_DEFINE(WIDECHAR)   fi

CPPFLAGS="${CPPFLAGS} -DDATADIR=\${datadir}"
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LIBS)
AC_SUBST(OTHER_OBJS)

AC_OUTPUT(Makefile unix/vars.mak src/tfdefs.h, [

### Create src/Makefile from pieces.

cat >src/Makefile <<END
#### DO NOT EDIT THIS FILE.
#### This src/Makefile was automatically generated by configure.  The correct
#### installation precedure is to run ./configure in the top directory.  You
#### should not edit this file; all configuration changes should be made
#### via arguments to configure.

END
cat unix/vars.mak src/vars.mak unix/unix.mak src/rules.mak >> src/Makefile
])

AC_MSG_NOTICE([
#####################################################
## prefix: $prefix
## exec_prefix: $exec_prefix
## bindir: $bindir
## datadir: $datadir
## executable: \${bindir}/$EXENAME
## library: \${datadir}/$LIBNAME
##
## TinyFugue configuration successful.
## Use "make" to build.
])
