# @(#) $Header: configure,v 1.15 94/07/05 10:48:22 deyke Exp $

case "`uname -sr`" in
HP-UX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=c89;;
AIX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-L; cc=cc;;
IRIX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-L; cc=cc;;
Linux*)
	isdir=-d; isexec=-x; isfile=-f; islink=-L; cc=gcc;;
386BSD*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=cc;;
BSD/386*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=cc;;
SunOS\ 4.*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=acc;;
SunOS\ 5.*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=cc;;
ULTRIX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=gcc;;
A/UX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=gcc;;
RISC\ iX*)
	isdir=-d; isexec=-x; isfile=-f; islink=-h; cc=/tcp/cc;;
AOS*)
	isdir=-d; isexec=-x; isfile=-f; islink=-L; cc=/usr/local/bin/gcc;;
*)
	echo System `uname -sr` is not supported >&2
	exit 1;;
esac

tmp=tmp$$

findfile()
{
	name=$1
	shift
	for i in $*; do
		if [ $isfile $i -a ! $islink $i ]; then
			echo "#define ${name} \"$i\""
			return
		fi
	done
	echo "#define ${name} \"\""
}

findprog()
{
	name=$1
	shift
	for i in $*; do
		if [ $isfile $i -a $isexec $i -a ! $islink $i ]; then
			echo "#define ${name} \"$i\""
			return
		fi
	done
	for i in $*; do
		if [ $isfile $i -a $isexec $i ]; then
			echo "#define ${name} \"$i\""
			return
		fi
	done
	echo "#define ${name} \"\""
}

finddir()
{
	name=$1
	shift
	for i in $*; do
		if [ $isdir $i -a ! $islink $i ]; then
			echo "#define ${name} \"$i\""
			return
		fi
	done
	for i in $*; do
		if [ $isdir $i ]; then
			echo "#define ${name} \"$i\""
			return
		fi
	done
	echo "#define ${name} \"\""
}

checksymbol()
{
	echo "$2" >$tmp.c
	if $cc $tmp.c -o $tmp >/dev/null 2>&1; then
		echo "#define $1 1"
	else
		echo "#define $1 0"
	fi
}

echo "#ifndef _CONFIGURE_H"
echo "#define _CONFIGURE_H"
echo

finddir HOME_DIR /home /users /u /usr/people
finddir MAIL_DIR /var/mail /var/spool/mail /usr/mail /usr/spool/mail
finddir SPOOL_DIR /var/spool /usr/spool
finddir UUCP_DIR /var/spool/uucp /usr/spool/uucp

echo

findfile ALIASES_FILE /etc/aliases /etc/mail/aliases /usr/lib/aliases
findfile UTMP__FILE /var/adm/utmp /var/run/utmp /etc/utmp
findfile WTMP__FILE /var/adm/wtmp /var/log/wtmp /usr/adm/wtmp /etc/wtmp

echo

findprog GZIP_PROG /usr/bin/gzip /usr/local/bin/gzip
findprog LS_PROG /usr/bin/ls /bin/ls
findprog MAIL_PROG /usr/openwin/bin/xview/mail /usr/bin/mailx /bin/mailx /usr/sbin/Mail /usr/bin/mail /bin/mail
findprog NEWALIASES_PROG /usr/bin/newaliases /usr/ucb/newaliases /usr/bsd/newaliases
findprog RNEWS_PROG /usr/bin/rnews /usr/local/bin/rnews
findprog SENDMAIL_PROG /usr/sbin/sendmail /usr/lib/sendmail

case "`uname -sr`" in
HP-UX*)
	findprog PATCH_PROG /usr/local/bin/patch;;
*)
	findprog PATCH_PROG /usr/bin/patch /usr/local/bin/patch;;
esac

echo

checksymbol HAS_ADJTIME "main(){adjtime(0,0);}"

echo
echo "#endif"

rm -f $tmp*
