diff --git a/contrib/adminpack/Makefile b/contrib/adminpack/Makefile
index 11b5f39cd3..c7dad12de0 100644
--- a/contrib/adminpack/Makefile
+++ b/contrib/adminpack/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/adminpack/Makefile,v 1.4 2007/02/09 17:03:59 petere Exp $
+# $PostgreSQL: pgsql/contrib/adminpack/Makefile,v 1.5 2007/06/26 22:05:01 tgl Exp $
 
 MODULE_big = adminpack
 PG_CPPFLAGS = -I$(libpq_srcdir)
@@ -8,7 +8,8 @@ DOCS = README.adminpack
 OBJS = adminpack.o
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/adminpack
diff --git a/contrib/btree_gist/Makefile b/contrib/btree_gist/Makefile
index a165f4bb3d..2e734cc330 100644
--- a/contrib/btree_gist/Makefile
+++ b/contrib/btree_gist/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/btree_gist/Makefile,v 1.10 2007/02/09 17:03:59 petere Exp $
+# $PostgreSQL: pgsql/contrib/btree_gist/Makefile,v 1.11 2007/06/26 22:05:01 tgl Exp $
 
 MODULE_big  = btree_gist
 
@@ -15,7 +15,8 @@ REGRESS     = init int2 int4 int8 float4 float8 cash oid timestamp timestamptz t
               date interval macaddr inet cidr text varchar char bytea bit varbit numeric
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/btree_gist
diff --git a/contrib/chkpass/Makefile b/contrib/chkpass/Makefile
index af7f492b3a..017f413f3e 100644
--- a/contrib/chkpass/Makefile
+++ b/contrib/chkpass/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/chkpass/Makefile,v 1.8 2006/02/27 12:54:38 petere Exp $
+# $PostgreSQL: pgsql/contrib/chkpass/Makefile,v 1.9 2007/06/26 22:05:01 tgl Exp $
 
 MODULE_big = chkpass
 OBJS = chkpass.o
@@ -8,7 +8,8 @@ DATA = uninstall_chkpass.sql
 DOCS = README.chkpass
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/chkpass
diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile
index f661952858..89e46d094e 100644
--- a/contrib/cube/Makefile
+++ b/contrib/cube/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/cube/Makefile,v 1.19 2007/02/09 17:24:33 petere Exp $
+# $PostgreSQL: pgsql/contrib/cube/Makefile,v 1.20 2007/06/26 22:05:01 tgl Exp $
 
 MODULE_big = cube
 OBJS= cube.o cubeparse.o
@@ -13,7 +13,8 @@ EXTRA_CLEAN = y.tab.c y.tab.h
 SHLIB_LINK += $(filter -lm, $(LIBS))
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/cube
diff --git a/contrib/dblink/Makefile b/contrib/dblink/Makefile
index aebf403fae..66113fd92d 100644
--- a/contrib/dblink/Makefile
+++ b/contrib/dblink/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/dblink/Makefile,v 1.13 2006/09/10 22:07:02 tgl Exp $
+# $PostgreSQL: pgsql/contrib/dblink/Makefile,v 1.14 2007/06/26 22:05:01 tgl Exp $
 
 MODULE_big = dblink
 PG_CPPFLAGS = -I$(libpq_srcdir)
@@ -12,7 +12,8 @@ REGRESS = dblink
 
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/dblink
diff --git a/contrib/earthdistance/Makefile b/contrib/earthdistance/Makefile
index 787957acef..9ff3763f77 100644
--- a/contrib/earthdistance/Makefile
+++ b/contrib/earthdistance/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/earthdistance/Makefile,v 1.17 2006/02/27 12:54:38 petere Exp $
+# $PostgreSQL: pgsql/contrib/earthdistance/Makefile,v 1.18 2007/06/26 22:05:02 tgl Exp $
 
 MODULES = earthdistance
 DATA_built = earthdistance.sql
