prefix?=/usr/local
osname!=uname
osrel!=uname -r | awk -F. '{print $$1}'

all:	; @echo "Please type 'make install' and then 'make test' to check if all required Perl modules are installed."

install:	install.${osname} ${prefix}/lib ${prefix}/sbin ${prefix}/libexec
	-rm -v ${prefix}/lib/graylib.pl
	install -m 0644 graylib.pm ${prefix}/lib/
	install -m 0755 graypold.pl ${prefix}/sbin/
	install -m 0755 graycron.pl ${prefix}/libexec/
	@echo ""
	@echo "!!!!"
	@echo "Please note if you have upgraded from graypold below version 11:"
	@echo "The default graylisting unix socket was renamed from"
	@echo "/var/run/graypold_graypol.sock to /var/run/graypold_graylist.sock"
	@echo "Please verify that check_policy_service within"
	@echo "smtpd_recipient_restrictions in your main.cf querys the correct unix socket."
	@echo "!!!!"

install.FreeBSD:	/usr/local/etc/rc.d
	if [ ${osrel} -le 6 ]; then \
		install -m 0755 graypold.freebsd /usr/local/etc/rc.d/graypold.sh; \
	else \
		install -m 0755 graypold.freebsd /usr/local/etc/rc.d/graypold; \
	fi

install.Linux:	/etc/init.d
	install -m 0755 graypold.linux /etc/init.d/graypold

${prefix}/lib ${prefix}/sbin ${prefix}/libexec /usr/local/etc/rc.d /etc/init.d:
	install -m 0755 -d $@

test:	; perl -MMail::SPF -MRRDs -MDBI -e 'Mail::SPF::Server->new() || die'

.PHONY:	all install install.${osname} test
