#!/bin/csh -f
if ( ! -d libpcap || ! -r libpcap/libpcap.a ) then
	set libpcapdir
	set dir=`ls .. | egrep '^libpcap-[0-9]*\.[0-9ab]*$'`
	if ( $#dir > 1 ) set dir="$dir[$#dir]"
	foreach d ( /usr/lib /usr/local/lib ../libpcap ../$dir )
		if ( -d $d && -r $d/libpcap.a ) then
			set libpcapdir=$d
			break
		endif
	end
	if ( "$libpcapdir" == "" ) then
		echo "configure: can't find libpcap.a"
		echo "configure: (see the README for more info)"
		exit 1
	endif
	if ( "$libpcapdir" != "/usr/lib" && \
	    "$libpcapdir" != "/usr/local/lib" ) then
		rm -f libpcap
		ln -s $libpcapdir libpcap
		echo "configure: using libpcap.a installed in $libpcapdir"
	endif
endif
if ( -f /bin/uname || -f /usr/bin/uname ) then
	set md=`uname -m`
	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]'`
else if ( -f /bin/arch ) then
	# sun3 only supported machine without uname
	if ( `/bin/arch` != sun3 ) goto bail
	set md=sun3
	set name=sunos
	set vers=3
else
	goto bail
endif
if ( $name == "bsd/os" ) then
	set os=bsd
else
	set os=$name$vers
endif
switch ( $md )
	case alpha:
	case i386:
		breaksw

	case sun3:
		set md=sun3
		breaksw

	case sparc:
	case sun4*:
		set md=sun4
		breaksw

	case RISC:
		set md=mips
		breaksw

	case IP7:
	case IP20:
		set md=mips
		breaksw

	default:
		goto bail
		breaksw
endsw
rm -f Makefile md.h os.h
set bpf
set cslip
set dnet
set ethers
set gcc
set solaris
if ( -e /dev/bpf0 ) set bpf='-e s/^#have-bpf#//'
if ( -f /usr/include/net/slip.h ) set cslip='-e s/^#have-cslip#//'
if ( -f /usr/lib/libdnet.a ) set dnet='-e s/^#have-dnet#//'
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 ) then
	set gcc='-e s/^#have-gcc#//'
endif
if ( "$name$vers" == "sunos5") set solaris='-e s/^#have-solaris#//'
if ( ! -f /usr/include/stdlib.h ) ln -s /dev/null stdlib.h
ln -s md-$md.h md.h
ln -s os-$os.h os.h
sed -e "s/^#$md-$os#//" $bpf $cslip $ethers $dnet $gcc $solaris \
    Makefile.in > Makefile
chmod ug+w Makefile
make depend
exit 0
bail:
echo 'configure: unsupported system'
exit 1