@@ -9,7 +9,8 @@ REGRESS = earthdistance
 SHLIB_LINK += $(filter -lm, $(LIBS))
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/earthdistance
diff --git a/contrib/fuzzystrmatch/Makefile b/contrib/fuzzystrmatch/Makefile
index f22e102a02..8d3835a1ad 100644
--- a/contrib/fuzzystrmatch/Makefile
+++ b/contrib/fuzzystrmatch/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/fuzzystrmatch/Makefile,v 1.8 2006/10/19 17:40:03 tgl Exp $
+# $PostgreSQL: pgsql/contrib/fuzzystrmatch/Makefile,v 1.9 2007/06/26 22:05:02 tgl Exp $
 
 MODULE_big = fuzzystrmatch
 OBJS = fuzzystrmatch.o dmetaphone.o
@@ -7,7 +7,8 @@ DATA = uninstall_fuzzystrmatch.sql
 DOCS = README.fuzzystrmatch README.soundex
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/fuzzystrmatch
diff --git a/contrib/intagg/Makefile b/contrib/intagg/Makefile
index 084d78b1d7..12fea9ffdc 100644
--- a/contrib/intagg/Makefile
+++ b/contrib/intagg/Makefile
@@ -2,7 +2,7 @@
 # Makefile for integer aggregator
 # Copyright (C) 2001 Digital Music Network.
 # by Mark L. Woodward
-# $PostgreSQL: pgsql/contrib/intagg/Makefile,v 1.7 2006/02/27 12:54:39 petere Exp $
+# $PostgreSQL: pgsql/contrib/intagg/Makefile,v 1.8 2007/06/26 22:05:02 tgl Exp $
 
 MODULES = int_aggregate
 DATA_built = int_aggregate.sql
@@ -10,7 +10,8 @@ DATA = uninstall_int_aggregate.sql
 DOCS = README.int_aggregate
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/intagg
diff --git a/contrib/intarray/Makefile b/contrib/intarray/Makefile
index 2b9a62409c..85cf4c0a34 100644
--- a/contrib/intarray/Makefile
+++ b/contrib/intarray/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/intarray/Makefile,v 1.14 2006/05/03 16:31:07 teodor Exp $
+# $PostgreSQL: pgsql/contrib/intarray/Makefile,v 1.15 2007/06/26 22:05:02 tgl Exp $
 
 MODULE_big = _int
 OBJS = _int_bool.o _int_gist.o _int_op.o _int_tool.o _intbig_gist.o _int_gin.o 
@@ -8,7 +8,8 @@ DOCS = README.intarray
 REGRESS = _int
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/intarray
diff --git a/contrib/isn/Makefile b/contrib/isn/Makefile
index bfc3a37de1..d84b499021 100644
--- a/contrib/isn/Makefile
+++ b/contrib/isn/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/isn/Makefile,v 1.1 2006/09/09 04:07:52 tgl Exp $
+# $PostgreSQL: pgsql/contrib/isn/Makefile,v 1.2 2007/06/26 22:05:02 tgl Exp $
 
 MODULES = isn
 DATA_built = isn.sql
@@ -6,7 +6,8 @@ DATA = uninstall_isn.sql
 DOCS = README.isn
 
 ifdef USE_PGXS
-PGXS = $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/isn
diff --git a/contrib/lo/Makefile b/contrib/lo/Makefile
index 0cf642a0a8..78bcf4a5dc 100644
--- a/contrib/lo/Makefile
+++ b/contrib/lo/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/lo/Makefile,v 1.15 2006/09/11 15:14:46 tgl Exp $
+# $PostgreSQL: pgsql/contrib/lo/Makefile,v 1.16 2007/06/26 22:05:02 tgl Exp $
 
 MODULES = lo
 DATA_built = lo.sql
@@ -6,7 +6,8 @@ DATA = uninstall_lo.sql
 DOCS = README.lo
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/lo
diff --git a/contrib/ltree/Makefile b/contrib/ltree/Makefile
index c9d3bde0bf..723dba4197 100644
--- a/contrib/ltree/Makefile
+++ b/contrib/ltree/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/ltree/Makefile,v 1.6 2007/02/09 17:04:00 petere Exp $
+# $PostgreSQL: pgsql/contrib/ltree/Makefile,v 1.7 2007/06/26 22:05:02 tgl Exp $
 
 PG_CPPFLAGS = -DLOWER_NODE
 MODULE_big = ltree
