#!/bin/sh
#
# Copyright 1996,1997 Michael Graff <explorer@flame.org>
# You may distribute this file without changes freely providing this notice
# remains intact. 
#
IRCD_VERSION="dal4.6.7b.DreamForge"
CONF_DATE=`date`
LAST_VERSION="very very old"
#
trap "" 13 14 15
MV=mv
RM=rm
SETUP=include/setup.h
OPTIONS_H=include/options.h
OPTIONS=Options
AUTO_CONFIG=""
#
STDLIBH=undef
STDDEFH=undef
SYSSYSLOGH=undef
MALLOCH=undef
PARAMH=undef
UNISTDH=undef
STRINGH=undef
STRINGSH=undef
RUSAGEH=undef
NOINDEX=undef
NSTRERROR=undef
NSTRTOKEN=undef
NSTRTOK=undef
NINETADDR=undef
NINETNTOA=undef
NINETNETOF=undef
GETTIMEOFDAY=undef
LRAND48=undef
STRTOUL=undef
NEEDSKIPNAME=""
CCPATH=''
SIGNAL=''
BLOCKING=''
TMP=/tmp/.Configtmp$$.c
EXEC=/tmp/.Configtmp$$
PLATE=/tmp/.ConPlate$$
c=''
n=''
#
# Some reasonable defaults
#
DEFOPT="-O -g"
DEFCFLAGS="$DEFOPT"
DEFLIBS="none"
OSNAME="an unrecgonized operating system"
#
NOSPOOF="1"
NOSPOOF_SEED01="0x12345678"
NOSPOOF_SEED02="0x9abcdef0"
CONTACT_URL=""
CONTACT_EMAIL=""
SERVICES_NAME="none"
KLINE_ADDRESS=""
DPATH="/usr/local/lib/ircd"
SPATH="/usr/local/bin/ircd"
HUB=""
CRYPT_OPER_PASSWORD="1"
CRYPT_LINK_PASSWORD=""
LISTEN_SIZE="5"
MAXSENDQLENGTH="3000000"
BUFFERPOOL="(9 * MAXSENDQLENGTH)"
NICKNAMEHISTORYLENGTH="2000"
UNIXPORT=""
MAXCONNECTIONS="1024"
SHOWOPERS="Yes"

#
# load $OPTIONS if present
#
if [ -r "$OPTIONS" ] ; then
    . $OPTIONS
fi

#
2>/dev/null
if [ "`eval echo -n 'a'`" = "-n a" ] ; then
	c='\c'
else
	n='-n'
fi

clear

if [ "$LAST_VERSION" != "$IRCD_VERSION" ] ; then
    if [ -r doc/CHANGES.NEW ] ; then
	more doc/CHANGES.NEW
	echo $n "[Enter to begin]"
	read cc
    fi
fi

if [ "$1" = "-n" ] ; then
    if [ "$LAST_VERSION" != "$IRCD_VERSION" ] ; then
	echo "You specified the no-questions-asked configure, but the version"
	echo "of Config which created your Options file was $LAST_VERSION,"
	echo "And the current version is $IRCD_VERSION."
	echo " "
	echo "Please read the prompts carefully since some of them may have"
	echo "changed."
	echo " "
    else
	AUTO_CONFIG=Yes
    fi
fi

#
# Take a wild stab at the OS, and take reasonable defaults for each
#
OS=`uname -a`
case "$OS" in
    *NetBSD*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS="-lcrypt"
	OSNAME="NetBSD"
	;;
    *FreeBSD*2.2*)
        DEFCFLAGS="$DEFOPT"
        DEFLIBS="none"
        OSNAME="FreeBSD 2.2"
        CRYPT_OPER_PASSWORD=""
        CRYPT_LINK_PASSWORD=""
        echo "You are using FreeBSD 2.2; do NOT crypt passwords at this time"
        ;;
    *FreeBSD*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS="none"
	OSNAME="FreeBSD"
	CRYPT_OPER_PASSWORD=""
	CRYPT_LINK_PASSWORD=""
	echo "You are using FreeBSD ; do NOT crypt passwords at this time"
	;;
    *SCO_SV*)
	DEFCFLAGS="$DEFOPT -DSCOUNIX"
	DEFLIBS="-lsocket"
	OSNAME="SCO Openserver"
	NEEDSKIPNAME="Yep"
	echo "You're using SCO Unix. For more support, contact darkrot@dal.net"
	;;
    *OSF1*alpha*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS="none"
	OSNAME="OSF/1 or Digital Unix"
	;;
    *SunOS*4.*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS="none"
	OSNAME="SunOS 4.x"
	;;
    *SunOS*5.*)
	DEFCFLAGS="$DEFOPT -DSOL20"
	DEFLIBS="-lsocket -lnsl -lresolv"
	OSNAME="Solaris 2.x (or SunOS 5.x)"
	;;
    *Linux*)
	cat > $TMP << __EOF__
#include <stdio.h>
main()
{
	printf("%d\n",
#ifndef __GLIBC__
0);
#else
__GLIBC__);
#endif
exit(0);
}
__EOF__
#
# Yes, I know we don't have $CCPATH and $XCFLAGS and such set up yet,
# but below should work on just about any Linux system
#
	cc $TMP -o $EXEC >/dev/null 2>&1
	GLIBCVERS=`$EXEC`
	if [ -n "$GLIBCVERS" -a "$GLIBCVERS" -ge 2 ];then
		OSNAME="Linux (with GLIBC 2.x or greater)"
		DEFLIBS="-lcrypt -lresolv"
	else
		OSNAME="Linux"
		DEFLIBS=""
	fi
	DEFCFLAGS="$DEFOPT"
	;;
    *HP-UX*.09.*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS=""
	OSNAME="HPUX 9.x"
	;;
    *HP-UX*.10.*)
	DEFCFLAGS="$DEFOPT"
	DEFLIBS=""
	OSNAME="HPUX 10.x"
	;;
