#!/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 -rf libpcap
		ln -s $libpcapdir libpcap
		echo "configure: using libpcap.a installed in $libpcapdir"
	endif
endif
if ( -x /bin/uname || -x /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]'`
	if ( "$name$vers" == "sunos5") then
		set path=($path /usr/ccs/bin)
	endif
else if ( -x /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/386" || $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 IP[0-9]*:
		set md=mips
		breaksw

	default:
		goto bail
		breaksw
endsw
rm -f stdlib.h os.h Makefile
set brokenmake
set gcc
set gcc1
set libresolv
set sendmail
if ( -x /usr/local/bin/gcc || -x /usr/local/gcc ) then
	set libresolv='-e s/^#have-libresolv#//'
endif
if ( -x /usr/local/bin/gcc || -x /usr/local/gcc ) then
	set gcc='-e s/^#have-gcc#//'
	set ver=`gcc -v |& sed -n -e '$s/.* //' -e '$s/\..*//p'`
	if ( "$ver" == 1 ) set gcc1='-e s/^#have-gcc1#//'
endif
if ( -x /usr/sbin/sendmail ) set \
    sendmail='-e s,^#sendmail-path#,SENDMAIL=-DSENDMAIL="/usr/sbin/sendmail",'
if ("$name$vers" == "ultrix4" || "$name$vers" == "sunos3") then
	set brokenmake='-e s/^#have-broken-make#//'
endif
if ( ! -f /usr/include/stdlib.h ) ln -s /dev/null stdlib.h
ln -s lbl/os-$os.h os.h
if (! -f addresses.h) then
	cp addresses.h.in addresses.h
	chmod +w addresses.h
endif
sed -e "s/^#have-$md-$os#//" -e "s/^#have-$name$vers#//" \
    $gcc $gcc1 $libresolv $sendmail Makefile.in > Makefile
set mflags=""
if ( "$gcc" != "" ) set mflags="CC=gcc"
chmod ug+w Makefile
make depend $mflags
exit 0
bail:
echo 'configure: unsupported system'
exit 1
