dnl Process this file with autoconf to produce a configure script.
AC_INIT(scl.c)
AM_INIT_AUTOMAKE(scm, 5b3)
AM_CONFIG_HEADER(scmconfig.h)

dnl Check for cryptlib and savant in tree
#if test -d "$srcdir/../Cryptlib"; then
#	crypt_inc="-I$srcdir/../Cryptlib"
#	crypt_lib="-L$srcdir/../Cryptlib"
#	with_cryptlib=yes
#fi
if test -d "$srcdir/../Savant"; then
	savant_inc="-I$srcdir/../Savant/wordvec \
	-I$srcdir/../Savant/savutil -I$srcdir/../Savant/template \
	-I$srcdir/../Savant/collection -I$srcdir/../Savant"
	savant_lib="-L$srcdir/../Savant"
	with_savant=yes
fi
if test -d "$srcdir/../SSLeay"; then
	ssleay_inc="-I$srcdir/../SSLeay/include"
	ssleay_lib="-L$srcdir/../SSLeay/crypto -L$srcdir/../SSLeay/ssl"
	ssleay_lib="$ssleay_lib -L../SSLeay/rsaref"
	with_ssleay=yes
fi

INITS=
XLIBS=
XOBJ=

AC_ARG_ENABLE(reckless-error-checking,
[  --enable-reckless-error-checking  turn most SCM error checking off],
[if test "x$enableval" != xno; then
	AC_DEFINE(RECKLESS)
fi])

AC_ARG_ENABLE(cautious-argument-checking,
[  --disable-cautious-argument-checking  don't check the number of arguments
                                        to interpreted closures],
[if test "x$enableval" = xno; then
	AC_DEFINE(CAUTIOUS)
fi],
[AC_DEFINE(CAUTIOUS)])