esac

echo " "
echo You are running $OSNAME...
echo " "
	
# Create Makefile if it doesn't exist...
if [ ! -f Makefile ] ; then
  cp Makefile.dist Makefile
fi
cat << __EOF__
Welcome to autoconfigure for the DALnet IRC server version $IRCD_VERSION.

Config will generate a system-specific $SETUP file, a top
level Makefile, $OPTIONS_H, and a persistant options file named
$OPTIONS

Enter "none" at any prompt to effect a null entry.

__EOF__

runonce=""
FOO=`egrep "^CC=" Makefile 2>/dev/null | sed -e 's/^[^=]*[ 	]*=\(.*\)/\1/'`
while [ -z "$CCPATH" ] ; do
	MYP=`echo "$PATH" | sed -e 's/:/ /g'`
	echo "Which compiler do you use, gcc or cc or...?"
	echo $n "[$FOO] -> $c"
	if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	    read cc
	else
	    cc=""
	fi
	if [ -z "$cc" ] ; then
		cc=$FOO
		CCPATH=$FOO
	elif [ -f $cc ] ; then
		CCPATH=$cc
	else
		for i in $MYP; do
			if [ -f $i/$cc -a -z "$CCPATH" ] ; then
				CCPATH=$i/$cc
			fi
		done
	fi
	if [ -z "$CCPATH" ]; then runonce="Yes"; fi
done
if [ "$FOO" != "$cc" ] ; then
	MYP=`echo "$CCPATH" | sed -e 's@/@ @g'`
	set $MYP
	if [ $2 ] ; then
		while [ $2 ] ; do
			shift
		done
	fi
	if [ $1 = "gcc" ] ; then
		CCPATH="$CCPATH"
	fi
fi
echo "Compiler selected: $CCPATH"
echo " "
# Check it out
cat > $TMP <<__EOF__
main() {}
__EOF__
$CCPATH $TMP -o $EXEC >/dev/null 2>&1
if [ ! -f $EXEC ] ; then
        echo "You don't have $CCPATH or it's broken!"
        exit 1
fi
# Fix Makefile
#
$RM -f Makefile.tmp
sed -e "s@^CC=\(.*\)@CC=$CCPATH@" Makefile > Makefile.tmp
cp Makefile.tmp Makefile
$RM -f Makefile.tmp
#
echo "Enter additional flags to give to $CCPATH"
FOO=`egrep "^XCFLAGS=" Makefile 2>/dev/null | sed -e 's/^[^=]*=[	 ]*\(.*\)/\1/'`
if [ -z "$FOO" ] ; then
    echo "I recommend $DEFCFLAGS"
    FOO="$DEFCFLAGS"
fi
echo $n "[$FOO] -> $c"
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
    read cc
else
    cc=""
fi
if [ -z "$cc" ] ; then
	cc="$FOO"
fi
if [ "$cc" = "none" ] ; then
	cc=''
fi
XCFLAGS=$cc
# Fix Makefile
#
$RM -f Makefile.tmp
sed -e "s@^XCFLAGS=\(.*\)@XCFLAGS=$XCFLAGS@" Makefile > Makefile.tmp
cp Makefile.tmp Makefile
$RM -f Makefile.tmp
#
cat <<__EOF__

If you need to use any extra libraries when compiling the server,
please tell me now (might need to look at the Makefiles) and please
include all the -l and -L flags.

You should use the recommended value unless you have a compelling reason
not to...
__EOF__
LIBS=`egrep "^IRCDLIBS=" Makefile 2>/dev/null | sed -e 's/^[^=]*=\(.*\)/\1/' | tr -d "\012"`
if [ -z "$LIBS" ] ; then
    echo "I suggest: $DEFLIBS"
    LIBS="$DEFLIBS"
fi
echo $n "[$LIBS] -> $c"
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
    read cc
else
    cc=""
fi
if [ -z "$cc" ] ; then
	cc="$LIBS"
fi
if [ "$cc" = "none" ] ; then
	cc=''
fi
LIBS=$cc
# Fix Makefile
#
$RM -f Makefile.tmp
sed -e "s@^IRCDLIBS=\(.*\)@IRCDLIBS=$LIBS@" Makefile > Makefile.tmp
cp Makefile.tmp Makefile
$RM -f Makefile.tmp
#
COMP="$CCPATH $XCFLAGS $TMP -o $EXEC $LIBS"
#
echo 'Checking out /usr/include'
echo $n "...Looking for /usr/include/stdlib.h...$c"
if [ -r /usr/include/stdlib.h ] ; then
	STDLIBH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for stddef.h...$c"
if [ -r /usr/include/stddef.h ] ; then
        STDDEFH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for /usr/include/sys/syslog.h...$c"
if [ -r /usr/include/sys/syslog.h ] ; then
	SYSSYSLOGH=define
	echo  'found!'
else
	echo 'not found :('
fi
#echo $n "...Looking for malloc.h...$c"
#if [ -r /usr/include/malloc.h ] ; then
#	MALLOCH=malloc.h
#	echo  'found!'
#elif [ -r /usr/include/sys/malloc.h ] ; then
#	MALLOCH=sys/malloc.h
#	echo  'found!'
#else
#	echo 'not found :('
#	MALLOCH=undef
#fi

echo $n "...Looking for /usr/include/sys/param.h...$c"
if [ -r /usr/include/sys/param.h ] ; then
	PARAMH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for /usr/include/unistd.h...$c"
if [ -r /usr/include/unistd.h ] ; then
	UNISTDH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for /usr/include/string.h...$c"
if [ -r /usr/include/string.h ] ; then
	STRINGH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for /usr/include/strings.h...$c"
if [ -r /usr/include/strings.h ] ; then
	STRINGSH=define
	echo  'found!'
