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
	install -m 0644 graylib.pl ${prefix}/lib/
	install -m 0755 graypold.pl ${prefix}/sbin/
	install -m 0755 graycron.pl ${prefix}/libexec/

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