@@ -10,7 +10,8 @@ DOCS = README.ltree
 REGRESS = ltree
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/ltree
diff --git a/contrib/oid2name/Makefile b/contrib/oid2name/Makefile
index 3511c656af..a486a1a7ff 100644
--- a/contrib/oid2name/Makefile
+++ b/contrib/oid2name/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/oid2name/Makefile,v 1.8 2005/09/27 17:13:06 tgl Exp $
+# $PostgreSQL: pgsql/contrib/oid2name/Makefile,v 1.9 2007/06/26 22:05:02 tgl Exp $
 
 PROGRAM = oid2name
 OBJS	= oid2name.o
@@ -9,7 +9,8 @@ PG_LIBS = $(libpq_pgport)
 DOCS = README.oid2name
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/oid2name
diff --git a/contrib/pageinspect/Makefile b/contrib/pageinspect/Makefile
index 5222e89e62..8e5f8ea61a 100644
--- a/contrib/pageinspect/Makefile
+++ b/contrib/pageinspect/Makefile
@@ -2,7 +2,7 @@
 #
 # pageinspect Makefile
 #
-# $PostgreSQL: pgsql/contrib/pageinspect/Makefile,v 1.1 2007/05/17 19:11:24 momjian Exp $
+# $PostgreSQL: pgsql/contrib/pageinspect/Makefile,v 1.2 2007/06/26 22:05:02 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,7 +13,8 @@ DATA_built	= pageinspect.sql
 DATA      	= uninstall_pageinspect.sql
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pageinspect
diff --git a/contrib/pg_buffercache/Makefile b/contrib/pg_buffercache/Makefile
index 5d08beccd3..1de802cfae 100644
--- a/contrib/pg_buffercache/Makefile
+++ b/contrib/pg_buffercache/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/pg_buffercache/Makefile,v 1.3 2006/02/27 12:54:39 petere Exp $
+# $PostgreSQL: pgsql/contrib/pg_buffercache/Makefile,v 1.4 2007/06/26 22:05:02 tgl Exp $
 
 MODULE_big = pg_buffercache
 OBJS	= pg_buffercache_pages.o
@@ -8,7 +8,8 @@ DATA = uninstall_pg_buffercache.sql
 DOCS = README.pg_buffercache
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pg_buffercache
diff --git a/contrib/pg_freespacemap/Makefile b/contrib/pg_freespacemap/Makefile
index 666b6e4f1f..59d2e334b5 100644
--- a/contrib/pg_freespacemap/Makefile
+++ b/contrib/pg_freespacemap/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/pg_freespacemap/Makefile,v 1.2 2006/09/30 18:15:48 tgl Exp $
+# $PostgreSQL: pgsql/contrib/pg_freespacemap/Makefile,v 1.3 2007/06/26 22:05:02 tgl Exp $
 
 MODULE_big = pg_freespacemap
 OBJS	= pg_freespacemap.o
@@ -8,7 +8,8 @@ DATA = uninstall_pg_freespacemap.sql
 DOCS = README.pg_freespacemap
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pg_freespacemap
diff --git a/contrib/pg_standby/Makefile b/contrib/pg_standby/Makefile
index e66b1b5c11..582dccf0cd 100644
--- a/contrib/pg_standby/Makefile
+++ b/contrib/pg_standby/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/pg_standby/Makefile,v 1.2 2007/02/09 17:04:00 petere Exp $
+# $PostgreSQL: pgsql/contrib/pg_standby/Makefile,v 1.3 2007/06/26 22:05:02 tgl Exp $
 
 PROGRAM = pg_standby
 OBJS	= pg_standby.o
@@ -9,7 +9,8 @@ PG_LIBS = $(libpq_pgport)
 DOCS = README.pg_standby
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pg_standby
diff --git a/contrib/pg_standby/pg_standby.c b/contrib/pg_standby/pg_standby.c
index de3ad5ed2e..bb885384c3 100644
--- a/contrib/pg_standby/pg_standby.c
+++ b/contrib/pg_standby/pg_standby.c
@@ -19,7 +19,6 @@
  * Current maintainer: 	Simon Riggs
  */
 #include "postgres_fe.h"
-#include "pg_config_manual.h"
 
 #include <ctype.h>
 #include <dirent.h>