else
	echo 'not found :('
fi
echo $n "...Looking for /usr/include/sys/rusage.h...$c"
if [ -r /usr/include/sys/rusage.h ] ; then
	RUSAGEH=define
	echo  'found!'
else
	echo 'not found (good!)'
fi
#
# to b or not to b
#
echo " "
echo $n "To be or not to be...$c"
cat > $TMP <<__EOF__
main()
{
	char	a[3], b[3];
	bzero(b,3);
	bcopy(a,b,3);
	(void)bcmp(a,b,3);
	exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	echo "and so it shall be! bcopy/bzero/bcmp are about!"
	BZERO=bzero
else
	echo "and it wasn't.  No bcopy/bzero/bcmp...hmpf"
	BZERO=memset
fi
echo " "
echo $n "Which one, gettimeofday, or lrand48..$c"
cat > $TMP <<__EOF__
#include <stdio.h>
#include <sys/time.h>
main()
 {
   struct timeval tv;
   (void) gettimeofday(&tv, NULL);
 }
__EOF__
$COMP >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	echo "We have a winner! gettimeofday found."
	GETTIMEOFDAY=define
else
	echo "No gettimeofday. Lets try lrand48."
cat > $TMP <<__EOF__
main()
{
   int a;
   a=lrand48();
}
__EOF__
	$COMP >/dev/null 2>&1
	if [ $? -eq 0 ] ; then
 		echo "Bingo! lrand48!"
		LRAND48=define
	fi
fi
#
# check for non-blocking fd style available..
#
echo " "
echo 'Checking for POSIX/BSD/SYSV non-blocking stuff'
if [ -f $TMP -o -d $TMP ] ; then
	$RM -f $TMP
fi
cat > $PLATE <<__EOF__
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <signal.h>
alarmed()
{
	exit(1);
}
main()
{
	char b[12], x[32];
	int f, l = sizeof(x);
	f = socket(AF_INET, SOCK_DGRAM, 0);
	if (f >= 0 && !(fcntl(f, F_SETFL, BLOCKING))) {
		signal(SIGALRM, alarmed);
		alarm(3);
		recvfrom(f, b, 12, 0, x, &l);
		alarm(0);
		exit(0);
	}
	exit(1);
}
__EOF__
sed -e 's/BLOCKING/O_NONBLOCK/' $PLATE > $TMP
$COMP >/dev/null 2>&1
if [ 0 -eq $? ] ; then
	$EXEC
fi
if [ 0 -eq $? ] ; then
	BLOCK=O_NONBLOCK
else
	echo 'O_NONBLOCK not present/working in fcntl.h or sys/ioctl.h'
	if [ -f $TMP -o -d $TMP ] ; then
		$RM -f $TMP $EXEC;
	fi
	sed -e 's/BLOCKING/O_NDELAY/' $PLATE > $TMP
	$COMP >/dev/null 2>&1
	if [ 0 -eq $? ] ; then
		$EXEC
	fi
	if [ 0 -eq $? ] ; then
		BLOCK=O_NDELAY
	else
		echo 'O_NDELAY not present/working in fcntl.h or sys/ioctl.h'
		if [ -f $TMP -o -d $TMP ] ; then
			$RM -f $TMP $EXEC;
		fi
		sed -e 's/BLOCKING/FIONBIO/' $PLATE > $TMP
		$COMP >/dev/null 2>&1
		if [ 0 -eq $? ] ; then
			echo 'FIONBIO not found!  No option found!'
			BLOCK=none
		else
			BLOCK=FIONBIO
		fi
	fi
fi
$RM -f $TMP $PLATE $EXEC
echo "Blocking selected: $BLOCK";
#
# reliable signals ?
#
echo 'Looking for reliable signals...'
echo "Hmmm...wonder if you have 'action from POSIX..."
cat > $TMP <<__EOF__
#include <signal.h>

main()
{	/* poor replacement for NULL but who cares here ? */
	sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	echo "Ooooh, you are a lucky one! 'action from POSIX!"
	SIGNAL=posix
else
	$RM -f $EXEC $TMP
	cat > $TMP <<__EOF__
#include <signal.h>
int	calls = 0;
void	handler()
{
	if (calls)
		return;
	calls++;
	kill(getpid(), SIGTERM);
	sleep(1);
}
main()
{
	signal(SIGTERM, handler);
	kill(getpid(), SIGTERM);
	exit (0);
}
__EOF__
	echo $n "Nope, but you have...$c"
	$COMP >/dev/null 2>&1
	$EXEC
	if [ $? -eq 0 ] ; then
		echo 'reliable signals! Cheers BSD!'
		SIGNAL=bsd
	else
		echo "yucky, unreliable SYSV!"
		SIGNAL=sysv
	fi
fi
$RM -f $EXEC $TMP
#
echo 'Now those strings libraries...hmm...which one is it...'
cat > $TMP <<__EOF__
#$STRINGH STRINGH
#$STRINGSH STRINGSH
#ifdef STRINGH
#include <string.h>
#endif
#ifdef STRINGSH
#include <strings.h>
#endif
main()
{
	char *s = index("foo", 'o');
	exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	echo "Cool...you have index()!"
else
	NOINDEX=define
	echo "Grmpf...I guess there is a strchr() out there somewhere..."
fi
$RM -f $EXEC $TMP
#
# getrusage or times ?
#
echo $n "One for debugging, mainly, getrusage(2) or times(2)...$c"
cat > $TMP <<__EOF__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
main()
{
	struct	rusage	rus;
	(void)getrusage(RUSAGE_SELF, &rus);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -eq 0 ] ; then
	TIMES=getrusage
	echo "getrusage()"
else
	$RM -f $EXEC $TMP
	cat > $TMP <<__EOF__
#include <sys/types.h>
#include <sys/time.h>
#include <sys/times.h>
main()
{
	struct	tms	tmsbuf;
	(void)times(&tmsbuf);
}
__EOF__
	$COMP >/dev/null 2>&1
	if [ $? -eq 0 ] ; then
		TIMES=times
		echo "times()"
	else
		echo "couldn't get either ?!"
		TIMES=none
	fi
fi
#
# what do we need that isn't here already ?
#
echo "What else do I need that you don't have..."
echo $n "Lets see...$c"
cat > $TMP <<__EOF__
main()
{
	unsigned long foo;

	char  *s = strtoul("0x12345", &foo, 16);
	exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo $n " strtoul$c"
    $RM -f Makefile.tmp
    sed -e "s@^STRTOUL=\(.*\)@STRTOUL=strtoul.o@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
else
    $RM -f Makefile.tmp
    sed -e "s@^STRTOUL=\(.*\)@STRTOUL=@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
fi
$RM -f $EXEC $TMP
cat > $TMP <<__EOF__
main()
{
	char  *s = strerror(0);
	exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " strerror$c"
	NSTRERROR=define
fi
$RM -f $EXEC $TMP
cat > $TMP <<__EOF__
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>

main()
{
	dn_skipname("","");
	exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
# dn_skipname passes the small test but won't resolve when ircd is linked.
# Hmmm...
if [ $? -ne 0 -o "$OSNAME" = "Linux RedHat 5.0" -o -n "$NEEDSKIPNAME" ] ; then
    echo $n " dn_skipname$c"
    $RM -f Makefile.tmp
    sed -e "s@^RES=\(.*\)@RES=res_skipname.o@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
else
    $RM -f Makefile.tmp
    sed -e "s@^RES=\(.*\)@RES=@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
fi
$RM -f $EXEC $TMP
cat > $TMP <<__EOF__
#include <sys/types.h>
main()
{
    u_int32_t foo;
    exit(0);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo $n " u_int32_t$c"
    $RM -f Makefile.tmp
    sed -e "s@^NEED_U_INT32_T=\(.*\)@NEED_U_INT32_T=-DNEED_U_INT32_T@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
else
    $RM -f Makefile.tmp
    sed -e "s@^NEED_U_INT32_T=\(.*\)@NEED_U_INT32_T=@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
fi
$RM -f $EXEC $TMP
cat > $TMP <<__EOF__
#$STRINGH STRINGH
#$STRINGSH STRINGSH
#ifdef STRINGH
#include <string.h>
#endif
#ifdef STRINGSH
#include <strings.h>
#endif
main()
{
	char  t[] = "a", **p = NULL, *s = strtoken(&p, t, ",");
	if (!strcmp(t, s))
		exit(0);
	exit(1);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " strtoken$c"
	NSTRTOKEN=define
else
	$EXEC
	if [ $? -ne 0 ] ; then
		echo $n " strtoken$c"
		NSTRTOKEN=define
	fi
fi
$RM -f $EXEC $TMP
cat > $TMP <<__EOF__
#$STRINGH STRINGH
#$STRINGSH STRINGSH
#ifdef STRINGH
#include <string.h>
#endif
#ifdef STRINGSH
#include <strings.h>
#endif
main()
{
	char  t[] = "a", *s = strtok(t, ",");
	if (!strcmp(t, s))
		exit(0);
	exit(1);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " strtok$c"
	NSTRTOK=define
else
	$EXEC
	if [ $? -ne 0 ] ; then
		echo $n " strtok$c"
		NSTRTOK=define
	fi
fi
$RM -f $EXEC $TMP
cat > $TMP << __EOF__
#include <sys/types.h>
#include <netinet/in.h>
main()
{
	struct	in_addr in;
	(void)inet_addr("1.2.3.4");
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " inet_addr$c"
	NINETADDR=define
fi
$RM -f $EXEC $TMP
cat > $TMP << __EOF__
#include <sys/types.h>
#include <netinet/in.h>
main()
{
	struct	in_addr	in;
	in.s_addr = 0x12345678;
	(void)inet_ntoa(in);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " inet_ntoa$c"
fi
$RM -f $EXEC $TMP
cat > $TMP << __EOF__
#include <sys/types.h>
#include <netinet/in.h>
main()
{
	struct	in_addr	in;
	in.s_addr = 0x87654321;
	(void)inet_netof(in);
}
__EOF__
$COMP >/dev/null 2>&1
if [ $? -ne 0 ] ; then
	echo $n " inet_netof$c"
	NINETNETOF=define
fi
$RM -f $EXEC $TMP
echo " "
#
#
#
echo " "
echo "Ok, here's your chance...I think you should use $BLOCK, you want"
echo "which of these ? O_NONBLOCK (POSIX) O_NDELAY (BSD) FIONBIO (SYSV)"
echo $n "[$BLOCK] -> $c"
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
    read cc
else
    cc=""
fi
if [ "$cc" = "none" ] ; then
	cc=''
elif [ -z "$cc" ] ; then
	cc=$BLOCK
fi
BLOCK=$cc
echo "I found $SIGNAL signals."
if [ "$cc" = "none" ] ; then
	cc=''
elif [ "$SIGNAL" = "posix" ] ; then
	echo "Hmmm...I'm not sure if signal() is reliable or not either..."
fi
echo "You can choose between posix, bsd and sysv.  What'll it be ?"
echo $n "[$SIGNAL] -> $c"
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
    read cc
else
    cc=""
fi
if [ "$cc" = "none" ] ; then
	cc=''
elif [ -z "$cc" ] ; then
	cc=$SIGNAL
fi
SIGNAL=$cc
if [ "$TIMES" = "none" ] ; then
	echo "I didn't find either getrusage or times earlier...If you do have"
	echo "either of these, please tell me now."
else
	echo "I found $TIMES, out of getrusage and times.  getrusage is"
	echo "more informative.  If you wish to swap your choice, please"
	echo "do so now."
fi
echo $n "[$TIMES] -> $c"
if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
    read cc
else
    cc=""
fi
if [ "$cc" = "none" ] ; then
	cc=''
elif [ -z "$cc" ] ; then
	cc=$TIMES
fi
TIMES=$cc

$RM -f $EXEC $TMP $PLATE
cat > $SETUP  <<__EOF__
#ifndef __setup_include__
#define __setup_include__
#$PARAMH	PARAMH
#$UNISTDH	UNISTDH
#$STRINGH	STRINGH
#$STRINGSH	STRINGSH
#$STDLIBH	STDLIBH
#$STDDEFH	STDDEFH
#$SYSSYSLOGH	SYSSYSLOGH
#$NOINDEX	NOINDEX
#$NSTRERROR	NEED_STRERROR
#$NSTRTOKEN	NEED_STRTOKEN
#$NSTRTOK	NEED_STRTOK
#$NINETADDR	NEED_INET_ADDR
#$NINETNTOA	NEED_INET_NTOA
#$NINETNETOF	NEED_INET_NETOF
#$GETTIMEOFDAY	GETTIMEOFDAY
#$LRAND48	LRAND48
__EOF__
if [ "$MALLOCH" = "undef" ] ; then
	echo "#undef	MALLOCH" >> $SETUP
else
	echo "#define	MALLOCH	<$MALLOCH>" >> $SETUP
fi
if [ "$BZERO" = "memset" ] ; then
	cat >> $SETUP <<__EOF__
#define	bzero(a,b)	memset(a,0,b)
#define	bcopy(a,b,c)	memcpy(b,a,c)
#define	bcmp	memcmp
__EOF__
fi
if [ "$BLOCK" = "O_NONBLOCK" ] ; then
	echo "#define	NBLOCK_POSIX" >> $SETUP
elif [ "$BLOCK" = "O_NDELAY" ] ; then
	echo "#define	NBLOCK_BSD" >> $SETUP
else
	echo "#define	NBLOCK_SYSV" >> $SETUP
fi
if [ "$SIGNAL" = "posix" ] ; then
	echo "#define	POSIX_SIGNALS" >> $SETUP
elif [ "$SIGNAL" = "bsd" ] ; then
	echo "#define	BSD_RELIABLE_SIGNALS" >> $SETUP
else
	echo "#define	SYSV_UNRELIABLE_SIGNALS" >> $SETUP
fi
if [ "$TIMES" = "times" ] ; then
	echo "#define	TIMES_2" >> $SETUP
	echo "#undef	GETRUSAGE_2" >> $SETUP
elif [ "$TIMES" = "getrusage" ] ; then
	echo "#undef	TIMES_2" >> $SETUP
	echo "#define	GETRUSAGE_2" >> $SETUP
else
	echo "#undef	TIMES_2" >> $SETUP
	echo "#undef	GETRUSAGE_2" >> $SETUP
fi
echo "#endif" >> $SETUP

#
# Now, get site specific options.
#

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$NOSPOOF" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Many operating systems are running with insecure TCP stacks."
    echo "This allows IP spoofing attacks, which are very difficult for"
    echo "operators to track down and ban."
    echo ""
    echo "If you are CERTAIN your operating system has secure TCP stacks"
    echo "you do not need to define this.  If you are not certain, define"
    echo "this and find out if you need it later or not.  You can mail the"
    echo "source mailing list later; someone there can help you determine"
    echo "if your OS is secure or not."
    echo ""

        if [ "$OSNAME" = "FreeBSD 2.2" ]; then
        echo "Your version of FreeBSD is 2.2-Release or later, so you do not"
        echo "need to run nospoof."
        echo ""
        FOO=No
        fi

        if [ "$OSNAME" = "FreeBSD" ]; then
        echo "If your version of FreeBSD is 2.2-Release or later, you do not"
        echo "need to run nospoof."
        echo ""
        fi

    echo "Do you have an insecure operating system and therefore want to"
    echo "use the server anti-spoof protection?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    NOSPOOF="1"
	    ;;
	[Nn]*)
	    NOSPOOF=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done

if [ -n "$NOSPOOF" ] ; then

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$NOSPOOF_SEED01"
    echo "For security, the nospoof code uses two special values, called"
    echo "seeds.  Here, please enter one of them.  The values are in"
    echo "hexidecimal (base 16) using the digits 0123456789abcdef.  Each"
    echo "value can contain up to 8 digits, and should be specified in the"
    echo "form 0x12345678.  If you use the defaults, that should be ok, but"
    echo "it is more secure if you choose your own special values and keep"
    echo "them secret."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	0x[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
	    NOSPOOF_SEED01=$cc
	    ;;
	[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
	    NOSPOOF_SEED01=0x$cc
	    ;;
	*)
	    echo " "
	    echo "Read the instructions and try again...  You did not enter the"
	    echo "value correctly."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$NOSPOOF_SEED02"
    echo "For security, the nospoof code uses two special values, called"
    echo "seeds.  Here, please enter one of them.  The values are in"
    echo "hexidecimal (base 16) using the digits 0123456789abcdef.  Each"
    echo "value can contain up to 8 digits, and should be specified in the"
    echo "form 0x12345678.  If you use the defaults, that should be ok, but"
    echo "it is more secure if you choose your own special values and keep"
    echo "them secret."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	0x[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
	    NOSPOOF_SEED02=$cc
	    ;;
	[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])
	    NOSPOOF_SEED02=0x$cc
	    ;;
	*)
	    echo " "
	    echo "Read the instructions and try again...  You did not enter the"
	    echo "value correctly."
	    echo ""
	    FOO=""
	    ;;
    esac
done

# this matches a NOSPOOF check waaaaaay up there
fi

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -z "$CONTACT_URL" ] ; then
	if [ -z "$CONTACT_EMAIL" ] ; then
    	    if [ "$NS_ADDRESS" = "nospoof@dal.net" ] ; then
		CONTACT_INFO="http://www.dal.net/connect/"
	    else
		CONTACT_INFO="none"
	    fi
	else
	    CONTACT_INFO="$CONTACT_EMAIL"
	fi
    else
	CONTACT_INFO="$CONTACT_URL"
    fi
    FOO="$CONTACT_INFO"
    echo " "
    echo "Where should users turn to when they have connection"
    echo "problems, nospoof or otherwise? This can be any valid"
    echo "email address, ftp URL, or http URL. It can also be"
    echo "set as 'none', causing the connection problems contact"
    echo "section of the connect-time messages to be omitted completely."
    echo " "
    echo "Entries must follow one of the following formats:"
    echo "email address:  admin@server.net"
    echo "      ftp URL:  ftp://ftp.borg.com/pub/connection.txt"
    echo "     http URL:  http://www.dal.net/connect/"
    echo " "
    echo "For DALnet servers, this should be set to"
    echo "http://www.dal.net/connect/"
    echo "If your server is NOT part of DALnet, please enter"
    echo "another point of help (such as the admin's email address),"
    echo "or set this to 'none'."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" -o -z "$FOO" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	none)
	    CONTACT_URL=''
	    CONTACT_EMAIL=''
	    FOO=$cc
	    ;;
	nospoof@dal.net)
	    echo " "
	    echo "You have entered the former contact point for DALnet"
	    echo "servers. This address is no longer the main point of"
	    echo "help for connections. If this is indeed a DALnet"
	    echo "server, please use the URL listed in the instructions."
	    echo "If this is NOT a DALnet server, please provide another"
	    echo "point of contact, or enter 'none'"
	    echo " "
	    echo $n "[Enter to Continue]"
	    read cc
	    FOO=""
	    ;;
	http://*.*)
	    CONTACT_URL=$cc
	    CONTACT_EMAIL=''
	    FOO=$CONTACT_INFO
	    ;;
	ftp://*.*)
	    CONTACT_URL=$cc
	    CONTACT_EMAIL=''
	    FOO=$CONTACT_INFO
	    ;;
	*@*.*)
	    CONTACT_URL=''
	    CONTACT_EMAIL=$cc
	    FOO=$CONTACT_INFO
	    ;;
	*)
	    echo " "
	    echo "Read the instructions and examples, then try again..."
	    echo "Your entry here must be blank or one of the valid"
	    echo "types."
	    echo " "
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$KLINE_ADDRESS"
    echo " "
    echo "What is the contact address for connect problems due to the"
    echo "user being K:lined, shown to the user when they attempt to"
    echo "connect?  This should be a valid email address."
    echo " "
    echo "For DALnet servers, note that this message is displayed when"
    echo "the user is affected by a local K:line or k:line.  With"
    echo "Services-based autokills, the message is set up automatically"
    echo "by Services to ask the user to email kline@dal.net.  It is"
    echo "recommended that you set this up to give a valid email address"
    echo "for the server's admin, not kline@dal.net."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" -o -z "$FOO" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Kk][Ll][Ii][Nn][Ee]@[Dd][Aa][Ll].[Nn][Ee][Tt])
	    KLINE_ADDRESS=$cc
	    FOO=""
	    echo " "
	    while [ -z "$FOO" ] ; do
		FOO="No"
		echo "Please note that kline@dal.net does not handle server-specific"
		echo "K:lines."
		echo "Are you sure you want to set the address to kline@dal.net?"
		echo $n "[$FOO] -> $c"
		if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
		    read cc
		else
		    cc=""
		    runonce=Yes
		fi
		if [ -z "$cc" ] ; then
		    cc=$FOO
		fi
		case "$cc" in
		    [Yy]*)
			;;
		    [Nn]*)
			KLINE_ADDRESS=""
			;;
		    *)
			echo ""
			echo "You need to enter either Yes or No here..."
			echo ""
			FOO=""
			;;
		esac
	    done
	    FOO="$KLINE_ADDRESS"
	    ;;
	*@*.*)
	    KLINE_ADDRESS=$cc
	    FOO="$KLINE_ADDRESS"
	    ;;
	*)
	    echo " "
	    echo "Read the instructions and try again...  You did not enter a"
	    echo "proper email address (user@host.domain)."
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$SERVICES_NAME"
    echo " "
    echo "If you have network services and would like to make use of "
    echo "the built in secure services aliasing features, type in the "
    echo "name of your network services server here. If you are a "
    echo "DALnet admin, you would type in \"services.dal.net\" below."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" -o -z "$SERVICES_NAME" ] ; then
	read cc
	runonce=Yes
    else
	cc=""
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
done
SERVICES_NAME=$cc

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$DPATH"
    echo ""
    echo "What directory are all the server configuration files in?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
done
DPATH=$cc

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$SPATH"
    echo ""
    echo "What is the explicit path to where the ircd binary will be"
    echo "installed?  This should point to a file, not a directory"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
done
SPATH=$cc

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$DOMAINNAME"
    echo ""
    echo "What is your local domain name?  This is used for /stats w to"
    echo "report local clients vs. remote clients."

        if [ "$OSNAME" = "FreeBSD" -o "$OSNAME" = "FreeBSD 2.2" ]; then
        MACHINENAME=`hostname -s`
        HOSTNAME=${hostname}
        FOO=${HOSTNAME#$MACHINENAME.}
        fi

    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    FOO=$cc
done
DOMAINNAME=$cc

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$SHOWOPERS" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Would you like non opers to see your O:lines?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
	runonce=Yes
    else
	cc=""
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    SHOWOPERS="YES"
	    ;;
	[Nn]*)
	    SHOWOPERS=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$HUB" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Are you running as a HUB?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    HUB="1"
	    ;;
	[Nn]*)
	    HUB=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done


FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$UNIXPORT" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Would you like clients local to the SERVER MACHINE to be able to"
    echo "use Unix domain sockets?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    UNIXPORT="1"
	    ;;
	[Nn]*)
	    UNIXPORT=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$CRYPT_OPER_PASSWORD" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Do you use encrypted operator passwords?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    CRYPT_OPER_PASSWORD="1"
	    ;;
	[Nn]*)
	    CRYPT_OPER_PASSWORD=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    if [ -n "$CRYPT_LINK_PASSWORD" ] ; then
	FOO="Yes"
    else
	FOO="No"
    fi
    echo ""
    echo "Do you use encrypted incoming link passwords? (N lines only,"
    echo "C lines must remain unencrypted always)"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[Yy]*)
	    CRYPT_LINK_PASSWORD="1"
	    ;;
	[Nn]*)
	    CRYPT_LINK_PASSWORD=""
	    ;;
	*)
	    echo ""
	    echo "You need to enter either Yes or No here..."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$LISTEN_SIZE"
    echo ""
    echo "What listen() backlog value do you wish to use?  Some servers"
    echo "have problems with more than 5, others work fine with many, many"
    echo "more."
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[1-9]*)
	    LISTEN_SIZE="$cc"
	    ;;
	*)
	    echo ""
	    echo "You need to enter a number here."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$NICKNAMEHISTORYLENGTH"
    echo ""
    echo "How far back do you want to keep the nickname history?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[1-9]*)
	    NICKNAMEHISTORYLENGTH="$cc"
	    ;;
	*)
	    echo ""
	    echo "You need to enter a number here."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$MAXSENDQLENGTH"
    echo ""
    echo "What sendq length do you wish to have?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[1-9]*)
	    MAXSENDQLENGTH="$cc"
	    ;;
	*)
	    echo ""
	    echo "You need to enter a number here."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$BUFFERPOOL"
    echo ""
    echo "What size of a bufferpool (total of ALL sendq's in use) do you"
    echo "do you wish to have?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	\([1-9]*\))
	    BUFFERPOOL="$cc"
	    ;;
	*)
	    echo ""
	    echo "You need to enter a number here, either based on"
	    echo "MAXSENDQLENGTH or a literal value.  Also, this value"
	    echo "MUST be enclosed in parens -- (9*MAXSENDQLENGTH), for example."
	    echo ""
	    FOO=""
	    ;;
    esac
