#!/bin/sh
#
# buildtest -- build and test with numerous option combinations
# 

# configuration
module="opendkim"
version="$1"
buildtop="`echo $1 | sed 's/-[A-Za-z0-9]*//g'`"
download="http://downloads.sourceforge.net/project/${module}/${module}-${version}.tar.gz"
buildroot=/var/tmp

# setup
buildtime="`date +%Y%m%d%H%M%S`"
buildname="${module}-${buildtime}"
builddir="${buildroot}/${buildname}"

# create directories
mkdir $builddir
cd $builddir

# download and unpack
wget -q $download
gunzip -c `basename $download` | tar xf -
cd ${module}-${buildtop}

for i in	--enable-filter \
		--with-db \
		--with-odbx \
		--with-tre \
		--with-unbound \
		--enable-allsymbols \
		--enable-bodylengthdb \
		--enable-capture_unknown_errors \
		--enable-diffheaders \
		--enable-dkim_reputation \
		--enable-dnsupgrade \
		--enable-identity_header \
		--enable-parsetime \
		--enable-redirect \
		--enable-replace_rules \
		--enable-report_intervals \
		--enable-resign	\
		--enable-select_canonicalization \
		--enable-selector_header \
		--enable-sender_macro \
		--enable-stats \
		--enable-vbr \
		--enable-ztags
do

	# configure
	./configure $CONFIG_OPTS $i > configure.out 2>&1
	if test $? != 0
	then
		echo "${buildname} ./configure error"
		tail -20 configure.out
		exit 1
	fi

	# make
	make > make.out 2>&1
	if test $? != 0
	then
		echo "${buildname} make error"
		tail -20 make.out
		exit 1
	fi

	# make check
	make check > make.out 2>&1
	if test $? != 0
	then
		echo "${buildname} make check error"
		tail -20 make.out
		exit 1
	fi

	# make clean
	rm make.out configure.out
	make clean > /dev/null 2>&1
done

cd $HOME
rm -rf $builddir
exit 0