AC_ARG_ENABLE(floats,
[  --disable-floats        don't support inexact numbers],
[if test "x$enableval" = xno; then
	AC_DEFINE(FLOATS)
fi],
[AC_DEFINE(FLOATS)])

AC_ARG_ENABLE(singles,
[  --disable-singles       don't use single-precision floats],
[if test "x$enableval" = xno; then
	AC_DEFINE(SINGLES)
fi],
[AC_DEFINE(SINGLES)])

AC_ARG_ENABLE(singles-only,
[  --enable-singles-only   make all inexact reals single-precision],
[if test "x$enableval" != xno; then
	AC_DEFINE(SINGLESONLY)
fi])

AC_ARG_ENABLE(gc-free-segments,
[  --disable-gc-free-segments don't free unused heap after garbage collection],
[if test "x$enableval" = xno; then
	AC_DEFINE(GC_FREE_SEGMENTS)
fi],
[AC_DEFINE(GC_FREE_SEGMENTS)])

AC_ARG_ENABLE(ticks,
[  --enable-ticks          define ticks and ticks-interrupt],
[if test "x$enableval" != xno; then
	AC_DEFINE(TICKS)
fi])

AC_ARG_ENABLE(brackets-as-parens,
[  --enable-brackets-as-parens  have square brackets read as parens],
[if test "x$enableval" != xno; then
	AC_DEFINE(BRACKETS_AS_PARENS)
fi])

AC_ARG_ENABLE(huge-environments,
[  --enable-huge-environments  allow >4095 bound variables in one procedure at
                              the cost of performance],
[if test "x$enableval" = xno; then
	AC_DEFINE(MEMOIZE_LOCALS)
fi],
[AC_DEFINE(MEMOIZE_LOCALS)])

AC_ARG_ENABLE(engineering-notation,
[  --enable-engineering-notation  use engineering notation rather than
                                 scientific notation],
[if test "x$enableval" != xno; then
	AC_DEFINE(ENGNOT)
fi])

AC_ARG_ENABLE(sicp-compatibility,
[  --enable-sicp-compatibility  be more compatible with the Scheme used
                               in Sussman and Abelson's book _The Structure
                               and Interpretation of Computer Programs_],
[if test "x$enableval" != xno; then
	AC_DEFINE(SICP)
fi])

AC_ARG_ENABLE(arrays,
[  --disable-arrays        don't support arrays],
[if test "x$enableval" = xno; then
	AC_DEFINE(ARRAYS)
fi],
[AC_DEFINE(ARRAYS)])

AC_ARG_ENABLE(bignums,
[  --disable-bignums       don't support multiple-precision integers],
[if test "x$enableval" = xno; then
	AC_DEFINE(BIGNUMS)
fi],
[AC_DEFINE(BIGNUMS)])

AC_ARG_ENABLE(dumping,
[  --disable-dumping       don't support dumping scm images],
[if test "x$enableval" = xno; then
	AC_DEFINE(CAN_DUMP)
	dump=1
fi],
[AC_DEFINE(CAN_DUMP)
dump=1])

AC_ARG_ENABLE(compiled-closures,
[  --disable-compiled-closures  don't support compiled closures],
[if test "x$enableval" = xno; then
	AC_DEFINE(CCLO)
fi],
[AC_DEFINE(CCLO)])

AC_ARG_ENABLE(cheap-continuations,
[  --enable-cheap-continuations  enable cheap continuations],
[if test "x$enableval" != xno; then
	AC_DEFINE(CHEAP_CONTINUATIONS)
fi])

AC_ARG_ENABLE(io-extensions,
[  --disable-io-extensions  don't support chdir, pipes, delete-file,
                           file-position, or other i/o extensions],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ ioext.o" 
	INITS="$INITS init_ioext();"
fi],
[XOBJ="$XOBJ ioext.o" 
INITS="$INITS init_ioext();"])

AC_ARG_ENABLE(r2rs-procedures,
[  --disable-r2rs-procedures  disable procedures removed in R4RS],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ sc2.o" 
	INITS="$INITS init_sc2();"
fi],
[XOBJ="$XOBJ sc2.o" 
INITS="$INITS init_sc2();"])

AC_ARG_ENABLE(general-c-functions,
[  --disable-general-c-functions  only let C functions called from Scheme
                                 take certain fixed argument patterns],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ gsubr.o" 
	INITS="$INITS init_gsubr();"
	AC_DEFINE(CCLO)
fi],
[XOBJ="$XOBJ gsubr.o" 
INITS="$INITS init_gsubr();"
AC_DEFINE(CCLO)])

AC_ARG_ENABLE(unix-functions,
[  --disable-unix-functions  don't support Unix-specific functions],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ posix.o unix.o" 
	INITS="$INITS init_posix(); init_unix();"
fi],
[XOBJ="$XOBJ posix.o unix.o" 
INITS="$INITS init_posix(); init_unix();"])

AC_ARG_ENABLE(records,
[  --disable-records       don't support R5RS proposed user definable types],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ record.o" 
	INITS="$INITS init_record();"
fi],
[XOBJ="$XOBJ record.o" 
INITS="$INITS init_record();"])

AC_ARG_ENABLE(regexps,
[  --disable-regexps       don't support regular expressions],
[if test "x$enableval" = xno; then
	XOBJ="$XOBJ rgx.o regex.o" 
	INITS="$INITS init_rgx();"
fi],
[XOBJ="$XOBJ rgx.o regex.o" 
INITS="$INITS init_rgx();"])

dnl test -z "$CFLAGS" && CFLAGS=-g AC_SUBST(CFLAGS)
dnl test -z "$LDFLAGS" && LDFLAGS=-g AC_SUBST(LDFLAGS)

AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_CPP
AC_PROG_RANLIB
AC_AIX
AC_ISC_POSIX
AC_MINIX
AC_STDC_HEADERS
AC_CHECK_HEADERS([fcntl.h grp.h limits.h malloc.h memory.h pwd.h strings.h \
sys/filio.h sys/ioctl.h sys/select.h sys/types.h sys/time.h sys/timeb.h \
sys/times.h sys/un.h sys/utsname.h time.h unistd.h ])
AC_TIME_WITH_SYS_TIME
AC_RETSIGTYPE
AC_CONST
AC_MINUS_C_MINUS_O
AC_CHECK_TYPE(ssize_t, int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(double)
dnl AC_PREFIX(scm)
AC_CANONICAL_HOST

dnl Various linker flags, mostly for dumping, but some are required to
dnl build at all.  We statically link unless we can't for some reason.
dnl   HPUX	won't build dynamically (I think!); certainly won't dump unless static.
dnl   Linux	static dumps crash in gethostbyname, even though just-SCM dumps come up okay
dnl		if we do (set-current-output-port (current-error-port)) first.  dynamic
dnl		dumps don't require stderr redirection, and gethostbyname works
dnl   Irix	requires -G 0 to dump; -static seems a no-op ("file" still claims dynamic)
dnl   Solaris	no static libraries available
dnl   NetBSD	--> dump crashes <--
case "$host" in
  hppa*-hp-hpux* )
	LDFLAGS="$LDFLAGS -static"
    ;;
  mips-sgi-irix6.2 )
	LDFLAGS="$LDFLAGS -G 0"
    ;;
esac

AC_CHECK_FUNCS([acct chown fork ftime getcwd geteuid getgrent getgroups \
gethostent getppid getpwent getuid kill link pipe popen select seteuid \
setsid setuid sigaction strcasecmp times ttyname uname waitpid])

AC_CHECK_FUNC(b64_pton,[AC_DEFINE(HAVE_B64_PTON)],AC_CHECK_LIB(resolv,b64_pton,
	      [AC_DEFINE(HAVE_B64_PTON) LIBS="-lresolv $LIBS"]))

AC_TRY_CPP([
#if SIZEOF_LONG != SIZEOF_DOUBLE
#error asdf
#endif], [AC_DEFINE(CDR_DOUBLES)])

AC_TRY_CPP([
#if SIZEOF_LONG == SIZEOF_INT
#error asdf
#endif], [AC_DEFINE(SHORT_INT)])

AC_CACHE_CHECK(whether sleep() sets errno to EINTR,
ac_cv_func_sleep_EINTR,
AC_TRY_RUN([
#include <errno.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
int main() {
    errno = 0;
    sleep(1);
    return errno == EINTR;
}], [ac_cv_func_sleep_EINTR=no], [ac_cv_func_sleep_EINTR=yes]))

if test $ac_cv_func_sleep_EINTR = yes; then
    AC_DEFINE(SLEEP_EINTR)
fi

tlibs=
clibs=
rlibs=
slibs=

AC_CHECK_LIB(termcap, tgetent, [tlibs="-ltermcap"])

AC_CHECK_LIB(ncurses, initscr, [clibs="-lncurses $tlibs"],
    AC_CHECK_LIB(curses, initscr, [clibs="-lcurses $tlibs"], [nocurses=1]))

AC_ARG_ENABLE(curses,
[  --enable-curses         support text windowing],
[if test "x$enableval" != xno -a "x$nocurses" != 1; then
    XOBJ="$XOBJ crs.o"
    LIBS="$clibs $LIBS"
    INITS="$INITS init_crs();"
fi])

AC_CHECK_LIB(readline, readline, [rlibs="-lreadline $tlibs"], [noreadline=1],
	     $tlibs)

AC_ARG_ENABLE(line-editing,
[  --disable-line-editing  disable line editing support],
[if test "x$enableval" != xno -a "x$noreadline" != x1; then
    XOBJ="$XOBJ edline.o"
    LIBS="$rlibs $LIBS"
    INITS="$INITS init_edline();"
fi],
[if test "x$noreadline" != x1; then
    XOBJ="$XOBJ edline.o"
    LIBS="$rlibs $LIBS"
    INITS="$INITS init_edline();"
fi])

AC_CHECK_FUNCS(socket, [],
    AC_CHECK_LIB(socket, socket, [slibs="-lsocket -lnsl"], [nosocket=1],-lnsl))

AC_ARG_ENABLE(sockets,
[  --disable-sockets       disable socket (networking) support],
[if test "x$enableval" != xno -a "x$nosocket" != x1; then
    LIBS="$slibs $LIBS"
    INITS="$INITS init_socket(); init_sock_ext(); init_tcp(); init_udp();"
fi],
[if test "x$nosocket" != x1; then
    XOBJ="$XOBJ socket.o sock-ext.o tcp.o udp.o"
    LIBS="$slibs $LIBS"
    INITS="$INITS init_socket(); init_sock_ext(); init_tcp(); init_udp();"
fi])

AC_ARG_WITH(cryptlib-includes,
[  --with-cryptlib-includes=PATH  specify the location of cryptlib headers],
[crypt_inc="-I$withval"])

AC_ARG_WITH(cryptlib-library,
[  --with-cryptlib-library=PATH   specify the location of cryptlib library],
[crypt_lib="-L$withval"])

AC_ARG_WITH(cryptlib,
[  --with-cryptlib       provide an interface to cryptlib functions],
[if test "x$withval" != xno; then
    XOBJ="$XOBJ cryptscm.o"
    MAK0STRFROM=yes
    INITS="$INITS init_cryptlib();"
    CPPFLAGS="$CPPFLAGS $crypt_inc"
    XLIBS="$crypt_lib -lcrypt $XLIBS"
fi])

AC_ARG_WITH(savant-includes,
[  --with-savant-includes=PATH   specify the location of savant headers],
[savant_inc="-I$withval"])

AC_ARG_WITH(savant-library,
[  --with-savant-library=PATH   specify the location of savant library],
[savant_lib="-L$withval"])

AC_ARG_WITH(savant,
[  --with-savant         provide an interface to savant functions],
[if test "x$withval" != xno; then
    XOBJ="$XOBJ savant-linkage.o"
    INITS="$INITS init_savant();"
    CPPFLAGS="$CPPFLAGS $savant_inc"
    XLIBS="$savant_lib -lsavant-yenta $XLIBS"
fi])

AC_ARG_WITH(rsaref,
[  --with-rsaref[=DIR]   use the RSAref library (in DIR)],
[if test no \!= "$withval"; then
    if test yes \!= "$withval"; then
	rsadir="-L$withval"
    fi
    XLIBS="$rsadir -lrsaref $XLIBS"
fi])

AC_ARG_WITH(ssleay-includes,
[  --with-ssleay-includes=PATH   specify the location of SSLeay headers],
[ssleay_inc="-I$withval"])

AC_ARG_WITH(ssleay-library,
[  --with-ssleay-library=PATH   specify the location of SSLeay library],
[ssleay_lib="-L$withval"])

AC_ARG_WITH(ssleay,
[  --with-ssleay         provide an interface to SSLeay functions],
[if test "x$withval" != xno; then
    XOBJ="$XOBJ ssleay-linkage.o cryptfile.o"
    MAK0STRFROM=yes
    INITS="$INITS init_ssleay(); init_cryptfile();"
    CPPFLAGS="$CPPFLAGS $ssleay_inc"
    if test -n "${with_rsaref+x}" -a no \!= "$with_rsaref"; then
	XLIBS="-lRSAglue $XLIBS"
    fi
    XLIBS="$ssleay_lib -lssl -lcrypto $XLIBS"
fi])

AC_ARG_ENABLE(allow-bypassing-normal-startup,
[  --disable-allowing-bypassing-normal-startup  don't support allowing
                                                the bypassing of normal startup],
[if test "x$enableval" = xno; then
	INITS="$INITS init_bns();"
fi],
[INITS="$INITS init_bns();"])

if test "x$dump" = x1; then
	AC_FIND_UNEXEC
fi

if grep run_time_remap $UNEXEC_SRC >/dev/null 2>&1; then
	AC_DEFINE(RUN_TIME_REMAP)
fi

if test "$MAK0STRFROM" = yes; then
	XOBJ="$XOBJ mak0strfrom.o"
fi

AC_SUBST(XOBJ)
AC_SUBST(INITS)
AC_SUBST(LIBOBJS)

LIBS="$XLIBS $LIBS"

AC_OUTPUT(Makefile m/Makefile s/Makefile)

dnl Local Variables:
dnl comment-start: "dnl "
dnl comment-end: ""
dnl comment-start-skip: "\\bdnl\\b\\s *"
dnl compile-command: "make configure scmconfig.h.in"
dnl End:
