dnl Process this file with autoconf to produce a configure script.
AC_REVISION($Revision: 1.93 $)
AC_PREREQ(2.12.971222)
rm -f config.cache

### Use "configure -with-screen" to override the default configuration, which is
### termcap-based on unix systems.

dnl $Header: /usr/build/vile/vile/RCS/configure.in,v 1.93 1998/08/30 22:47:25 tom Exp $

dnl
AC_INIT(mktbls.c)
AC_CONFIG_HEADER(config.h:config_h.in)

CF_CHECK_CACHE

###	checks for alternative programs
AC_PROG_CC
AC_PROG_CPP
AC_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROGRAM_PATH(TD_CONFIG,td_config)

CF_DISABLE_ECHO
CF_PROG_EXT

CF_ARG_DISABLE(extensions,
	[  --disable-extensions    test: build only core functions],
	[AC_DEFINE(SMALLER)
	 AC_DEFINE(FEWNAMES)],
	[EXTRAOBJS="$EXTRAOBJS btree.o crypt.o"])
CF_ARG_DISABLE(shell,
	[  --disable-shell         test: disable shell/external commands],
	[AC_DEFINE(OPT_SHELL,0)],
	[EXTRAOBJS="$EXTRAOBJS npopen.o spawn.o"])

###	use option --with-cflags to set default CFLAGS
AC_MSG_CHECKING(for CFLAGS options)
AC_ARG_WITH(CFLAGS,
	[  --with-CFLAGS=value     set default for \$CFLAGS],
	[cflags=$withval])
if test -z "$cflags"; then
	AC_ARG_WITH(cflags,
		[  --with-cflags=value     (same as --with-CFLAGS)],
		[cflags=$withval])
fi

# if the user specified nothing else, set -O.  user can override
# with --with-cflags=" "
if test -n "$cflags"; then
	CFLAGS="$cflags"
elif test -z "$CFLAGS" ; then
	CFLAGS="-O"
fi
AC_MSG_RESULT($cflags)

AC_MSG_CHECKING(for startup path)
AC_ARG_WITH(startup-path,
[  --with-startup-path=PATH specify locations to search for vile.hlp, etc.],
[VILE_STARTUP_PATH=$withval],
[test -z "$VILE_STARTUP_PATH" &&\
	VILE_STARTUP_PATH='$(datadir):/usr/local/lib/:/usr/local/:/usr/lib/'])
AC_MSG_RESULT($VILE_STARTUP_PATH)
AC_SUBST(VILE_STARTUP_PATH)

AC_MSG_CHECKING(if you want to use perl as an extension language)
AC_ARG_WITH(perl,
	[  --with-perl             enable use of Perl as an extension language],
	[with_perl=$withval],
	[with_perl=no])
AC_MSG_RESULT($with_perl)
if test "$with_perl" = yes ; then
	CF_PROG_PERL(5.004)
	if test "$PERL" = no; then
	    AC_ERROR([perl not found])
	fi
	perl_lib_path=`$PERL -MConfig -e 'print $Config{privlib}'`
	AC_DEFINE(OPT_PERL)
	EXTRAOBJS="$EXTRAOBJS perl.o"
	LINK_PREFIX=`$PERL -MConfig -e 'print $Config{shrpenv}'`
	ac_link="$LINK_PREFIX $ac_link"
	CFLAGS="$CFLAGS `$PERL -MExtUtils::Embed -e ccopts`"
	LIBS="$LIBS `$PERL -MExtUtils::Embed -e ldopts`"
	EXTRA_INSTALL_DIRS="$EXTRA_INSTALL_DIRS \$(INSTALL_PERL_DIRS)"
	EXTRA_INSTALL_FILES="$EXTRA_INSTALL_FILES \$(INSTALL_PERL_FILES)"
fi
AC_SUBST(perl_lib_path)
AC_SUBST(PERL)
AC_SUBST(EXTRA_INSTALL_DIRS)
AC_SUBST(EXTRA_INSTALL_FILES)

# X11 checks will sometimes add to CFLAGS.  We want the state of CFLAGS
# prior to these checks
saved_CFLAGS="$CFLAGS"

###	checks for UNIX variants that set C preprocessor variables
AC_AIX
AC_ISC_POSIX
AC_MINIX
dnl: why this? AC_DYNIX_SEQ
AC_CHECK_FUNC(getpwnam,,AC_CHECK_LIB(sun,getpwnam))

