#!/bin/sh

# set the defaults to do the right thing for a test on nod.

USAGE="Usage: regress [ -p platform ] [ -d target_dir ] [ -f ]"
PG_NEWTREEDIR=/users/mer/pg.regress
PG_PLATFORM=sparc
FORCE=0
MASTER_SRC=/usr/local/dev/postgres/mastertree

set - `getopt fd:p: $*`
if [ $? != 0 ]
then
	echo $USAGE
	exit 1
fi

for opt in $*
do
	case $opt in
	-f) FORCE=1; shift;;
	-d) PG_NEWTREEDIR=$2; shift; shift;;
	-p) PG_PLATFORM=$2; shift; shift;;
	--) shift; break;;
	esac
done

if [ -d $PG_NEWTREEDIR -a $FORCE -eq 0 ]
then
	echo "$PG_NEWTREEDIR exists, still use it y/n (I will nuke it)?"
	read response
	if [ "$response" != "y" ]
	then
		echo Abort regression test
		exit 1
	fi
	mv $PG_NEWTREEDIR `dirname $PG_NEWTREEDIR`/delme$$
	rm -rf `dirname $PG_NEWTREEDIR`/delme$$
fi

# check out a new tree

cd $MASTER_SRC/newconf
./newtree << EOF
$PG_NEWTREEDIR
y
$PG_PLATFORM
O
EOF

# set up environment correctly

POSTGRESHOME=$PG_NEWTREEDIR
PATH="$POSTGRESHOME/bin:$PATH"
export POSTGRESHOME
export PATH

# Change the default build configuration to optimize and ignore asserts

cd $POSTGRESHOME/newconf
chmod 644 config.mk
sed -e 's/-g/-O -DNO_ASSERT_CHECKING/' < config.mk > /tmp/regress$$
mv /tmp/regress$$ ./config.mk

# Build the new tree and run all tests

./Make everything install alltests
