:

. traprm

[ "$1" = "-c" ] && CONTRIB="Y" && shift
[ "$1" = "-d" ] && DOCS="Y" && shift
[ "$1" = "-c" ] && CONTRIB="Y" && shift

export QUIET=$(($QUIET + 1))

. cd_pgtop

chown -R postgres .

echo "Checking SGML"
cd doc/src/sgml
# make postgres.sgml first so we don't filter on a configure check
make -q postgres.sgml
make check > $TMP/0 2>&1
if grep -v 'fully-tagged' < $TMP/0 | egrep -qi 'Error|Warning'
then	echo "SGML error"
	cat $TMP/0
	exit 1
fi

[ $(pwd) != '/pgsql/8.4/doc/src/sgml' ] && make check-tabs

# Run only at night to check for HISTORY build problems
# in HISTORY.html.
if [ ! -t 0 -o "$DOCS" = "Y" ]
then	make INSTALL.html > $TMP/0 2>&1
	if egrep -qi 'Error|Warning' < $TMP/0
	then	echo "SGML error"
		cat $TMP/0
		exit 1
	fi
	# removed in PG 9.4
	make HISTORY.html > $TMP/0 2>&1
	if grep -q 'Error' < $TMP/0
	then	echo "SGML error"
		cat $TMP/0
		exit 1
	fi
fi

# fails on /bin/sh
cd - > /dev/null

echo "Checking duplicate oids"
cd src/include/catalog
duplicate_oids > $TMP/0
if [ -s $TMP/0 ]
then	echo "Duplicate system oids"
	cat $TMP/0
	exit 1
fi
cd - > /dev/null

pggit diff --check || exit 1

echo "Running pgtest"
(aspg /pg/tools/pgtest --silent "$@"; echo "$?" > $TMP/ret) |
# use only one grep so we don't buffer output
egrep -v 'In file included from gram.y:|warning: unused variable .yyg.|yy_try_NUL_trans'

if [ "$CONTRIB" ]
then	cd contrib
	make --silent
	# install-check is much faster because no initdbs
	aspg make --silent check
	cd - > /dev/null
fi

rm -fr src/test/regress/tmp_check


[ -t 0 ] && bell

exit $(cat $TMP/ret)