# check for SCO.
# FIXME:  this is a hack, and should be split into individual features -- the
# sys/time.h and select.h conflict.
AC_CHECKING([for SCO by checking on /usr/bin/scosh])
AC_PROGRAM_CHECK(COULD_BE_SCO, [scosh], maybe, maybenot)
if test "$COULD_BE_SCO" = "maybe"
then
	AC_DEFINE(SYSTEM_LOOKS_LIKE_SCO)
fi

# check for a lint program.
AC_CHECK_PROGS(LINT, lint alint lclint, [])
if test -n "$LINT"
then
	AC_DEFINE(SYSTEM_HAS_LINT_PROG)
fi

###	checks for header files
AC_STDC_HEADERS
AC_HEADER_DIRENT
AC_CHECK_HEADERS(unistd.h stdlib.h stdarg.h stddef.h string.h memory.h fcntl.h \
                poll.h pwd.h termios.h termio.h sgtty.h \
		ioctl.h select.h setjmp.h signal.h utime.h varargs.h)

###	checks for <sys/xxx> header files (separate, to avoid bug in autoconf)
AC_CHECK_HEADERS(sys/filio.h sys/ioctl.h sys/itimer.h \
		sys/param.h \
		sys/resource.h sys/wait.h sys/time.h sys/select.h)

###	checks for typedefs
AC_TYPE_SIGNAL
AC_DEFINE(SIGT,RETSIGTYPE)
if test $ac_cv_type_signal = void; then
	AC_DEFINE(SIGRET,[/*do nothing*/])
else
	AC_DEFINE(SIGRET,[return 0])
fi

AC_TYPE_SIZE_T
AC_TYPE_OFF_T
AC_TYPE_UID_T
AC_TYPE_PID_T
AC_CHECK_TYPE(time_t, long)

###	checks for library functions
if test "$cross_compiling" = no; then
	AC_FUNC_SETVBUF_REVERSED
fi

###	checks for structures
AC_STAT_MACROS_BROKEN
AC_ST_BLKSIZE
AC_ST_BLOCKS
AC_ST_RDEV
AC_TIME_WITH_SYS_TIME
AC_STRUCT_TM
CF_SIZECHANGE
CF_FP_ISREADY

###	checks for compiler characteristics
AC_CONST
CF_ANSI_CC_REQD
CF_CC_INIT_UNIONS
CF_CC_OFFSETOF_CASES

###	checks for system services and user specified options
AC_LONG_FILE_NAMES
CF_RESTARTABLE_PIPEREAD		# is a read() of a pipe restartable?

AC_SUBST(CFLAGS)
AC_SUBST(LIBS)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)
AC_SUBST(X_EXTRA_LIBS)
AC_SUBST(SCREEN)
AC_SUBST(TARGET)
AC_SUBST(LINK_PREFIX)
dnl
dnl The killpg test and the tests for the presence of certain functions on
dnl a particular operating system are done prior to the checks for existence
dnl of screen libraries due to a problem with -lXt on certain SunOS systems.
dnl The nature of this problem is described in the FAQ on X.  Look for the
dnl following subject: ``What are these problems with "_XtInherit not found"
dnl on the Sun? ...''  The long and the short of it is that AC_HAVE_FUNCS will
dnl not work properly (without being rewritten) if placed after adding -lXt to
dnl LIBS on SunOS (and perhaps some others as well).
dnl
AC_FUNC_SETPGRP
AC_FUNC_GETPGRP
CF_KILLPG
CF_ERRNO
CF_SYS_ERRLIST
AC_DEFINE(SYS_UNIX)
AC_DEFINE(scrn_chosen)
# Try to eventually eliminate the following
AC_DEFINE(os_chosen)

AC_MSG_CHECKING(for screen type)
AC_ARG_WITH(screen,
[  --with-screen=value     specify terminal driver.  The default is tcap, for
                          the termcap/terminfo driver.  Other values include
                          ncurses (a special case of terminfo), X11, OpenLook,
                          Motif, Athena, Xaw, Xaw3d, neXtaw and ansi.],
[screen=$withval])

if test -z "$screen"; then
	AC_ARG_WITH(scr,
		[  --with-scr=value        (same as --with-screen)],
		[screen=$withval])
fi
test -z "$screen" && test "$with_x" = yes && screen=x11

if test -z "$screen"; then
	screen=termcap;
fi
AC_MSG_RESULT($screen)

: See if this is any type of xvile configuration:
case "$screen" in
changequote(,)dnl
	[Oo]pen[Ll]ook | [Mm]otif* | [xX] | [Aa]thena | [xX][atTmMoO]* | [xX]11 | neXtaw )