diff --git a/contrib/pg_trgm/Makefile b/contrib/pg_trgm/Makefile
index f7b65f873a..371702b614 100644
--- a/contrib/pg_trgm/Makefile
+++ b/contrib/pg_trgm/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/pg_trgm/Makefile,v 1.7 2007/03/14 14:15:40 teodor Exp $
+# $PostgreSQL: pgsql/contrib/pg_trgm/Makefile,v 1.8 2007/06/26 22:05:02 tgl Exp $
 
 MODULE_big = pg_trgm
 OBJS = trgm_op.o trgm_gist.o trgm_gin.o
@@ -10,7 +10,8 @@ REGRESS = pg_trgm
 
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pg_trgm
diff --git a/contrib/pgbench/Makefile b/contrib/pgbench/Makefile
index 1529986c3d..0a0be038c0 100644
--- a/contrib/pgbench/Makefile
+++ b/contrib/pgbench/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/pgbench/Makefile,v 1.14 2005/09/27 17:13:08 tgl Exp $
+# $PostgreSQL: pgsql/contrib/pgbench/Makefile,v 1.15 2007/06/26 22:05:03 tgl Exp $
 
 PROGRAM = pgbench
 OBJS	= pgbench.o
@@ -9,7 +9,8 @@ PG_LIBS = $(libpq_pgport)
 DOCS = README.pgbench README.pgbench_jis
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pgbench
diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile
index cb5e7bc4f2..44d5fe401b 100644
--- a/contrib/pgcrypto/Makefile
+++ b/contrib/pgcrypto/Makefile
@@ -1,5 +1,5 @@
 #
-# $PostgreSQL: pgsql/contrib/pgcrypto/Makefile,v 1.25 2007/01/14 20:55:14 alvherre Exp $
+# $PostgreSQL: pgsql/contrib/pgcrypto/Makefile,v 1.26 2007/06/26 22:05:03 tgl Exp $
 #
 
 INT_SRCS = md5.c sha1.c sha2.c internal.c internal-sha2.c blf.c rijndael.c \
@@ -39,7 +39,8 @@ REGRESS = init md5 sha1 hmac-md5 hmac-sha1 blowfish rijndael \
 
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pgcrypto
diff --git a/contrib/pgrowlocks/Makefile b/contrib/pgrowlocks/Makefile
index c0ae8cf7f6..92b4a4f852 100644
--- a/contrib/pgrowlocks/Makefile
+++ b/contrib/pgrowlocks/Makefile
@@ -2,7 +2,7 @@
 #
 # pgrowlocks Makefile
 #
-# $PostgreSQL: pgsql/contrib/pgrowlocks/Makefile,v 1.3 2006/10/19 17:40:03 tgl Exp $
+# $PostgreSQL: pgsql/contrib/pgrowlocks/Makefile,v 1.4 2007/06/26 22:05:03 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,7 +13,8 @@ DATA_built	= pgrowlocks.sql
 DATA		= uninstall_pgrowlocks.sql
 
 ifdef USE_PGXS
-PGXS = $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pgrowlocks
diff --git a/contrib/pgstattuple/Makefile b/contrib/pgstattuple/Makefile
index 047e64bbfd..d3197977e9 100644
--- a/contrib/pgstattuple/Makefile
+++ b/contrib/pgstattuple/Makefile
@@ -2,7 +2,7 @@
 #
 # pgstattuple Makefile
 #
-# $PostgreSQL: pgsql/contrib/pgstattuple/Makefile,v 1.7 2006/10/19 17:40:03 tgl Exp $
+# $PostgreSQL: pgsql/contrib/pgstattuple/Makefile,v 1.8 2007/06/26 22:05:03 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,7 +13,8 @@ DATA_built	= pgstattuple.sql
 DATA      	= uninstall_pgstattuple.sql
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/pgstattuple
diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile
index e0e95cf9ee..34cd37e657 100644
--- a/contrib/seg/Makefile
+++ b/contrib/seg/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/seg/Makefile,v 1.18 2007/02/09 17:24:33 petere Exp $
+# $PostgreSQL: pgsql/contrib/seg/Makefile,v 1.19 2007/06/26 22:05:03 tgl Exp $
 
 MODULE_big = seg
 OBJS = seg.o segparse.o