done

FOO=""
runonce=""
while [ -z "$FOO" ] ; do
    FOO="$MAXCONNECTIONS"
    echo ""
    echo "How many file descriptors (or sockets) can the irc server use?"
    echo $n "[$FOO] -> $c"
    if [ -z "$AUTO_CONFIG" -o -n "$runonce" ] ; then
	read cc
    else
	cc=""
	runonce=Yes
    fi
    if [ -z "$cc" ] ; then
	cc=$FOO
    fi
    case "$cc" in
	[1-9][0-9][0-9]*)
	    MAXCONNECTIONS="$cc"
	    ;;
	*)
	    echo ""
	    echo "You need to enter a number here, greater or equal to 100."
	    echo ""
	    FOO=""
	    ;;
    esac
done

#
# check FD_SETSIZE and override if needed.
#

cat > $TMP <<__EOF__
#include <stdio.h>
#include <sys/types.h>

#ifndef FD_SETSIZE
#define FD_SETSIZE -1
#endif

/*
 * Prints "notdef" if FD_SETSIZE is undefined,
 *        "ok"     if FD_SETSIZE is at least as large as provided on the
 *                 compile command line (-DMAXCONNECTIONS=1234)
 *        "###"    if it is less.  (### is the FD_SETSIZE value)
 */
