#!/bin/csh -f
set bison
set ethers
set flex
set gcc
set irix
set pcap
set ranlib
set solaris
if ( -e /dev/bpf0 ) then
	set pcap=bpf
else if ( -f /usr/include/net/pfilt.h ) then
	set pcap=pf
else if ( -e /dev/enet ) then
	set pcap=enet
else if ( -e /dev/nit ) then
	set pcap=snit
else if ( -f /usr/include/sys/net/nit.h ) then
	set pcap=nit
else if ( -f /usr/include/net/raw.h ) then
	set pcap=snoop
else if ( -f /usr/include/sys/dlpi.h ) then
	set pcap=dlpi
else if ( -f /usr/include/linux/if.h ) then
	set pcap=linux
else
	echo "configure: cannot determine packet capture interface"
	exit 1
endif
echo "configure: using $pcap packet capture interface"
if (-f /bin/uname || -f /usr/bin/uname) then
	set name=`uname -s | tr '[A-Z]' '[a-z]'`
	set vers=`uname -r | sed -e 's/\..*//' -e 's/T1/v1/' | tr '[A-Z]' '[a-z]'`
	if ( "$name" == "irix" ) set irix='-e s/^#have-irix#//'
	if ( "$name$vers" == "sunos5") then
		set solaris='-e s/^#have-solaris#//'
		set path=($path /usr/ccs/bin)
	endif
endif
if ( -x /usr/local/bin/flex || -x /usr/local/flex || -x /usr/bin/flex ) then
	set flex='-e s/^#have-flex#//'
	echo "configure: found flex executable"
else
	echo "configure: couldn't find flex executable; using lex"
endif
if ( -x /usr/local/bin/bison || -x /usr/local/bison || -x /usr/bin/bison ) then
	set bison='-e s/^#have-bison#//'
	echo "configure: found bison executable"
else
	echo "configure: couldn't find bison executable; using yacc"
endif
if ( ( "$flex" == "" && "$bison" != "" ) || \
     ( "$flex" != "" && "$bison" == "" ) ) then
	echo "configure: don't have both flex and yacc...reverting to lex/yacc"
	set flex
	set bison
endif
set libc
foreach f ( /usr/lib/libc.a /lib/libc.a /usr/lib/libc_s.a )
	if ( -f $f ) then
		set libc=$f
		break
	endif
end
if ( "$f" == "" ) then
	echo "configure: couldn't find libc"
else
	nm $libc | grep ether_ntoa > /dev/null
	if ( $status == 0 ) then
		set ethers='-e s/^#have-ethers#//'
		echo "configure: found support for /etc/ethers"
	endif
endif
if ( -x /usr/local/bin/gcc || -x /usr/local/gcc || -x /usr/bin/gcc ) then
	set gcc='-e s/^#have-gcc#//'
endif
if ( -x /usr/bin/ranlib ) then
	set ranlib='-e s/^#have-ranlib#//'
endif
if ( ! -f /usr/include/stdlib.h ) ln -s /dev/null stdlib.h
rm -f Makefile
sed -e "s/^#have-$pcap#//" $irix $solaris $flex $bison $ethers $gcc $ranlib \
    Makefile.in > Makefile
chmod ug+w Makefile
make depend
exit 0
