dnl Process this file with autoconf to produce a configure script.
dnl
dnl Copyright (c) 1997, by Carlo Wood <carlo@runaway.xs4all.nl>

dnl Make sure we are in the correct directory (someone could have run
dnl 'configure' with a wrong '--srcdir'); Note that a bug in autoconf
dnl forces us to have srcdir == dir where configure resides (config):
AC_INIT(config-sh.in)

dnl 'configure' must be run from within 'config/'.
AC_CONFIG_AUX_DIR(.)

dnl Define the input and output configuration header file,
dnl (Generate config/setup.h from config/setup.h.in):
AC_CONFIG_HEADER(setup.h)

dnl Demand at least version 2.13 of autoconf
AC_PREREQ(2.13)

dnl This should be done early.
AC_PROG_CC

dnl UNIX Variants
dnl Allow the use of BSD functions on AIX.
dnl AC_AIX
dnl Allow the use of POSIX functions on several OS.
dnl AC_ISC_POSIX
dnl ANSIfy the C compiler whenever possible.
AM_PROG_CC_STDC
dnl Use -O3 instead of -O2.
if test "$CFLAGS" != "" ; then
  CFLAGS=`echo "$CFLAGS" | sed -e 's/-O2/-O3/'`
fi
dnl Remove -pipe during configure
if test "$CFLAGS" != "" ; then
  CFLAGS=`echo "$CFLAGS" | sed -e 's/-pipe//g'`
fi

dnl Checks for libraries.
AC_CHECK_LIB(c, crypt, [true],
    AC_CHECK_LIB(descrypt, crypt, LIBS="-ldescrypt $LIBS",
    AC_CHECK_LIB(crypt, crypt)))
AC_CHECK_LIB(c, gethostbyname, [true],
    AC_CHECK_LIB(nsl, gethostbyaddr, LIBS="-lnsl $LIBS"))
dnl IRIX has -lsocket, but doesn't need it.
AC_CHECK_LIB(c, socket, [true],
    AC_CHECK_LIB(socket, socket, LIBS="-lsocket $LIBS"))
unet_CHECK_LIB_RESOLV

dnl Checks for header files.
AC_HEADER_STDC

dnl Checks for typedefs, structures, and compiler characteristics.
dnl AC_C_CONST
AC_C_BIGENDIAN
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_TYPE_UID_T
unet_CHECK_TYPE_SIZES

dnl Define SIZE_T_FMT and TIME_T_FMT to be the printf format for
dnl respectively size_t and time_t.
unet_DEFINE_SIZE_T_FMT
unet_DEFINE_TIME_T_FMT

dnl Checks for library functions.
dnl AC_PROG_GCC_TRADITIONAL
dnl AC_FUNC_MEMCMP
dnl AC_FUNC_VPRINTF

dnl Do we have a system call poll?
unet_FUNC_POLL_SYSCALL

dnl Do we have restarting syscalls ?
AC_SYS_RESTARTABLE_SYSCALLS

dnl Test for programs
AC_PROG_AWK
AC_PROG_MAKE_SET
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PATH_PROGS(RMPROG, rm, /bin/rm)
AC_PATH_PROGS(SHPROG, sh, /bin/sh)

dnl Test if /bin/sh supports 'set -h'
AC_CACHE_CHECK([for set -h], unet_cv_sys_set_h,
[echo "set -h; exit $?" > conftest ;
$SHPROG ./conftest 2> conftest.out
ac_err=`grep -v '^ *+' conftest.out`
if test -z "$ac_err"; then
  unet_cv_sys_set_h=yes
else
  unet_cv_sys_set_h=no
fi
$RMPROG -fr conftest*])
dnl Used in Configure.
AC_SUBST(unet_cv_sys_set_h)

unet_NONBLOCKING
unet_SIGNALS

dnl Add -pipe when possible
unet_PIPE_CFLAGS

dnl Used in config-sh.
AC_SUBST(ac_cv_header_poll_h)
AC_SUBST(ac_cv_header_syslog_h)
AC_SUBST(unet_cv_func_poll_syscall)

dnl Check OS for os_dep files.
uname=`uname`
AC_MSG_CHECKING(for OS type)
case "$uname" in
  *inux*)
    AC_MSG_RESULT($uname found.)
    OSDEP_C="os_linux.c"
  ;;
  *olaris*)
    AC_MSG_RESULT($uname found.)
    OSDEP_C="os_solaris.c"
  ;;
  *SunOS*)
    AC_MSG_RESULT($uname found.)
    OSDEP_C="os_solaris.c"
  ;;
  *BSD*)
    AC_MSG_RESULT($uname found.)
    OSDEP_C="os_bsd.c"
  ;;
  *)
    AC_MSG_RESULT(Unknown OS. Using generic routines.)
    OSDEP_C="os_generic.c"
  ;;
esac
AC_SUBST(OSDEP_C)

dnl Finally really generate all output files:
AC_OUTPUT(config-sh Configure ../Makefile ../ircd/Makefile ../doc/Makefile Makefile, [echo timestamp > stamp-h;],)