int
main(int argc, char *argv[])
{
	if (FD_SETSIZE == -1)
		printf("notdef\n");
	else if (FD_SETSIZE >= MAXCONNECTIONS)
		printf("ok\n");
	else
		printf("%d\n", FD_SETSIZE);

	return 0;
}
__EOF__
$COMP "-DMAXCONNECTIONS=$MAXCONNECTIONS" >/dev/null 2>&1
if [ $? -ne 0 ] ; then
    echo " "
    echo "I could not derrive what your system allows for the maximum number"
    echo "of connections becuase the test program did not compile."
    echo " "
    FD_SETSIZE=""
else
    fd_setsize_ok=`$EXEC`
    case $fd_setsize_ok in
	notdef)
	    echo " "
	    echo "I could not derrive what your system allows for the maximum"
	    echo "number of connections because the test program did not find"
	    echo "a system-supplied value for FD_SETSIZE.  Assuming it is"
	    echo "defined correctly but the test program cannot find it."
	    echo " "
	    FD_SETSIZE=""
	    ;;
	ok)
	    echo " "
	    echo "Your system-supplied value for FD_SETSIZE is large enough"
	    echo "for ircd to leave it untouched."
	    echo " "
	    FD_SETSIZE=""
	    ;;
	*)
	    echo " "
	    echo "Your system-supplied value for FD_SETSIZE is $fd_setsize_ok"
	    echo "but you requested $MAXCONNECTIONS for ircd.  FD_SETSIZE will"
	    echo "be overridden using -DFD_SETSIZE=$MAXCONNECTIONS when"
	    echo "compiling ircd."
	    echo " "
	    FD_SETSIZE=$MAXCONNECTIONS
	    ;;
    esac