changequote([,])dnl
		CF_X_TOOLKIT
		CF_IMAKE_CFLAGS
		X_CFLAGS="$X_CFLAGS $IMAKE_CFLAGS"
		LDFLAGS="$LDFLAGS $X_LIBS"
		CFLAGS="$CFLAGS $X_CFLAGS"
		SCREEN=x11
		TARGET=xvile
		AC_DEFINE(DISP_X11)
		AC_DEFINE(XTOOLKIT)
		AC_CHECK_HEADERS(X11/IntrinsicI.h)
	;;
esac

: Find the libraries that apply to the selected screen-type:
case "$screen" in
changequote(,)dnl
	[Oo]pen* | [Xx]ol )
changequote([,])dnl
		AC_DEFINE(OL_WIDGETS)
		CF_X_OPENLOOK
	;;
changequote(,)dnl
	[mM]otif* | [Xx]m )
changequote([,])dnl
		AC_DEFINE(MOTIF_WIDGETS)
		CF_X_MOTIF
	 	EXTRAOBJS="$EXTRAOBJS menu.o"
	;;
changequote(,)dnl
	[Aa]thena* | [Xx]aw* | neXtaw )
changequote([,])dnl
		AC_DEFINE(ATHENA_WIDGETS)
		case $screen in #(vi
		*aw*)
			cf_x_athena=`echo $screen | sed -e s/x/X/`
			;;
		esac
		CF_X_ATHENA
	 	EXTRAOBJS="$EXTRAOBJS menu.o"
	;;
changequote(,)dnl
	x | X | [Xx][Tt]* | [Xx]11 )
changequote([,])dnl
		AC_DEFINE(NO_WIDGETS)
	;;
	ansi)
		SCREEN=ansi
		TARGET=vile
		AC_DEFINE(DISP_ANSI)
	;;
	* )
		SCREEN=tcap
		TARGET=vile
		AC_DEFINE(DISP_TERMCAP)
		CF_TERMCAP_LIBS($screen)
	;;
esac

: Check for termcap vs terminfo:
cf_tc_funcs=""
cf_tc_externs=""
if test ".$cf_cv_lib_termcap" = .terminfo ; then
	AC_DEFINE(USE_TERMINFO)
	cf_tc_funcs="tigetint tigetnum tparam tparm"
	cf_tc_externs="$cf_tc_funcs tgoto tigetstr tputs tigetflag"
elif test ".$cf_cv_lib_termcap" = .termcap ; then
	# BSD 'tputs()' may need 'PC' to be set.
	AC_TRY_LINK([],[extern char PC; PC = 0],
		[AC_DEFINE(HAVE_EXTERN_TCAP_PC)])
	cf_tc_funcs="tgetint tgetnum tparam tparm"
	cf_tc_externs="$cf_tc_funcs tgoto tgetstr tputs tgetent tgetflag"
fi

LIBS="$LIBS $X_EXTRA_LIBS"

AC_HAVE_FUNCS( \
access \
alarm \
getcwd \
gethostname \
getpass \
getwd \
killpg \
link \
mkdir \
poll \
putenv \
select \
setitimer \
setsid \
setvbuf \
sigaction \
sigprocmask \
strchr \
strrchr \
symlink \
tcgetattr \
ttyname \
utime \
utimes \
$cf_tc_funcs \
)

CF_ANSI_QSORT

###	Miscellaneous options
if test -n "$cf_x_athena" ; then
    AC_MSG_CHECKING(if you want to use Xaw scrollbars rather than our own)
    AC_ARG_WITH(Xaw-scrollbars,
	[  --with-Xaw-scrollbars   use Xaw scrollbars rather than our own],
	[cf_Xaw_scrollbars=$withval],
	[cf_Xaw_scrollbars=no])
    AC_MSG_RESULT($cf_Xaw_scrollbars)

    if test "$cf_Xaw_scrollbars" = no ; then
	AC_DEFINE(OPT_KEV_SCROLLBARS)
	AC_DEFINE(OPT_KEV_DRAGGING)
    else
	AC_DEFINE(OPT_XAW_SCROLLBARS)
	AC_MSG_CHECKING(if you want to use the drag/scrolling extension with Xaw)
	AC_ARG_WITH(drag-extension,
	    [  --with-drag-extension   use drag/scrolling extension with Xaw],
	    [cf_drag_extension=$withval],
	    [cf_drag_extension=no])
	AC_MSG_RESULT($cf_drag_extension)
	if test "$cf_drag_extension" != "no" ; then
	    AC_DEFINE(OPT_KEV_DRAGGING)
	fi
    fi