@@ -10,7 +10,8 @@ REGRESS = seg
 EXTRA_CLEAN = y.tab.c y.tab.h
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/seg
diff --git a/contrib/spi/Makefile b/contrib/spi/Makefile
index bc3b1fd99f..704122286e 100644
--- a/contrib/spi/Makefile
+++ b/contrib/spi/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/spi/Makefile,v 1.26 2005/09/27 17:13:10 tgl Exp $
+# $PostgreSQL: pgsql/contrib/spi/Makefile,v 1.27 2007/06/26 22:05:03 tgl Exp $
 
 MODULES = autoinc insert_username moddatetime refint timetravel
 DATA_built = $(addsuffix .sql, $(MODULES))
@@ -9,7 +9,8 @@ DOCS	= README.spi $(addsuffix .example, $(MODULES))
 PG_CPPFLAGS = -DREFINT_VERBOSE
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/spi
diff --git a/contrib/sslinfo/Makefile b/contrib/sslinfo/Makefile
index ea24b753f5..1a43951ec5 100644
--- a/contrib/sslinfo/Makefile
+++ b/contrib/sslinfo/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/sslinfo/Makefile,v 1.8 2007/02/09 17:04:00 petere Exp $
+# $PostgreSQL: pgsql/contrib/sslinfo/Makefile,v 1.9 2007/06/26 22:05:03 tgl Exp $
 
 MODULE_big = sslinfo
 OBJS = sslinfo.o
@@ -7,7 +7,8 @@ DATA = uninstall_sslinfo.sql
 DOCS = README.sslinfo
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/sslinfo
diff --git a/contrib/tablefunc/Makefile b/contrib/tablefunc/Makefile
index a75dd62787..187f51ab2a 100644
--- a/contrib/tablefunc/Makefile
+++ b/contrib/tablefunc/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/tablefunc/Makefile,v 1.7 2007/02/09 17:04:00 petere Exp $
+# $PostgreSQL: pgsql/contrib/tablefunc/Makefile,v 1.8 2007/06/26 22:05:03 tgl Exp $
 
 MODULES = tablefunc
 DATA_built = tablefunc.sql
@@ -9,7 +9,8 @@ REGRESS = tablefunc
 SHLIB_LINK += $(filter -lm, $(LIBS))
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/tablefunc
diff --git a/contrib/tsearch2/Makefile b/contrib/tsearch2/Makefile
index ee8b2dc4f1..b4dbec036f 100644
--- a/contrib/tsearch2/Makefile
+++ b/contrib/tsearch2/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/tsearch2/Makefile,v 1.18 2007/02/09 15:55:57 petere Exp $
+# $PostgreSQL: pgsql/contrib/tsearch2/Makefile,v 1.19 2007/06/26 22:05:03 tgl Exp $
 
 MODULE_big = tsearch2
 OBJS = dict_ex.o dict.o snmap.o stopword.o common.o prs_dcfg.o \
@@ -25,7 +25,8 @@ SHLIB_LINK += $(filter -lm, $(LIBS))
 
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/tsearch2
diff --git a/contrib/tsearch2/ispell/Makefile b/contrib/tsearch2/ispell/Makefile
index 341f7f41e5..4302cee743 100644
--- a/contrib/tsearch2/ispell/Makefile
+++ b/contrib/tsearch2/ispell/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/tsearch2/ispell/Makefile,v 1.9 2005/10/18 01:30:48 tgl Exp $
+# $PostgreSQL: pgsql/contrib/tsearch2/ispell/Makefile,v 1.10 2007/06/26 22:05:03 tgl Exp $
 
 SUBOBJS = spell.o regis.o 
 
@@ -7,7 +7,8 @@ EXTRA_CLEAN = SUBSYS.o $(SUBOBJS)
 PG_CPPFLAGS = -I$(srcdir)/.. 
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/tsearch2/ispell
diff --git a/contrib/tsearch2/snowball/Makefile b/contrib/tsearch2/snowball/Makefile
index aa94658f65..dd5c84d723 100644
--- a/contrib/tsearch2/snowball/Makefile
+++ b/contrib/tsearch2/snowball/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/tsearch2/snowball/Makefile,v 1.9 2006/01/27 16:32:31 teodor Exp $
+# $PostgreSQL: pgsql/contrib/tsearch2/snowball/Makefile,v 1.10 2007/06/26 22:05:03 tgl Exp $
 
 SUBOBJS = english_stem.o api.o russian_stem.o russian_stem_UTF8.o utilities.o
 
