diff --git a/src/interfaces/ecpg/compatlib/Makefile b/src/interfaces/ecpg/compatlib/Makefile
index 1a888a450f80b1eddfcfc1dd446ab9b3b3c68b3e..f385d8b745e1d7adbd0d46956693cafa724f5cf1 100644
--- a/src/interfaces/ecpg/compatlib/Makefile
+++ b/src/interfaces/ecpg/compatlib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.23 2005/12/09 21:19:35 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/compatlib/Makefile,v 1.24 2006/08/28 16:13:10 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,11 +17,12 @@ SO_MAJOR_VERSION= 2
 SO_MINOR_VERSION= 2
 DLTYPE= library
 
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include -I$(libpq_srcdir) \
-	-I$(top_srcdir)/src/include/utils $(CPPFLAGS)
+override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
+	-I$(libpq_srcdir) -I$(top_srcdir)/src/include/utils $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 SHLIB_LINK = -L../ecpglib -lecpg -L../pgtypeslib -lpgtypes $(libpq) \
-	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) $(PTHREAD_LIBS)
+	$(filter -lintl -lssl -lcrypto -lkrb5 -lcrypt -lm, $(LIBS)) \
+	$(PTHREAD_LIBS)
 
 OBJS= informix.o
 
diff --git a/src/interfaces/ecpg/ecpglib/Makefile b/src/interfaces/ecpg/ecpglib/Makefile
index 49c10704006aecb4c34bddeba76d58fd01ecf89a..3528133aa66aa3828f7ff55b62fb33ad1ee1053c 100644
--- a/src/interfaces/ecpg/ecpglib/Makefile
+++ b/src/interfaces/ecpg/ecpglib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.40 2006/04/29 20:13:07 tgl Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/Makefile,v 1.41 2006/08/28 16:13:11 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,7 +17,8 @@ SO_MAJOR_VERSION= 5
 SO_MINOR_VERSION= 2
 DLTYPE= library
 
-override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
+override CPPFLAGS := -DFRONTEND \
+	-I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(libpq_srcdir) -I$(top_builddir)/src/port $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
diff --git a/src/interfaces/ecpg/include/Makefile b/src/interfaces/ecpg/include/Makefile
index 4f2c472c59626620aa6e087f6c347c35c8f9e300..8cbf9b606cf003059d6fb666253106a24a3ce5de 100644
--- a/src/interfaces/ecpg/include/Makefile
+++ b/src/interfaces/ecpg/include/Makefile
@@ -2,7 +2,8 @@ subdir = src/interfaces/ecpg/include
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
+override CPPFLAGS := -DFRONTEND \
+	-I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(libpq_srcdir) -I$(top_builddir)/src/port $(CPPFLAGS)
 
 informix_esql_dir = $(pkgincludedir)/informix/esql
diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile
index ca695a0c0812ab7d7243d1c2291ab14fd32e89b5..9e79118a393616331b9d8b22c335c95ef00ffcdc 100644
--- a/src/interfaces/ecpg/pgtypeslib/Makefile
+++ b/src/interfaces/ecpg/pgtypeslib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.29 2005/12/09 21:19:36 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.30 2006/08/28 16:13:11 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,7 +17,8 @@ SO_MAJOR_VERSION= 2
 SO_MINOR_VERSION= 2
 DLTYPE= library
 
-override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
+override CPPFLAGS := -DFRONTEND \
+	-I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
 	-I$(top_srcdir)/src/include/utils -I$(libpq_srcdir) $(CPPFLAGS)
 override CFLAGS += $(PTHREAD_CFLAGS)
 
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index 752579c464414166103fca826dee0e2c3c9466ca..b1bcd5522899527d23e38c4379483a5fe91bdd91 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1998-2006, PostgreSQL Global Development Group
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.120 2006/03/07 00:48:07 tgl Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.121 2006/08/28 16:13:11 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,9 +17,10 @@ MAJOR_VERSION= 4
 MINOR_VERSION= 2
 PATCHLEVEL=1
 
-override CPPFLAGS := -I$(srcdir)/../include -I$(srcdir) $(CPPFLAGS) \
-	-DMAJOR_VERSION=$(MAJOR_VERSION) \
-	-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL)
+override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
+	-I$(srcdir) -DMAJOR_VERSION=$(MAJOR_VERSION) \
+	-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
+	 $(CPPFLAGS)
 
 ifeq ($(GCC), yes)
 override CFLAGS += -Wno-error
diff --git a/src/interfaces/ecpg/test/Makefile b/src/interfaces/ecpg/test/Makefile
index 3bc224252931b0758c155ac1e6d3636669b5c84e..553c0d697d9a1d4a09a5a0cd7159e43c5a3a44be 100644
--- a/src/interfaces/ecpg/test/Makefile
+++ b/src/interfaces/ecpg/test/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.58 2006/08/19 13:42:40 meskes Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/test/Makefile,v 1.59 2006/08/28 16:13:11 tgl Exp $
 
 subdir = src/interfaces/ecpg/test
 top_builddir = ../../../..
@@ -17,6 +17,12 @@ ifdef NO_LOCALE
 NOLOCALE += --no-locale
 endif
 
+ifneq ($(PORTNAME),win32)
+abs_builddir := $(shell pwd)
+else
+abs_builddir := $(shell pwd -W)
+endif
+
 all install installdirs uninstall dep depend distprep:
 	$(MAKE) -C connect $@
 	$(MAKE) -C sql $@
@@ -36,13 +42,11 @@ clean distclean maintainer-clean:
 	$(MAKE) -C complex $@
 	$(MAKE) -C thread $@
 	rm -rf tmp_check results log
-	rm -f pg_regress.inc.sh regression.diffs
+	rm -f pg_regress regression.diffs
 
-all: pg_regress.sh
+all: pg_regress
 
-pg_regress.sh: pg_regress.inc.sh
-
-pg_regress.inc.sh: pg_regress.inc.sh.in $(top_builddir)/src/Makefile.global
+pg_regress: pg_regress.sh $(top_builddir)/src/Makefile.global
 	sed -e 's,@bindir@,$(bindir),g' \
 	    -e 's,@libdir@,$(libdir),g' \
 	    -e 's,@pkglibdir@,$(pkglibdir),g' \
