#!/bin/sh

if	echo '#include <resolv.h>' |
	cc -E -dM - |
	grep 'define __RES 200' >/dev/null
then
	cp Makefile.in Makefile
	echo 'Using system resolver'
elif
	echo '#include <resolv.h>' |
	cc -E -dM -I/usr/include/bind - |
	grep 'define __RES 200' >/dev/null
then
	# Debian with libbind4-dev
	sed '	s|^LIBFLAGS=.*|LIBFLAGS=-I/usr/include/bind|;
		s|^LIBS=.*|LIBS=-lbind|;
	' <Makefile.in >Makefile
	echo 'Using libbind4'
elif
	echo '#include <resolv.h>' |
	cc -E -dM - |
	grep 'define res_setservers' >/dev/null
then
	# MacOS
	sed '	s|^LIBS=.*|LIBS=-lresolv|;
	' <Makefile.in >Makefile
	echo 'Using libresolv'
else
	sed '	s|^LIBDEPS=.*|LIBDEPS=${RESLIB}|;
		s|^LIBFLAGS=.*|LIBFLAGS=-I${RES}/include -L${RES}|;
		s|^LIBS=.*|LIBS=-lbind|;
	' <Makefile.in >Makefile
	make resconfig
	echo 'Using static libbind'
fi

echo 'Now run make...'