@@ -7,7 +7,8 @@ EXTRA_CLEAN = SUBSYS.o $(SUBOBJS)
 PG_CPPFLAGS = -I$(srcdir)/..
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/tsearch2/snowball
diff --git a/contrib/tsearch2/wordparser/Makefile b/contrib/tsearch2/wordparser/Makefile
index c4eceba60b..2d1e739599 100644
--- a/contrib/tsearch2/wordparser/Makefile
+++ b/contrib/tsearch2/wordparser/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/tsearch2/wordparser/Makefile,v 1.9 2005/11/21 12:27:57 teodor Exp $
+# $PostgreSQL: pgsql/contrib/tsearch2/wordparser/Makefile,v 1.10 2007/06/26 22:05:03 tgl Exp $
 
 SUBOBJS =  parser.o deflex.o
 
@@ -7,7 +7,8 @@ EXTRA_CLEAN = SUBSYS.o $(SUBOBJS)
 PG_CPPFLAGS = -I$(srcdir)/..
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/tsearch2/wordparser
diff --git a/contrib/uuid-ossp/Makefile b/contrib/uuid-ossp/Makefile
index 76727a5798..67f29ccc7d 100644
--- a/contrib/uuid-ossp/Makefile
+++ b/contrib/uuid-ossp/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/uuid-ossp/Makefile,v 1.1 2007/04/21 17:26:17 petere Exp $
+# $PostgreSQL: pgsql/contrib/uuid-ossp/Makefile,v 1.2 2007/06/26 22:05:03 tgl Exp $
 
 MODULE_big = uuid-ossp
 OBJS = uuid-ossp.o
@@ -9,7 +9,8 @@ DOCS = README.uuid-ossp
 SHLIB_LINK += -lossp-uuid
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/uuid-ossp
diff --git a/contrib/vacuumlo/Makefile b/contrib/vacuumlo/Makefile
index 349ae8bd03..4a776a53ad 100644
--- a/contrib/vacuumlo/Makefile
+++ b/contrib/vacuumlo/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/vacuumlo/Makefile,v 1.15 2005/09/27 17:13:13 tgl Exp $
+# $PostgreSQL: pgsql/contrib/vacuumlo/Makefile,v 1.16 2007/06/26 22:05:03 tgl Exp $
 
 PROGRAM = vacuumlo
 OBJS	= vacuumlo.o
@@ -9,7 +9,8 @@ PG_LIBS = $(libpq_pgport)
 DOCS = README.vacuumlo
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/vacuumlo
diff --git a/contrib/xml2/Makefile b/contrib/xml2/Makefile
index 1b724c2193..5c04fd05a8 100644
--- a/contrib/xml2/Makefile
+++ b/contrib/xml2/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/xml2/Makefile,v 1.9 2007/02/09 17:04:00 petere Exp $
+# $PostgreSQL: pgsql/contrib/xml2/Makefile,v 1.10 2007/06/26 22:05:04 tgl Exp $
 
 MODULE_big = pgxml
 
@@ -15,7 +15,8 @@ DOCS = README.xml2
 override CFLAGS += $(shell xml2-config --cflags)
 
 ifdef USE_PGXS
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 else
 subdir = contrib/xml2
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index de7eed5a6d..0b8860c0c2 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.128 2007/06/06 23:00:36 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/xfunc.sgml,v 1.129 2007/06/26 22:05:04 tgl Exp $ -->
 
  <sect1 id="xfunc">
   <title>User-Defined Functions</title>
@@ -2071,10 +2071,11 @@ MODULES = isbn_issn
 DATA_built = isbn_issn.sql
 DOCS = README.isbn_issn
 
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 </programlisting>
-    The last two lines should always be the same.  Earlier in the
+    The last three lines should always be the same.  Earlier in the
     file, you assign variables or add custom
     <application>make</application> rules.
    </para>
@@ -2215,6 +2216,18 @@ include $(PGXS)
        </para>
       </listitem>
      </varlistentry>
