dnl Process this file with autoconf to produce a configure script.
AC_INIT(exp_global.h)
AC_CONFIG_HEADER(exp_conf.h)
AC_PROG_INSTALL
AC_PROG_RANLIB

AC_PID_T

#
# Look for various header files
#
AC_HEADER_CHECK(string.h, ,AC_DEFINE(NO_STRING_H))
AC_HEADER_CHECK(stdlib.h, ,AC_DEFINE(NOSTDLIB))
AC_HEADER_CHECK(sys/stropts.h, AC_DEFINE(HAVE_STROPTS_H))
AC_HEADER_CHECK(sys/sysconfig.h, AC_DEFINE(HAVE_SYSCONF_H))
AC_HEADER_CHECK(sys/fcntl.h, AC_DEFINE(HAVE_SYS_FCNTL_H))
AC_HEADER_CHECK(sys/sysmacros.h, AC_DEFINE(HAVE_SYSMACROS_H))
AC_UNISTD_H

#
# Look for various functions
#
AC_FUNC_CHECK(memcpy, ,AC_DEFINE(NO_MEMCPY))
AC_FUNC_CHECK(waitpid, ,AC_DEFINE(NOWAITPID))
AC_FUNC_CHECK(sysconf, AC_DEFINE(HAVE_SYSCONF))

#
# check how signals work
#

# Check for the data type of the function used in signal(). This
# must be before the test for rearming.
echo checking return type of signal handlers
AC_HEADER_EGREP([(void|sighandler_t).*signal], signal.h, retsigtype=void,AC_DEFINE(RETSIGTYPE, int) retsigtype=int)

# FIXME: check to see it alarm exists
# Check to see it signals need to be re-armed after use.
echo checking to see if signals need to be re-armed
AC_TEST_PROGRAM([
#include <signal.h>
#define RETSIGTYPE $retsigtype

void
sigquit_handler(n)
int n;
{
}

main()
{
	if (0 == fork()) {
		unlink("core");
		signal(SIGQUIT,sigquit_handler);
		kill(getpid(),SIGQUIT);
		kill(getpid(),SIGQUIT);
	} else {
		int status;

		wait(status);
		exit(unlink("core")==-1?0:1);
	}
}], ,AC_DEFINE(REARM_SIG))

# HPUX7 has trouble with the big cat so split it
# Owen Rees <rtor@ansa.co.uk> 29Mar93 
SEDDEFS="${SEDDEFS}CONFEOF
cat >> conftest.sed <<CONFEOF
"
#
# Look for various features to determine what kind of pty
# we have. For some weird reason, ac_compile_check would not
# work, but ac_test_program does.
#
echo checking for HP style pty allocation
# following test fails on DECstations and other things that don't grok -c
# but that's ok, since they don't have PTYMs anyway
if test -c /dev/ptym/ptyp0 2>>/dev/null ; then
    AC_DEFINE(HAVE_PTYM)
fi

echo checking for HP style pty-trapping
AC_HEADER_EGREP([struct.*request_info], sys/ptyio.h, AC_DEFINE(HAVE_PTYTRAP), )

echo checking for AIX new-style pty allocation
if test -r /dev/ptc -a -r /dev/pts ; then
    AC_DEFINE(HAVE_PTC_PTS)
fi

echo checking for SGI old-style pty allocation
if test -r /dev/ptc -a ! -r /dev/pts ; then
    AC_DEFINE(HAVE_PTC)
fi

echo checking for SVR4 style pty allocation
if test -r /dev/ptmx ; then
    AC_DEFINE(HAVE_PTMX)
fi

AC_FUNC_CHECK(tcgetattr, tcgetattr=1)
AC_FUNC_CHECK(tcsetattr, tcsetattr=1)
if test $tcgetattr -a $tcsetattr ; then
    AC_DEFINE(POSIX)
fi

# first check for the pure bsd
echo checking for struct sgttyb
AC_TEST_PROGRAM([#include <sgtty.h>
main()
{
  struct sgttyb tmp;
  exit(0);
}], AC_DEFINE(HAVE_SGTTYB) PTY_TYPE=sgttyb)

# next check for the older style ttys
echo checking for struct termio
AC_TEST_PROGRAM([#include <termio.h>
main()
{
  struct termio tmp;
  exit(0);
}], AC_DEFINE(HAVE_TERMIO) PTY_TYPE=termio)

# now check for the new style ttys (not yet posix)
echo checking for struct termios
AC_TEST_PROGRAM([#include <termios.h>
main()
{
  struct termios tmp;
  exit(0);
}], AC_DEFINE(HAVE_TERMIOS) PTY_TYPE=termios)

# finally check for Cray style ttys
echo checking for Cray-style ptys
SETUID="@:"
AC_TEST_PROGRAM([
main(){
#ifdef CRAY
	return 0;
#else
	return 1;
#endif
}
], PTY_TYPE=unicos SETUID="chmod u+s", )
#
# Check for select and/or poll. If both exist, we prefer select.
# if neither exists, define SIMPLE_EVENT.
#
select=0
poll=0
AC_FUNC_CHECK(select, select=1)
AC_FUNC_CHECK(poll,   poll=1)
if test $poll -a $select ; then
   EVENT_TYPE=select
   poll=0
elif test $poll ; then
   EVENT_TYPE=poll
elif test $select ; then
   EVENT_TYPE=select
else
   AC_DEFINE(SIMPLE_EVENT)
fi

#
AC_HAVE_FUNCS(getpty)
AC_HAVE_FUNCS(_getpty)

# SETUID="@:"

#
# Set up makefile substitutions
#
AC_SUBST(PTY_TYPE)
AC_SUBST(EVENT_TYPE)
AC_SUBST(SETUID)
AC_OUTPUT(Makefile)
