diff --git a/contrib/adminpack/Makefile b/contrib/adminpack/Makefile
index 11b5f39cd36ceaec1189dbe7689b11323f63d743..c7dad12de0164021c4ef5539d375e070c42659f6 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 a165f4bb3d9f47ed38ac6f20c2d24ac4317db87b..2e734cc330d7c2beceedd14ce41b81f7a1849bd2 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 af7f492b3acb9d38bd807c04cfd228bc411d573a..017f413f3ea32b57af6552decd9243728d7b0920 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 f661952858ce4fe3a1839714e7fb7fc733056b80..89e46d094e68362e087c3cc15134741a84006e91 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 aebf403fae4413ba8a566e98514b388ab3ffbe64..66113fd92df9d2d7927df07760c34545aee7fdbd 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 787957acef5b6486d53c66237555bb73458704b9..9ff3763f77c8867349119f669bb709092411099d 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 f22e102a02a5235e65f74011270e60e25068555a..8d3835a1ad2474ece5b67049b7c5e74c1f9fe100 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 084d78b1d72a382d14f42b84438ee43dfee55920..12fea9ffdcfe23af0212eeca155fa3b879f99e5c 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 2b9a62409cd8f4760a15739aa47d4b2d79287852..85cf4c0a344fa1c04968816180f7283b9131530d 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 bfc3a37de12e0a43323802feaf3fea12db000b0e..d84b49902185fdf5603c4caf3112938f7e70e3dd 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 0cf642a0a8cb6d10d2609c7e5fa05c90734117f2..78bcf4a5dc30c934dfcf412a55a18378b5c61b06 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 c9d3bde0bf20960b37e2450fcd7e5b0925c9b5c9..723dba419714ef3e3a744623e69fc155ade5f269 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 3511c656af67e941f080c5eb4e04a851a8a801e7..a486a1a7ff14ca537cb75b216564f34b3d238044 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 5222e89e6258e2a1355771aa3716730c3f34432e..8e5f8ea61a4cc6d589091c0ef5e9b5865a21d093 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 5d08beccd3ada319e758146360d678a3c90699b3..1de802cfae34b5ed2b889652c4a96d95562919f0 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 666b6e4f1ff367a31fabf3cb787f1c2e34686911..59d2e334b5116d72fcc561a69f7a4bad19a62659 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 e66b1b5c118e9f0822d3434e3a6c00fc89fba75c..582dccf0cd1c66bbb7e84eb5be2ee30933ddc26b 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 de3ad5ed2e43dcde3fcb894c3b8d9361b4c276ad..bb885384c3e0ae370066e983a3aca0635fac8103 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 f7b65f873a32912eddaf00d708a27a4de484a28f..371702b614cab6734943d61fd9d95fa74f9ebbf7 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 1529986c3d5fbd368cbf97c66f19d66e716dd581..0a0be038c09c385cc86751ae778d460e326d6094 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 cb5e7bc4f28a571c5e5481b7fd20a80966f1a892..44d5fe401bf938fb08f6c5fd30a53bd0a6f3ab63 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 c0ae8cf7f6be990b21f94b0590ecb325595ed46e..92b4a4f852b5f93ec86bf53786ae2184141e2895 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 047e64bbfd003a11c47a1f6ad64103c5a528ccdf..d3197977e90aa9e8c90589782af618a69804fc2e 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 e0e95cf9ee8a3ae076fc283fa351009cf5311a22..34cd37e6579c8b099aae6a0f31543d3bcfe134fa 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 bc3b1fd99ff321fd97bc274dcbd2ccc29428aa24..704122286e40c5fab6c9b8a30ac7ce96c2a4d954 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 ea24b753f54a1ab26ef3609f01ae92886bbc6653..1a43951ec520daa3758f4b7a21440fbe0953556a 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 a75dd6278711e3195d4a010f19f43bf6c9388788..187f51ab2a2889c33ecae5e2eef3da9b4aafb279 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 ee8b2dc4f14ab240abb2a8d463fe68252744768b..b4dbec036fbbf5d364abf7bb90d0b1b2f9dc54eb 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 341f7f41e5d4a8864f4066a2dda195cfc99071ae..4302cee743448f970c5d30105fddd2dd681993a0 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 aa94658f6578b11f7ce4c3e0fa1326c8d6a653cb..dd5c84d72384e3f319de4a16bdd4aefb462c1cd8 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 c4eceba60bb22b2e515908786b8b2c43a7608fe3..2d1e7395996cf915c4ce6d415f1a4a44bf5295d1 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 76727a5798505617091ff3e059dd4499245c821b..67f29ccc7d168c0f2e9d4c255c61d3c7b1898340 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 349ae8bd0332a7b63b9544123f590728d54d07ca..4a776a53ad6cc99dad2f6e2aae6681d3d9370d08 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 1b724c2193adf168c4cfee233de3aab97d3bf433..5c04fd05a8a36bcba2a25600077c1c01649f7bf6 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 de7eed5a6db7cf1e8f1483245de1c7ea793f32e0..0b8860c0c2982cc8780a2c63264c3f31163f2f1e 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 604d7bbc67faf4a8a856c223ae361eb9bd5b3d38..032da4f5791b711707b68747c22f0a68d1fc6f07 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 1a0fa54c6ef35905fe04b1d50358d8a47abf7908..7b5683f6211400ac323f01c1f8eaf7b23467f239 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 5ddb0ae78c60cdf2cbb8a3636ab9b935f7d4cc32..19647df6929f5342a0e63b41203e0befd2b7355a 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