fi

if [ -n "$FD_SETSIZE" ] ; then
    $RM -f Makefile.tmp
    sed -e "s@^FD_SETSIZE=\(.*\)@FD_SETSIZE=-DFD_SETSIZE=$FD_SETSIZE@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
else
    $RM -f Makefile.tmp
    sed -e "s@^FD_SETSIZE=\(.*\)@FD_SETSIZE=@" Makefile > Makefile.tmp
    cp Makefile.tmp Makefile
    $RM -f Makefile.tmp
fi

$RM -f $EXEC $TMP


cat <<__EOF__

The file "$OPTIONS" was either created or rewritten to contain your
answers to the above questions.

This file is automatically generated and will be updated each time you
run Config.  You should retain a copy of this to help migrate to future
versions of the DALnet server with ease.

__EOF__

#
# create the $OPTIONS_H file
#
rm -f $OPTIONS_H
cat > $OPTIONS_H << __EOF__
/*
 * VERSION: $IRCD_VERSION
 * DATE:    $CONF_DATE
 *
 * This file is automatically generated and will be updated each time you
 * run Config.  YOU SHOULD NOT EDIT THIS FILE.  Instead, edit "$OPTIONS" in
 * the same directory as Config, and rerun to regenerate this file.
 */

#define DPATH "$DPATH"
#define SPATH "$SPATH"
#define LISTEN_SIZE $LISTEN_SIZE
#define MAXSENDQLENGTH $MAXSENDQLENGTH
#define BUFFERPOOL $BUFFERPOOL
#define MAXCONNECTIONS $MAXCONNECTIONS
#define NICKNAMEHISTORYLENGTH $NICKNAMEHISTORYLENGTH
__EOF__
if [ -n "$SHOWOPERS" ] ; then
    echo "#define SHOWOPERS" >> $OPTIONS_H