fi

AC_MSG_CHECKING(if you want to change the number of exec-macros)
AC_ARG_WITH(exec-macros,
	[  --with-exec-macros=N    specify count of numbered macros],
	[cf_exec_macros=$withval],
	[cf_exec_macros=no])
AC_MSG_RESULT($cf_exec_macros)
test "$cf_exec_macros" != no && AC_DEFINE(OPT_EXEC_MACROS,$cf_exec_macros)

# I don't know of a reliable test for working locale, but we can at least check
# that it is available before offering it as an option.
AC_CHECK_FUNC(setlocale,[
AC_CHECK_HEADER(locale.h,[
AC_MSG_CHECKING(if you want to use i18n locale support)
AC_ARG_WITH(locale,
	[  --with-locale           use i18n support for character-types],
	[cf_locale=$withval],
	[cf_locale=no])
AC_MSG_RESULT($cf_locale)
test "$cf_locale" != no && AC_DEFINE(OPT_LOCALE)
])])

###	Debugging/development options
AC_ARG_WITH(dbmalloc,
	[  --with-dbmalloc         test: use Conor Cahill's dbmalloc library],
	[AC_DEFINE(USE_DBMALLOC)
	 LIBS="$LIBS -ldbmalloc"])

AC_ARG_WITH(dmalloc,
	[  --with-dmalloc          test: use Gray Watson's dmalloc library],
	[AC_DEFINE(USE_DMALLOC)
	 LIBS="$LIBS -ldmalloc"])

AC_ARG_WITH(no-leaks,
	[  --with-no-leaks         test: free permanent memory, analyze leaks],
	[AC_DEFINE(NO_LEAKS)])

AC_ARG_WITH(trace,
	[  --with-trace            test: turn on debug-tracing],
	[AC_DEFINE(OPT_TRACE)
	 EXTRAOBJS="$EXTRAOBJS trace.o"])

CFLAGS="$saved_CFLAGS"
AC_ARG_WITH(warnings,
	[  --with-warnings         test: turn on GCC compiler warnings],
	[with_warnings=$withval])
if test -n "$with_warnings"
then
	CF_GCC_ATTRIBUTES
	CF_GCC_WARNINGS
fi

###	Do these last, since they rely on a properly constructed config.h

###	Mandatory checks for missing prototypes:
CHECK_DECL_FLAG="-I. -I$srcdir -Dscrn_chosen"
VILE_CHECK_HDRS='
#define CHECK_PROTOTYPES 1
#include <estruct.h>
'
CHECK_DECL_HDRS="$VILE_CHECK_HDRS"

CF_MISSING_EXTERN( \
environ \
getenv \
getpass \
getwd \
malloc \
realloc \
rindex \
strerror \
strtol \
)

if test -n "$cf_tc_externs"
then
CHECK_DECL_HDRS="$VILE_CHECK_HDRS
#include <tcap.h>
"

if test ".$cf_cv_lib_termcap" != ".none" ; then
	CF_TYPE_OUTCHAR
fi
CF_MISSING_EXTERN( \
$cf_tc_externs \
)
fi

###	Optional checks for missing functions (enabled with --with-warnings)
if test -n "$with_warnings"
then
CHECK_DECL_HDRS="$VILE_CHECK_HDRS"
CF_MISSING_EXTERN( \
_filbuf \
_flsbuf \
access \
alarm \
atoi \
bzero \
chdir \
close \
dup \
execlp \
fclose \
fflush \
fgetc \
fileno \
fork \
fprintf \
fputc \
fputs \
fread \
free \
fseek \
fwrite \
gethostname \
getpgrp \
getpid \
getuid \
isatty \
kill \
killpg \
link \
longjmp \
lstat \
memset \
mkdir \
mktemp \
open \
perror \
pipe \
printf \
puts \
qsort \
read \
readlink \
select \
setbuf \
setbuffer \
setitimer \
setjmp \
setpgrp \
setsid \
setvbuf \
sleep \
sscanf \
system \
time \
unlink \
utime \
utimes \
wait \
write \
)

CHECK_DECL_HDRS="$VILE_CHECK_HDRS
#if HAVE_SYS_IOCTL_H
#include	<sys/ioctl.h>
#endif
"
CF_MISSING_EXTERN( \
ioctl \
)
fi

AC_SUBST(EXTRAOBJS)

###	output makefile and config.h
AC_OUTPUT(makefile,,,sort)