@@ -54,12 +58,29 @@ pg_regress.inc.sh: pg_regress.inc.sh.in $(top_builddir)/src/Makefile.global
 	    -e 's/@GCC@/$(GCC)/g' \
 	  $< >$@
 
-check: all pg_regress.inc.sh
-	sh ./pg_regress.sh  --dbname=regress1 --debug --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE)
+# When doing a VPATH build, copy over the .pgc, .stdout and .stderr
+# files so that the driver script can find them.  We have to use an
+# absolute path for the targets, because otherwise make will try to
+# locate the missing files using VPATH, and will find them in
+# $(srcdir), but the point here is that we want to copy them from
+# $(srcdir) to the build directory.
+
+ifdef VPATH
+remaining_files_src := $(wildcard $(srcdir)/*/*.pgc) $(wildcard $(srcdir)/expected/*.c) $(wildcard $(srcdir)/expected/*.stdout) $(wildcard $(srcdir)/expected/*.stderr)
+remaining_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(remaining_files_src))
+
+all: $(remaining_files_build)
+$(remaining_files_build): $(abs_builddir)/%: $(srcdir)/%
+	ln -s $< $@
+endif
+
+
+check: all
+	sh ./pg_regress  --dbname=regress1 --debug --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE)
 
 # the same options, but with --listen-on-tcp
-checktcp: all pg_regress.inc.sh
-	sh ./pg_regress.sh  --dbname=regress1 --debug --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE) --listen-on-tcp
+checktcp: all
+	sh ./pg_regress  --dbname=regress1 --debug --temp-install --top-builddir=$(top_builddir) --temp-port=$(TEMP_PORT) --multibyte=$(MULTIBYTE) --load-language=plpgsql $(NOLOCALE) --listen-on-tcp
 
-installcheck: all pg_regress.inc.sh
-	sh ./pg_regress.sh  --dbname=regress1 --debug --top-builddir=$(top_builddir) --load-language=plpgsql $(NOLOCALE)
+installcheck: all
+	sh ./pg_regress  --dbname=regress1 --debug --top-builddir=$(top_builddir) --load-language=plpgsql $(NOLOCALE)
diff --git a/src/interfaces/ecpg/test/Makefile.regress b/src/interfaces/ecpg/test/Makefile.regress
index c79393b7e099c1f17b3500103d4ff88bcc81d6e1..31f767a1c499073106f5432857d575fc6b1be35d 100644
--- a/src/interfaces/ecpg/test/Makefile.regress
+++ b/src/interfaces/ecpg/test/Makefile.regress
@@ -1,4 +1,5 @@
-override CPPFLAGS := -I$(srcdir)/../../include -I$(libpq_srcdir) $(CPPFLAGS) 
+override CPPFLAGS := -I../../include -I$(top_srcdir)/src/interfaces/ecpg/include \
+	-I$(libpq_srcdir) $(CPPFLAGS) 
 override CFLAGS += $(PTHREAD_CFLAGS) 
 
 override LDFLAGS := -L../../ecpglib -L../../pgtypeslib -L../../../libpq $(LDFLAGS)
diff --git a/src/interfaces/ecpg/test/pg_regress.inc.sh.in b/src/interfaces/ecpg/test/pg_regress.inc.sh.in
deleted file mode 100644
index c0e03716482392f391f27e7e76e0038a9ab1aa8e..0000000000000000000000000000000000000000
--- a/src/interfaces/ecpg/test/pg_regress.inc.sh.in
+++ /dev/null
@@ -1,613 +0,0 @@
-message(){
-    _dashes='==============' # 14
-    _spaces='                                      ' # 38
-    _msg=`echo "$1$_spaces" | cut -c 1-38`
-    echo "$_dashes $_msg $_dashes"
-}
-
-build_help(){
-help="\
-PostgreSQL regression test driver
-
-Usage: $me [options...] [extra tests...]
-
-Options:
-  --dbname=DB               use database DB (default \`regression')
-  --debug                   turn on debug mode in programs that are run
-  --inputdir=DIR            take input files from DIR (default \`.')
-  --load-language=lang      load the named language before running the
-                            tests; can appear multiple times
-  --max-connections=N       maximum number of concurrent connections
-                            (default is 0 meaning unlimited)
-  --multibyte=ENCODING      use ENCODING as the multibyte encoding, and
-                            also run a test by the same name
-  --outputdir=DIR           place output files in DIR (default \`.')
-  --temp-install[=DIR]      create a temporary installation (in DIR)
-  --no-locale               use C locale
-$1
-Options for \`temp-install' mode:
-  --top-builddir=DIR        (relative) path to top level build directory
-  --temp-port=PORT          port number to start temp postmaster on
-  --listen-on-tcp           listen on the tcp port as well
-
-Options for using an existing installation:
-  --host=HOST               use postmaster running on HOST
-  --port=PORT               use postmaster running at PORT
-  --user=USER               connect as USER
-
-The exit status is 0 if all tests passed, 1 if some tests failed, and 2
-if the tests could not be run for some reason.
-
-Report bugs to <pgsql-bugs@postgresql.org>."
-}
-
-init_vars(){
-	: ${TMPDIR=/tmp}
-	TMPFILE=$TMPDIR/pg_regress.$$
-
-	# ----------
-	# Initialize default settings
-	# ----------
-
-	: ${inputdir=.}
-	: ${outputdir=.}
-
-	libdir='@libdir@'
-	bindir='@bindir@'
-	datadir='@datadir@'
-	host_platform='@host_tuple@'
-	enable_shared='@enable_shared@'
-	GCC=@GCC@
-	VERSION=@VERSION@
-
-	if [ "$GCC" = yes ]; then
-	    compiler=gcc
-	else
-	    compiler=cc
-	fi
-
-	unset mode
-	unset schedule
-	unset debug
-	unset nolocale
-	unset top_builddir
-	unset temp_install
-	unset multibyte
-
-	dbname=regression
-	hostname=localhost
-	maxconnections=0
-	temp_port=65432
-	load_langs=""
-	listen_on_tcp=no
-
-	: ${GMAKE='@GMAKE@'}
-}
-
-parse_general_options(){
-# ----------
-# Parse command line options
-# ----------
-
-while [ "$#" -gt 0 ]
-do
-    case $1 in
-        --help|-\?)
-                echo "$help"
-                exit 0;;
-        --version)
-                echo "pg_regress (PostgreSQL $VERSION)"
-                exit 0;;
-        --dbname=*)
-                dbname=`expr "x$1" : "x--dbname=\(.*\)"`
-                shift;;
-        --debug)
-                debug=yes
-                shift;;
-        --inputdir=*)
-                inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
-                shift;;
-        --listen-on-tcp)
-                listen_on_tcp=yes
-                shift;;
-        --load-language=*)
-                lang=`expr "x$1" : "x--load-language=\(.*\)"`
-                load_langs="$load_langs $lang"
-                unset lang
-                shift;;
-        --multibyte=*)
-                multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
-                shift;;
-        --no-locale)
-                nolocale=yes
-                shift;;
-        --temp-install)
-                temp_install=./tmp_check
-                shift;;
-        --temp-install=*)
-                temp_install=`expr "x$1" : "x--temp-install=\(.*\)"`
-                shift;;
-        --max-connections=*)
-                maxconnections=`expr "x$1" : "x--max-connections=\(.*\)"`
-                shift;;
-        --outputdir=*)
-                outputdir=`expr "x$1" : "x--outputdir=\(.*\)"`
-                shift;;
-        --top-builddir=*)
-                top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
-                shift;;
-        --temp-port=*)
-                temp_port=`expr "x$1" : "x--temp-port=\(.*\)"`
-                shift;;
-        --host=*)
-                PGHOST=`expr "x$1" : "x--host=\(.*\)"`
-                export PGHOST
-                unset PGHOSTADDR
-                shift;;
-        --port=*)
-                PGPORT=`expr "x$1" : "x--port=\(.*\)"`
-                export PGPORT
-                shift;;
-        --user=*)
-                PGUSER=`expr "x$1" : "x--user=\(.*\)"`
-                export PGUSER
-                shift;;
-        -*)
-                # on error, this will not return but exit
-                parse_special_options "$1"
-                shift;;
-        *)
-                extra_tests="$extra_tests $1"
-                shift;;
-    esac
-done
-}
-
-
-
-setup_environment_variables(){
-
-	# This function has two parts. Part 1 sets/unsets environment variables
-	# independently of what options the script receives.
-	# Part 2 later sets environment variables with respect to the
-	# options given.
-
-	# =======
-	# PART 1: Options independent stuff goes here
-	# =======
-
-
-	# ----------
-	# Unset locale settings
-	# ----------
-
-	unset LC_COLLATE LC_CTYPE LC_MONETARY LC_MESSAGES LC_NUMERIC LC_TIME LC_ALL LANG LANGUAGE
-
-	# On Windows the default locale may not be English, so force it
-	case $host_platform in
-	    *-*-cygwin*|*-*-mingw32*)
-		LANG=en
-		export LANG
-		;;
-	esac
-
-	# ----------
-	# On some platforms we can't use Unix sockets.
-	# ----------
-
-	case $host_platform in
-	    *-*-cygwin* | *-*-mingw32*)
-		listen_on_tcp=yes
-	esac
-
-	# ----------
-	# Set up diff to ignore horizontal white space differences.
-	# ----------
-
-	case $host_platform in
-	    *-*-sco3.2v5*)
-		DIFFFLAGS=-b;;
-	    *)
-		DIFFFLAGS=-w;;
-	esac
-
-	# ----------
-	# Check for echo -n vs echo \c
-	# ----------
-
-	if echo '\c' | grep c >/dev/null 2>&1; then
-	    ECHO_N='echo -n'
-	    ECHO_C=''
-	else
-	    ECHO_N='echo'
-	    ECHO_C='\c'
-	fi
-
-	# ----------
-	# Set backend timezone and datestyle explicitly
-	#
-	# To pass the horology test in its current form, the postmaster must be
-	# started with PGDATESTYLE=ISO, while the frontend must be started with
-	# PGDATESTYLE=Postgres.  We set the postmaster values here and change
-	# to the frontend settings after the postmaster has been started.
-	# ----------
-
-	PGTZ='PST8PDT'; export PGTZ
-	PGDATESTYLE='ISO, MDY'; export PGDATESTYLE
-
-	# ----------
-	# Set up SQL shell for the test.
-	# ----------
-
-	psql_test_options="-a -q -X $psql_options"
-
-
-
-	# =======
-	# PART 2: Options dependent stuff goes here
-	# =======
-
-	LOGDIR=$outputdir/log
-
-	# ----------
-	# warn of Cygwin likely failure if maxconnections = 0
-	# and we are running parallel tests
-	# ----------
-
-	case $host_platform in
-	    *-*-cygwin*)
-		case "$schedule" in
-		    *parallel_schedule*)
-			if [ $maxconnections -eq 0 ] ; then
-			    echo Using unlimited parallel connections is likely to fail or hang on Cygwin.
-			    echo Try \"$me --max-connections=n\" or \"gmake MAX_CONNECTIONS=n check\"
-			    echo with n = 5 or 10 if this happens.
-			    echo
-			fi
-			;;
-		esac
-		;;
-	esac
-
-	# ----------
-	# Set up multibyte environment
-	# ----------
-
-	if [ -n "$multibyte" ]; then
-	    PGCLIENTENCODING=$multibyte
-	    export PGCLIENTENCODING
-	    encoding_opt="-E $multibyte"
-	else
-	    unset PGCLIENTENCODING
-	fi
-}
-
-do_temp_install(){
-    if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
-        temp_install="`pwd`/$temp_install"
-    fi
-
-    bindir=$temp_install/install/$bindir
-    libdir=$temp_install/install/$libdir
-    datadir=$temp_install/install/$datadir
-    PGDATA=$temp_install/data
-
-    if [ "$unix_sockets" = no ]; then
-        PGHOST=$hostname
-        export PGHOST
-        unset PGHOSTADDR
-    else
-        unset PGHOST
-        unset PGHOSTADDR
-    fi
-
-    # since Makefile isn't very bright, check for out-of-range temp_port
-    if [ "$temp_port" -ge 1024 -a "$temp_port" -le 65535 ] ; then
-	PGPORT=$temp_port
-    else
-	PGPORT=65432
-    fi
-    export PGPORT
-
-    # Get rid of environment stuff that might cause psql to misbehave
-    # while contacting our temp installation
-    unset PGDATABASE PGUSER PGSERVICE PGSSLMODE PGREQUIRESSL PGCONNECT_TIMEOUT
-
-    # ----------
-    # Set up shared library paths, needed by psql and pg_encoding
-    # (if you run multibyte).  LD_LIBRARY_PATH covers many platforms.
-    # DYLD_LIBRARY_PATH works on Darwin, and maybe other Mach-based systems.
-    # Feel free to account for others as well.
-    # ----------
-
-    if [ -n "$LD_LIBRARY_PATH" ]; then
-        LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
-    else
-        LD_LIBRARY_PATH=$libdir
-    fi
-    export LD_LIBRARY_PATH
-
-    if [ -n "$DYLD_LIBRARY_PATH" ]; then
-        DYLD_LIBRARY_PATH="$libdir:$DYLD_LIBRARY_PATH"
-    else
-        DYLD_LIBRARY_PATH=$libdir
-    fi
-    export DYLD_LIBRARY_PATH
-
-    # ----------
-    # Windows needs shared libraries in PATH. (Only those linked into
-    # executables, not dlopen'ed ones)
-    # ----------
-    case $host_platform in
-        *-*-cygwin*|*-*-mingw32*)
-            PATH=$libdir:$PATH
-            export PATH
-            ;;
-    esac
-
-    if [ -d "$temp_install" ]; then
-        message "removing existing temp installation"
-        rm -rf "$temp_install"
-    fi
-
-    message "creating temporary installation"
-    if [ ! -d "$LOGDIR" ]; then
-        mkdir -p "$LOGDIR" || { (exit 2); exit; }
-    fi
-    $GMAKE -C "$top_builddir" DESTDIR="$temp_install/install" install with_perl=no with_python=no >"$LOGDIR/install.log" 2>&1
-
-    if [ $? -ne 0 ]
-    then
-        echo
-        echo "$me: installation failed"
-        echo "Examine $LOGDIR/install.log for the reason."
-        echo
-        (exit 2); exit
-    fi
-
-    message "initializing database system"
-    [ "$debug" = yes ] && initdb_options="--debug"
-    [ "$nolocale" = yes ] && initdb_options="$initdb_options --no-locale"
-    "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
-
-    if [ $? -ne 0 ]
-    then
-        echo
-        echo "$me: initdb failed"
-        echo "Examine $LOGDIR/initdb.log for the reason."
-        echo
-        (exit 2); exit
-    fi
-
-
-    # ----------
-    # Start postmaster
-    # ----------
-
-    message "starting postmaster"
-    [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
-    if [ "$listen_on_tcp" = yes ]; then
-        postmaster_options="$postmaster_options -c listen_addresses=$hostname"
-    else
-        postmaster_options="$postmaster_options -c listen_addresses="
-    fi
-    "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
-    postmaster_pid=$!
-
-    # Wait till postmaster is able to accept connections (normally only
-    # a second or so, but Cygwin is reportedly *much* slower).  Don't
-    # wait forever, however.
-    i=0
-    max=60
-    until "$bindir/psql" -X $psql_options postgres </dev/null 2>/dev/null
-    do
-        i=`expr $i + 1`
-        if [ $i -ge $max ]
-        then
-            break
-        fi
-        if kill -0 $postmaster_pid >/dev/null 2>&1
-        then
-            : still starting up
-        else
-            break
-        fi
-        sleep 1
-    done
-
-    if kill -0 $postmaster_pid >/dev/null 2>&1
-    then
-        echo "running on port $PGPORT with pid $postmaster_pid"
-    else
-        echo
-        echo "$me: postmaster did not start"
-        echo "Examine $LOGDIR/postmaster.log for the reason."
-        echo
-        (exit 2); exit
-    fi
-}
-
-dont_temp_install(){
-    # ----------
-    # Windows needs shared libraries in PATH. (Only those linked into
-    # executables, not dlopen'ed ones)
-    # ----------
-    case $host_platform in
-        *-*-cygwin*|*-*-mingw32*)
-            PATH=$libdir:$PATH
-            export PATH
-            ;;
-    esac
-
-    if [ -n "$PGPORT" ]; then
-        port_info="port $PGPORT"
-    else
-        port_info="default port"
-    fi
-
-    if [ -n "$PGHOST" ]; then
-        echo "(using postmaster on $PGHOST, $port_info)"
-    else
-        if [ "$unix_sockets" = no ]; then
-            echo "(using postmaster on localhost, $port_info)"
-        else
-            echo "(using postmaster on Unix socket, $port_info)"
-        fi
-    fi
-}
-
-setup_client_environment_variables(){
-	PGDATESTYLE='Postgres'
-	export PGDATESTYLE
-}
-
-# ----------
-# Exit trap to remove temp file and shut down postmaster
-# ----------
-
-# Note:  There are some stupid shells (even among recent ones) that
-# ignore the argument to exit (as in `exit 1') if there is an exit
-# trap.  The trap (and thus the shell script) will then always exit
-# with the result of the last shell command before the `exit'.  Hence
-# we have to write `(exit x); exit' below this point.
-
-exit_trap(){ 
-    savestatus=$1
-    if [ -n "$postmaster_pid" ]; then
-        kill -2 "$postmaster_pid"
-        wait "$postmaster_pid"
-        unset postmaster_pid
-    fi
-    rm -f "$TMPFILE" && exit $savestatus
-}
-
-sig_trap() {
-    savestatus=$1
-    echo; echo "caught signal"
-    if [ -n "$postmaster_pid" ]; then
-        echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
-        kill -2 "$postmaster_pid"
-        wait "$postmaster_pid"
-        unset postmaster_pid
-    fi
-    (exit $savestatus); exit
-}
-
-setup_database(){
-	# this receives the name of the database to set up as its argument
-	"$bindir/psql" -q -X $psql_options -c "\
-	alter database \"$1\" set lc_messages to 'C';
-	alter database \"$1\" set lc_monetary to 'C';
-	alter database \"$1\" set lc_numeric to 'C';
-	alter database \"$1\" set lc_time to 'C';" "$1"
-	if [ $? -ne 0 ]; then
-	    echo "$me: could not set database default locales"
-	    (exit 2); exit
-	fi
-
-	# ----------
-	# Install any requested PL languages
-	# ----------
-
-	if [ "$enable_shared" = yes ]; then
-	    for lang in xyzzy $load_langs ; do    
-		if [ "$lang" != "xyzzy" ]; then
-		    message "installing $lang"
-		    "$bindir/createlang" $psql_options $lang "$1"
-		    if [ $? -ne 0 ] && [ $? -ne 2 ]; then
-			echo "$me: createlang $lang failed"
-			(exit 2); exit
-		    fi
-		fi
-	    done
-	fi
-}
-
-drop_database(){
-	message "dropping database \"$1\""
-	"$bindir/dropdb" $psql_options "$1"
-}
-
-create_database(){
-	# ----------
-	# We use template0 so that any installation-local cruft in template1
-	# will not mess up the tests.
-	# ----------
-
-	message "creating database \"$1\""
-	"$bindir/createdb" $encoding_opt $psql_options --template template0 "$1"
-	if [ $? -ne 0 ]; then
-	    echo "$me: createdb failed"
-	    (exit 2); exit
-	fi
-
-	setup_database "$1"
-}
-
-database_cleanup(){
-	# ----------
-	# Remove regressuser* and regressgroup* user accounts.
-	# ----------
-
-	message "dropping regression test user accounts"
-	"$bindir/psql" -q -X $psql_options -c 'DROP GROUP regressgroup1; DROP GROUP regressgroup2; DROP USER regressuser1, regressuser2, regressuser3, regressuser4;' $dbname 2>/dev/null
-	if [ $? -eq 2 ]; then
-	    echo "$me: could not drop user accounts"
-	    (exit 2); exit
-	fi
-}
-
-postmaster_shutdown(){
-	# ----------
-	# Server shutdown
-	# ----------
-
-	if [ -n "$postmaster_pid" ]; then
-	    message "shutting down postmaster"
-	    "$bindir/pg_ctl" -s -D "$PGDATA" stop
-	    wait "$postmaster_pid"
-	    unset postmaster_pid
-	fi
-}
-
-evaluate(){
-	# ----------
-	# Evaluation
-	# ----------
-
-	count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`
-	count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`
-	count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`
-	count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`
-
-	echo
-	if [ $count_total -eq $count_ok ]; then
-	    msg="All $count_total tests passed."
-	    result=0
-	elif [ $count_failed -eq 0 ]; then
-	    msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored."
-	    result=0
-	elif [ $count_ignored -eq 0 ]; then
-	    msg="$count_failed of $count_total tests failed."
-	    result=1
-	else
-	    msg="`expr $count_failed + $count_ignored` of $count_total tests failed, $count_ignored of these failures ignored."
-	    result=1
-	fi
-
-	dashes=`echo " $msg " | sed 's/./=/g'`
-	echo "$dashes"
-	echo " $msg "
-	echo "$dashes"
-	echo
-
-	if [ -s "$diff_file" ]; then
-	    echo "The differences that caused some tests to fail can be viewed in the"
-	    echo "file \`$diff_file'.  A copy of the test summary that you see"
-	    echo "above is saved in the file \`$result_summary_file'."
-	    echo
-	else
-	    rm -f "$diff_file" "$result_summary_file"
-	fi
-}
-
diff --git a/src/interfaces/ecpg/test/pg_regress.sh b/src/interfaces/ecpg/test/pg_regress.sh
index bf5160c065ba05627646a11b474ea772482fef28..35a42158cde866a6346ab3c4352d6a92220b7138 100644
--- a/src/interfaces/ecpg/test/pg_regress.sh
+++ b/src/interfaces/ecpg/test/pg_regress.sh
@@ -1,9 +1,620 @@
 #! /bin/sh
-# $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress.sh,v 1.6 2006/08/19 13:42:40 meskes Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/test/pg_regress.sh,v 1.7 2006/08/28 16:13:11 tgl Exp $
 
 me=`basename $0`
 
-. ./pg_regress.inc.sh
+message(){
+    _dashes='==============' # 14
+    _spaces='                                      ' # 38
+    _msg=`echo "$1$_spaces" | cut -c 1-38`
+    echo "$_dashes $_msg $_dashes"
+}
+
+build_help(){
+help="\
+PostgreSQL regression test driver
+
+Usage: $me [options...] [extra tests...]
+
+Options:
+  --dbname=DB               use database DB (default \`regression')
+  --debug                   turn on debug mode in programs that are run
+  --inputdir=DIR            take input files from DIR (default \`.')
+  --load-language=lang      load the named language before running the
+                            tests; can appear multiple times
+  --max-connections=N       maximum number of concurrent connections
+                            (default is 0 meaning unlimited)
+  --multibyte=ENCODING      use ENCODING as the multibyte encoding, and
+                            also run a test by the same name
+  --outputdir=DIR           place output files in DIR (default \`.')
+  --temp-install[=DIR]      create a temporary installation (in DIR)
+  --no-locale               use C locale
+$1
+Options for \`temp-install' mode:
+  --top-builddir=DIR        (relative) path to top level build directory
+  --temp-port=PORT          port number to start temp postmaster on
+  --listen-on-tcp           listen on the tcp port as well
+
+Options for using an existing installation:
+  --host=HOST               use postmaster running on HOST
+  --port=PORT               use postmaster running at PORT
+  --user=USER               connect as USER
+
+The exit status is 0 if all tests passed, 1 if some tests failed, and 2
+if the tests could not be run for some reason.
+
+Report bugs to <pgsql-bugs@postgresql.org>."
+}
+
+init_vars(){
+	: ${TMPDIR=/tmp}
+	TMPFILE=$TMPDIR/pg_regress.$$
+
+	# ----------
+	# Initialize default settings
+	# ----------
+
+	: ${inputdir=.}
+	: ${outputdir=.}
+
+	libdir='@libdir@'
+	bindir='@bindir@'
+	datadir='@datadir@'
+	host_platform='@host_tuple@'
+	enable_shared='@enable_shared@'
+	GCC=@GCC@
+	VERSION=@VERSION@
+
+	if [ "$GCC" = yes ]; then
+	    compiler=gcc
+	else
+	    compiler=cc
+	fi
+
+	unset mode
+	unset schedule
+	unset debug
+	unset nolocale
+	unset top_builddir
+	unset temp_install
+	unset multibyte
+
+	dbname=regression
+	hostname=localhost
+	maxconnections=0
+	temp_port=65432
+	load_langs=""
+	listen_on_tcp=no
+
+	: ${GMAKE='@GMAKE@'}
+}
+
+parse_general_options(){
+# ----------
+# Parse command line options
+# ----------
+
+while [ "$#" -gt 0 ]
+do
+    case $1 in
+        --help|-\?)
+                echo "$help"
+                exit 0;;
+        --version)
+                echo "pg_regress (PostgreSQL $VERSION)"
+                exit 0;;
+        --dbname=*)
+                dbname=`expr "x$1" : "x--dbname=\(.*\)"`
+                shift;;
+        --debug)
+                debug=yes
+                shift;;
+        --inputdir=*)
+                inputdir=`expr "x$1" : "x--inputdir=\(.*\)"`
+                shift;;
+        --listen-on-tcp)
+                listen_on_tcp=yes
+                shift;;
+        --load-language=*)
+                lang=`expr "x$1" : "x--load-language=\(.*\)"`
+                load_langs="$load_langs $lang"
+                unset lang
+                shift;;
+        --multibyte=*)
+                multibyte=`expr "x$1" : "x--multibyte=\(.*\)"`
+                shift;;
+        --no-locale)
+                nolocale=yes
+                shift;;
+        --temp-install)
+                temp_install=./tmp_check
+                shift;;
+        --temp-install=*)
+                temp_install=`expr "x$1" : "x--temp-install=\(.*\)"`
+                shift;;
+        --max-connections=*)
+                maxconnections=`expr "x$1" : "x--max-connections=\(.*\)"`
+                shift;;
+        --outputdir=*)
+                outputdir=`expr "x$1" : "x--outputdir=\(.*\)"`
+                shift;;
+        --top-builddir=*)
+                top_builddir=`expr "x$1" : "x--top-builddir=\(.*\)"`
+                shift;;
+        --temp-port=*)
+                temp_port=`expr "x$1" : "x--temp-port=\(.*\)"`
+                shift;;
+        --host=*)
+                PGHOST=`expr "x$1" : "x--host=\(.*\)"`
+                export PGHOST
+                unset PGHOSTADDR
+                shift;;
+        --port=*)
+                PGPORT=`expr "x$1" : "x--port=\(.*\)"`
+                export PGPORT
+                shift;;
+        --user=*)
+                PGUSER=`expr "x$1" : "x--user=\(.*\)"`
+                export PGUSER
+                shift;;
+        -*)
+                # on error, this will not return but exit
+                parse_special_options "$1"
+                shift;;
+        *)
+                extra_tests="$extra_tests $1"
+                shift;;
+    esac
+done
+}
+
+
+
+setup_environment_variables(){
+
+	# This function has two parts. Part 1 sets/unsets environment variables
+	# independently of what options the script receives.
+	# Part 2 later sets environment variables with respect to the
+	# options given.
+
+	# =======
+	# PART 1: Options independent stuff goes here
+	# =======
+
+
+	# ----------
+	# Unset locale settings
+	# ----------
+
+	unset LC_COLLATE LC_CTYPE LC_MONETARY LC_MESSAGES LC_NUMERIC LC_TIME LC_ALL LANG LANGUAGE
+
+	# On Windows the default locale may not be English, so force it
+	case $host_platform in
+	    *-*-cygwin*|*-*-mingw32*)
+		LANG=en
+		export LANG
+		;;
+	esac
+
+	# ----------
+	# On some platforms we can't use Unix sockets.
+	# ----------
+
+	case $host_platform in
+	    *-*-cygwin* | *-*-mingw32*)
+		listen_on_tcp=yes
+	esac
+
+	# ----------
+	# Set up diff to ignore horizontal white space differences.
+	# ----------
+
+	case $host_platform in
+	    *-*-sco3.2v5*)
+		DIFFFLAGS=-b;;
+	    *)
+		DIFFFLAGS=-w;;
+	esac
+
+	# ----------
+	# Check for echo -n vs echo \c
+	# ----------
+
+	if echo '\c' | grep c >/dev/null 2>&1; then
+	    ECHO_N='echo -n'
+	    ECHO_C=''
+	else
+	    ECHO_N='echo'
+	    ECHO_C='\c'
+	fi
+
+	# ----------
+	# Set backend timezone and datestyle explicitly
+	#
+	# To pass the horology test in its current form, the postmaster must be
+	# started with PGDATESTYLE=ISO, while the frontend must be started with
+	# PGDATESTYLE=Postgres.  We set the postmaster values here and change
+	# to the frontend settings after the postmaster has been started.
+	# ----------
+
+	PGTZ='PST8PDT'; export PGTZ
+	PGDATESTYLE='ISO, MDY'; export PGDATESTYLE
+
+	# ----------
+	# Set up SQL shell for the test.
+	# ----------
+
+	psql_test_options="-a -q -X $psql_options"
+
+
+
+	# =======
+	# PART 2: Options dependent stuff goes here
+	# =======
+
+	LOGDIR=$outputdir/log
+
+	# ----------
+	# warn of Cygwin likely failure if maxconnections = 0
+	# and we are running parallel tests
+	# ----------
+
+	case $host_platform in
+	    *-*-cygwin*)
+		case "$schedule" in
+		    *parallel_schedule*)
+			if [ $maxconnections -eq 0 ] ; then
+			    echo Using unlimited parallel connections is likely to fail or hang on Cygwin.
+			    echo Try \"$me --max-connections=n\" or \"gmake MAX_CONNECTIONS=n check\"
+			    echo with n = 5 or 10 if this happens.
+			    echo
+			fi
+			;;
+		esac
+		;;
+	esac
+
+	# ----------
+	# Set up multibyte environment
+	# ----------
+
+	if [ -n "$multibyte" ]; then
+	    PGCLIENTENCODING=$multibyte
+	    export PGCLIENTENCODING
+	    encoding_opt="-E $multibyte"
+	else
+	    unset PGCLIENTENCODING
+	fi
+}
+
+do_temp_install(){
+    if echo x"$temp_install" | grep -v '^x/' >/dev/null 2>&1; then
+        temp_install="`pwd`/$temp_install"
+    fi
+
+    bindir=$temp_install/install/$bindir
+    libdir=$temp_install/install/$libdir
+    datadir=$temp_install/install/$datadir
+    PGDATA=$temp_install/data
+
+    if [ "$unix_sockets" = no ]; then
+        PGHOST=$hostname
+        export PGHOST
+        unset PGHOSTADDR
+    else
+        unset PGHOST
+        unset PGHOSTADDR
+    fi
+
+    # since Makefile isn't very bright, check for out-of-range temp_port
+    if [ "$temp_port" -ge 1024 -a "$temp_port" -le 65535 ] ; then
+	PGPORT=$temp_port
+    else
+	PGPORT=65432
+    fi
+    export PGPORT
+
+    # Get rid of environment stuff that might cause psql to misbehave
+    # while contacting our temp installation
+    unset PGDATABASE PGUSER PGSERVICE PGSSLMODE PGREQUIRESSL PGCONNECT_TIMEOUT
+
+    # ----------
+    # Set up shared library paths, needed by psql and pg_encoding
+    # (if you run multibyte).  LD_LIBRARY_PATH covers many platforms.
+    # DYLD_LIBRARY_PATH works on Darwin, and maybe other Mach-based systems.
+    # Feel free to account for others as well.
+    # ----------
+
+    if [ -n "$LD_LIBRARY_PATH" ]; then
+        LD_LIBRARY_PATH="$libdir:$LD_LIBRARY_PATH"
+    else
+        LD_LIBRARY_PATH=$libdir
+    fi
+    export LD_LIBRARY_PATH
+
+    if [ -n "$DYLD_LIBRARY_PATH" ]; then
+        DYLD_LIBRARY_PATH="$libdir:$DYLD_LIBRARY_PATH"
+    else
+        DYLD_LIBRARY_PATH=$libdir
+    fi
+    export DYLD_LIBRARY_PATH
+
+    # ----------
+    # Windows needs shared libraries in PATH. (Only those linked into
+    # executables, not dlopen'ed ones)
+    # ----------
+    case $host_platform in
+        *-*-cygwin*|*-*-mingw32*)
+            PATH=$libdir:$PATH
+            export PATH
+            ;;
+    esac
+
+    if [ -d "$temp_install" ]; then
+        message "removing existing temp installation"
+        rm -rf "$temp_install"
+    fi
+
+    message "creating temporary installation"
+    if [ ! -d "$LOGDIR" ]; then
+        mkdir -p "$LOGDIR" || { (exit 2); exit; }
+    fi
+    $GMAKE -C "$top_builddir" DESTDIR="$temp_install/install" install with_perl=no with_python=no >"$LOGDIR/install.log" 2>&1
+
+    if [ $? -ne 0 ]
+    then
+        echo
+        echo "$me: installation failed"
+        echo "Examine $LOGDIR/install.log for the reason."
+        echo
+        (exit 2); exit
+    fi
+
+    message "initializing database system"
+    [ "$debug" = yes ] && initdb_options="--debug"
+    [ "$nolocale" = yes ] && initdb_options="$initdb_options --no-locale"
+    "$bindir/initdb" -D "$PGDATA" -L "$datadir" --noclean $initdb_options >"$LOGDIR/initdb.log" 2>&1
+
+    if [ $? -ne 0 ]
+    then
+        echo
+        echo "$me: initdb failed"
+        echo "Examine $LOGDIR/initdb.log for the reason."
+        echo
+        (exit 2); exit
+    fi
+
+
+    # ----------
+    # Start postmaster
+    # ----------
+
+    message "starting postmaster"
+    [ "$debug" = yes ] && postmaster_options="$postmaster_options -d 5"
+    if [ "$listen_on_tcp" = yes ]; then
+        postmaster_options="$postmaster_options -c listen_addresses=$hostname"
+    else
+        postmaster_options="$postmaster_options -c listen_addresses="
+    fi
+    "$bindir/postmaster" -D "$PGDATA" -F $postmaster_options >"$LOGDIR/postmaster.log" 2>&1 &
+    postmaster_pid=$!
+
+    # Wait till postmaster is able to accept connections (normally only
+    # a second or so, but Cygwin is reportedly *much* slower).  Don't
+    # wait forever, however.
+    i=0
+    max=60
+    until "$bindir/psql" -X $psql_options postgres </dev/null 2>/dev/null
+    do
+        i=`expr $i + 1`
+        if [ $i -ge $max ]
+        then
+            break
+        fi
+        if kill -0 $postmaster_pid >/dev/null 2>&1
+        then
+            : still starting up
+        else
+            break
+        fi
+        sleep 1
+    done
+
+    if kill -0 $postmaster_pid >/dev/null 2>&1
+    then
+        echo "running on port $PGPORT with pid $postmaster_pid"
+    else
+        echo
+        echo "$me: postmaster did not start"
+        echo "Examine $LOGDIR/postmaster.log for the reason."
+        echo
+        (exit 2); exit
+    fi
+}
+
+dont_temp_install(){
+    # ----------
+    # Windows needs shared libraries in PATH. (Only those linked into
+    # executables, not dlopen'ed ones)
+    # ----------
+    case $host_platform in
+        *-*-cygwin*|*-*-mingw32*)
+            PATH=$libdir:$PATH
+            export PATH
+            ;;
+    esac
+
+    if [ -n "$PGPORT" ]; then
+        port_info="port $PGPORT"
+    else
+        port_info="default port"
+    fi
+
+    if [ -n "$PGHOST" ]; then
+        echo "(using postmaster on $PGHOST, $port_info)"
+    else
+        if [ "$unix_sockets" = no ]; then
+            echo "(using postmaster on localhost, $port_info)"
+        else
+            echo "(using postmaster on Unix socket, $port_info)"
+        fi
+    fi
+}
+
+setup_client_environment_variables(){
+	PGDATESTYLE='Postgres'
+	export PGDATESTYLE
+}
+
+# ----------
+# Exit trap to remove temp file and shut down postmaster
+# ----------
+
+# Note:  There are some stupid shells (even among recent ones) that
+# ignore the argument to exit (as in `exit 1') if there is an exit
+# trap.  The trap (and thus the shell script) will then always exit
+# with the result of the last shell command before the `exit'.  Hence
+# we have to write `(exit x); exit' below this point.
+
+exit_trap(){ 
+    savestatus=$1
+    if [ -n "$postmaster_pid" ]; then
+        kill -2 "$postmaster_pid"
+        wait "$postmaster_pid"
+        unset postmaster_pid
+    fi
+    rm -f "$TMPFILE" && exit $savestatus
+}
+
+sig_trap() {
+    savestatus=$1
+    echo; echo "caught signal"
+    if [ -n "$postmaster_pid" ]; then
+        echo "signalling fast shutdown to postmaster with pid $postmaster_pid"
+        kill -2 "$postmaster_pid"
+        wait "$postmaster_pid"
+        unset postmaster_pid
+    fi
+    (exit $savestatus); exit
+}
+
+setup_database(){
+	# this receives the name of the database to set up as its argument
+	"$bindir/psql" -q -X $psql_options -c "\
+	alter database \"$1\" set lc_messages to 'C';
+	alter database \"$1\" set lc_monetary to 'C';
+	alter database \"$1\" set lc_numeric to 'C';
+	alter database \"$1\" set lc_time to 'C';" "$1"
+	if [ $? -ne 0 ]; then
+	    echo "$me: could not set database default locales"
+	    (exit 2); exit
+	fi
+
+	# ----------
+	# Install any requested PL languages
+	# ----------
+
+	if [ "$enable_shared" = yes ]; then
+	    for lang in xyzzy $load_langs ; do    
+		if [ "$lang" != "xyzzy" ]; then
+		    message "installing $lang"
+		    "$bindir/createlang" $psql_options $lang "$1"
+		    if [ $? -ne 0 ] && [ $? -ne 2 ]; then
+			echo "$me: createlang $lang failed"
+			(exit 2); exit
+		    fi
+		fi
+	    done
+	fi
+}
+
+drop_database(){
+	message "dropping database \"$1\""
+	"$bindir/dropdb" $psql_options "$1"
+}
+
+create_database(){
+	# ----------
+	# We use template0 so that any installation-local cruft in template1
+	# will not mess up the tests.
+	# ----------
+
+	message "creating database \"$1\""
+	"$bindir/createdb" $encoding_opt $psql_options --template template0 "$1"
+	if [ $? -ne 0 ]; then
+	    echo "$me: createdb failed"
+	    (exit 2); exit
+	fi
+
+	setup_database "$1"
+}
+
+database_cleanup(){
+	# ----------
+	# Remove regressuser* and regressgroup* user accounts.
+	# ----------
+
+	message "dropping regression test user accounts"
+	"$bindir/psql" -q -X $psql_options -c 'DROP GROUP regressgroup1; DROP GROUP regressgroup2; DROP USER regressuser1, regressuser2, regressuser3, regressuser4;' $dbname 2>/dev/null
+	if [ $? -eq 2 ]; then
+	    echo "$me: could not drop user accounts"
+	    (exit 2); exit
+	fi
+}
+
+postmaster_shutdown(){
+	# ----------
+	# Server shutdown
+	# ----------
+
+	if [ -n "$postmaster_pid" ]; then
+	    message "shutting down postmaster"
+	    "$bindir/pg_ctl" -s -D "$PGDATA" stop
+	    wait "$postmaster_pid"
+	    unset postmaster_pid
+	fi
+}
+
+evaluate(){
+	# ----------
+	# Evaluation
+	# ----------
+
+	count_total=`cat "$result_summary_file" | grep '\.\.\.' | wc -l | sed 's/ //g'`
+	count_ok=`cat "$result_summary_file" | grep '\.\.\. ok' | wc -l | sed 's/ //g'`
+	count_failed=`cat "$result_summary_file" | grep '\.\.\. FAILED' | wc -l | sed 's/ //g'`
+	count_ignored=`cat "$result_summary_file" | grep '\.\.\. failed (ignored)' | wc -l | sed 's/ //g'`
+
+	echo
+	if [ $count_total -eq $count_ok ]; then
+	    msg="All $count_total tests passed."
+	    result=0
+	elif [ $count_failed -eq 0 ]; then
+	    msg="$count_ok of $count_total tests passed, $count_ignored failed test(s) ignored."
+	    result=0
+	elif [ $count_ignored -eq 0 ]; then
+	    msg="$count_failed of $count_total tests failed."
+	    result=1
+	else
+	    msg="`expr $count_failed + $count_ignored` of $count_total tests failed, $count_ignored of these failures ignored."
+	    result=1
+	fi
+
+	dashes=`echo " $msg " | sed 's/./=/g'`
+	echo "$dashes"
+	echo " $msg "
+	echo "$dashes"
+	echo
+
+	if [ -s "$diff_file" ]; then
+	    echo "The differences that caused some tests to fail can be viewed in the"
+	    echo "file \`$diff_file'.  A copy of the test summary that you see"
+	    echo "above is saved in the file \`$result_summary_file'."
+	    echo
+	else
+	    rm -f "$diff_file" "$result_summary_file"
+	fi
+}
 
 additional_regress_options=""