else
    echo "#undef SHOWOPERS" >> $OPTIONS_H
fi
if [ -n "$HUB" ] ; then
    echo "#define HUB 1" >> $OPTIONS_H
else
    echo "#undef HUB" >> $OPTIONS_H
fi
if [ -n "$CRYPT_OPER_PASSWORD" ] ; then
    echo "#define CRYPT_OPER_PASSWORD 1" >> $OPTIONS_H
else
    echo "#undef CRYPT_OPER_PASSWORD" >> $OPTIONS_H
fi
if [ -n "$CRYPT_LINK_PASSWORD" ] ; then
    echo "#define CRYPT_LINK_PASSWORD 1" >> $OPTIONS_H
else
    echo "#undef CRYPT_LINK_PASSWORD" >> $OPTIONS_H
fi
if [ -n "$UNIXPORT" ] ; then
    echo "#define UNIXPORT 1" >> $OPTIONS_H
else
    echo "#undef UNIXPORT" >> $OPTIONS_H
fi
if [ -n "$NOSPOOF" ] ; then
    echo "#define NOSPOOF 1" >> $OPTIONS_H
else
    echo "#undef NOSPOOF" >> $OPTIONS_H
fi
if [ -n "$NOSPOOF_SEED01" ] ; then
    echo "#define NOSPOOF_SEED01 $NOSPOOF_SEED01" >> $OPTIONS_H
fi
if [ -n "$NOSPOOF_SEED02" ] ; then
    echo "#define NOSPOOF_SEED02 $NOSPOOF_SEED02" >> $OPTIONS_H
fi
if [ -n "$CONTACT_URL" ] ; then
    echo "#define CONTACT_URL \"$CONTACT_URL\"" >> $OPTIONS_H
fi
if [ -n "$CONTACT_EMAIL" ] ; then
    echo "#define CONTACT_EMAIL \"$CONTACT_EMAIL\"" >> $OPTIONS_H
fi
if [ -n "$SERVICES_NAME" ] ; then
    echo "#define SERVICES_NAME \"$SERVICES_NAME\"" >> $OPTIONS_H
fi
if [ -n "$KLINE_ADDRESS" ] ; then
    echo "#define KLINE_ADDRESS \"$KLINE_ADDRESS\"" >> $OPTIONS_H
fi
if [ -n "$DOMAINNAME" ] ; then
    echo "#define DOMAINNAME \"$DOMAINNAME\"" >> $OPTIONS_H
else
    echo "undef DOMAINNAME" >> $OPTIONS_H
fi

#
# create the persistant file
#
rm -f $OPTIONS
cat > $OPTIONS << __EOF__
#
# VERSION: $IRCD_VERSION
# DATE:    $CONF_DATE
#
# This file is automatically generated and will be updated each time you
# run Config.  You should retain a copy of this to help migrate to future
# versions of the DALnet server with ease.
#
LAST_VERSION="$IRCD_VERSION"
NOSPOOF="$NOSPOOF"
NOSPOOF_SEED01="$NOSPOOF_SEED01"
NOSPOOF_SEED02="$NOSPOOF_SEED02"
CONTACT_URL="$CONTACT_URL"
CONTACT_EMAIL="$CONTACT_EMAIL"
SERVICES_NAME="$SERVICES_NAME"
KLINE_ADDRESS="$KLINE_ADDRESS"
DPATH="$DPATH"
SPATH="$SPATH"
HUB="$HUB"
CRYPT_OPER_PASSWORD="$CRYPT_OPER_PASSWORD"
CRYPT_LINK_PASSWORD="$CRYPT_LINK_PASSWORD"
LISTEN_SIZE="$LISTEN_SIZE"
MAXSENDQLENGTH="$MAXSENDQLENGTH"
BUFFERPOOL="$BUFFERPOOL"
UNIXPORT="$UNIXPORT"
MAXCONNECTIONS="$MAXCONNECTIONS"
DOMAINNAME="$DOMAINNAME"
NICKNAMEHISTORYLENGTH="$NICKNAMEHISTORYLENGTH"

__EOF__

cat <<__EOF__

 Config is complete.

 Before compiling, check the contents of include/config.h for any strange
 things you usually set.  If you want them to be included in the future,
 ask them to be moved to the options.h file on dalnet-src@dal.net.

__EOF__