+
+     <varlistentry>
+      <term><varname>PG_CONFIG</varname></term>
+      <listitem>
+       <para>
+        path to <application>pg_config</> program for the
+        <productname>PostgreSQL</productname> installation to build against
+        (typically just <literal>pg_config</> to use the first one in your
+        <varname>PATH</>)
+       </para>
+      </listitem>
+     </varlistentry>
     </variablelist>
    </para>
 
@@ -2222,13 +2235,26 @@ include $(PGXS)
     Put this makefile as <literal>Makefile</literal> in the directory
     which holds your extension. Then you can do
     <literal>make</literal> to compile, and later <literal>make
-    install</literal> to install your module.  The extension is
+    install</literal> to install your module.  By default, the extension is
     compiled and installed for the
     <productname>PostgreSQL</productname> installation that
-    corresponds to the first <command>pg_config</command> command
-    found in your path.
+    corresponds to the first <command>pg_config</command> program
+    found in your path.  You can use a different installation by
+    setting <varname>PG_CONFIG</varname> to point to its
+    <command>pg_config</command> program, either within the makefile
+    or on the <literal>make</literal> command line.
    </para>
 
+   <caution>
+    <para>
+     Changing <varname>PG_CONFIG</varname> only works when building
+     against <productname>PostgreSQL</productname> 8.3 or later.
+     With older releases it does not work to set it to anything except
+     <literal>pg_config</>; you must alter your <varname>PATH</>
+     to select the installation to build against.
+    </para>
+   </caution>
+
    <para>
     The scripts listed in the <varname>REGRESS</> variable are used for
     regression testing of your module, just like <literal>make
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 604d7bbc67..032da4f579 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.236 2007/04/21 17:26:18 petere Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.237 2007/06/26 22:05:04 tgl Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -118,7 +118,10 @@ localedir := @localedir@
 
 else # PGXS case
 
+# Extension makefiles should set PG_CONFIG, but older ones might not
+ifndef PG_CONFIG
 PG_CONFIG = pg_config
+endif
 
 bindir := $(shell $(PG_CONFIG) --bindir)
 datadir := $(shell $(PG_CONFIG) --sharedir)
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 1a0fa54c6e..7b5683f621 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -1,6 +1,6 @@
 # PGXS: PostgreSQL extensions makefile
 
-# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.9 2006/07/21 00:24:04 tgl Exp $ 
+# $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.10 2007/06/26 22:05:04 tgl Exp $ 
 
 # This file contains generic rules to build many kinds of simple
 # extension modules.  You only need to set a few variables and include
@@ -11,7 +11,8 @@
 #   [variable assignments, see below]
 #   [custom rules, rarely necessary]
 #
-#   PGXS := $(shell pg_config --pgxs)
+#   PG_CONFIG = pg_config
+#   PGXS := $(shell $(PG_CONFIG) --pgxs)
 #   include $(PGXS)
 #
 # The following variables can be set:
@@ -38,6 +39,9 @@
 #   PG_CPPFLAGS -- will be added to CPPFLAGS
 #   PG_LIBS -- will be added to PROGRAM link line
 #   SHLIB_LINK -- will be added to MODULE_big link line
+#   PG_CONFIG -- path to pg_config program for the PostgreSQL installation
+#     to build against (typically just "pg_config" to use the first one in
+#     your PATH)
 #
 # Better look at some of the existing uses for examples...
 
diff --git a/src/tutorial/Makefile b/src/tutorial/Makefile
index 5ddb0ae78c..19647df692 100644
--- a/src/tutorial/Makefile
+++ b/src/tutorial/Makefile
@@ -9,7 +9,7 @@
 # to build using the surrounding source tree.
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/tutorial/Makefile,v 1.19 2005/09/27 17:13:14 tgl Exp $
+#    $PostgreSQL: pgsql/src/tutorial/Makefile,v 1.20 2007/06/26 22:05:04 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -24,7 +24,8 @@ top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 include $(top_srcdir)/src/makefiles/pgxs.mk
 else
-PGXS := $(shell pg_config --pgxs)
+PG_CONFIG = pg_config
+PGXS := $(shell $(PG_CONFIG) --pgxs)
 include $(PGXS)
 endif