diff --git a/contrib/cube/Makefile b/contrib/cube/Makefile
index 7f91b14c64d8020d0626185e68d975c27e200e50..2f3da437e52d6133e49407e1682294b400842153 100644
--- a/contrib/cube/Makefile
+++ b/contrib/cube/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/cube/Makefile,v 1.22 2008/08/29 13:02:32 petere Exp $
+# $PostgreSQL: pgsql/contrib/cube/Makefile,v 1.23 2009/08/28 20:26:18 petere Exp $
 
 MODULE_big = cube
 OBJS= cube.o cubeparse.o
@@ -24,23 +24,23 @@ endif
 
 
 # cubescan is compiled as part of cubeparse
-cubeparse.o: $(srcdir)/cubescan.c
+cubeparse.o: cubescan.c
 
-$(srcdir)/cubeparse.c: cubeparse.y
+cubeparse.c: cubeparse.y
 ifdef BISON
 	$(BISON) $(BISONFLAGS) -o $@ $<
 else
 	@$(missing) bison $< $@
 endif
 
-$(srcdir)/cubescan.c: cubescan.l
+cubescan.c: cubescan.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
 	@$(missing) flex $< $@
 endif
 
-distprep: $(srcdir)/cubeparse.c $(srcdir)/cubescan.c
+distprep: cubeparse.c cubescan.c
 
 maintainer-clean:
-	rm -f $(srcdir)/cubeparse.c $(srcdir)/cubescan.c
+	rm -f cubeparse.c cubescan.c
diff --git a/contrib/seg/Makefile b/contrib/seg/Makefile
index 31012da3441d21332c8fd2d55a56b749a6a047b6..c6a5ef4efee8749e454eb847cd21ade3faa0f15d 100644
--- a/contrib/seg/Makefile
+++ b/contrib/seg/Makefile
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/contrib/seg/Makefile,v 1.21 2008/08/29 13:02:32 petere Exp $
+# $PostgreSQL: pgsql/contrib/seg/Makefile,v 1.22 2009/08/28 20:26:18 petere Exp $
 
 MODULE_big = seg
 OBJS = seg.o segparse.o
@@ -21,23 +21,23 @@ endif
 
 
 # segscan is compiled as part of segparse
-segparse.o: $(srcdir)/segscan.c
+segparse.o: segscan.c
 
-$(srcdir)/segparse.c: segparse.y
+segparse.c: segparse.y
 ifdef BISON
 	$(BISON) $(BISONFLAGS) -o $@ $<
 else
 	@$(missing) bison $< $@
 endif
 
-$(srcdir)/segscan.c: segscan.l
+segscan.c: segscan.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
 	@$(missing) flex $< $@
 endif
 
-distprep: $(srcdir)/segparse.c $(srcdir)/segscan.c
+distprep: segparse.c segscan.c
 
 maintainer-clean:
-	rm -f $(srcdir)/segparse.c $(srcdir)/segscan.c
+	rm -f segparse.c segscan.c
diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile
index 64cc837f04e2cc6c4831614e7e0e9ca0a05e6205..c1e30be877db5c67fae87bcb1bc42b62c0e7b07c 100644
--- a/doc/src/sgml/Makefile
+++ b/doc/src/sgml/Makefile
@@ -2,7 +2,7 @@
 #
 # PostgreSQL documentation makefile
 #
-# $PostgreSQL: pgsql/doc/src/sgml/Makefile,v 1.128 2009/08/26 22:24:42 petere Exp $
+# $PostgreSQL: pgsql/doc/src/sgml/Makefile,v 1.129 2009/08/28 20:26:18 petere Exp $
 #
 #----------------------------------------------------------------------------
 
@@ -32,7 +32,7 @@ endif
 ifndef JADE
 JADE = jade
 endif
-SGMLINCLUDE = -D $(srcdir)
+SGMLINCLUDE = -D . -D $(srcdir)
 
 ifndef NSGMLS
 NSGMLS = nsgmls
@@ -75,13 +75,9 @@ override SPFLAGS += -wall -wno-unused-param -wno-empty -wfully-tagged
 
 man: man-stamp
 
-ifeq ($(vpath_build),yes)
-XSLTPROC_MAN_FLAGS = --stringparam man.output.base.dir '$(srcdir)/'
-endif
-
-$(srcdir)/man-stamp: stylesheet-man.xsl postgres.xml
+man-stamp: stylesheet-man.xsl postgres.xml
 	$(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_MAN_FLAGS) $^
-	rm $(srcdir)/man1/dblink*
+	rm man1/dblink*
 	touch $@
 
 
@@ -92,30 +88,26 @@ $(srcdir)/man-stamp: stylesheet-man.xsl postgres.xml
 .PHONY: draft
 
 JADE.html.call = $(JADE) $(JADEFLAGS) $(SPFLAGS) $(SGMLINCLUDE) $(CATALOG) -d stylesheet.dsl -t sgml -i output-html
-ifeq ($(vpath_build),yes)
-# This only works with openjade, not with the older jade.
-JADE.html.call += -V '(define %output-dir% "$(srcdir)/html")'
-endif
 
 # The draft target creates HTML output in draft mode, without index (for faster build).
 draft: postgres.sgml $(ALMOSTALLSGML) stylesheet.dsl
-	$(MKDIR_P) $(srcdir)/html
+	$(MKDIR_P) html
 	$(JADE.html.call) -V draft-mode $<
-	cp $(srcdir)/stylesheet.css $(srcdir)/html/
+	cp $(srcdir)/stylesheet.css html/
 
 html: html-stamp
 
-$(srcdir)/html-stamp: postgres.sgml $(ALLSGML) stylesheet.dsl
-	$(MKDIR_P) $(srcdir)/html
+html-stamp: postgres.sgml $(ALLSGML) stylesheet.dsl
+	$(MKDIR_P) html
 	$(JADE.html.call) -i include-index $<
-	cp $(srcdir)/stylesheet.css $(srcdir)/html/
+	cp $(srcdir)/stylesheet.css html/
 	touch $@
 
-$(srcdir)/HTML.index: postgres.sgml $(ALMOSTALLSGML) stylesheet.dsl
-	@$(MKDIR_P) $(srcdir)/html
+HTML.index: postgres.sgml $(ALMOSTALLSGML) stylesheet.dsl
+	@$(MKDIR_P) html
 	$(JADE.html.call) -V html-index $<
 
-$(srcdir)/bookindex.sgml: HTML.index
+bookindex.sgml: HTML.index
 	LC_ALL=C $(PERL) $(COLLATEINDEX) -f -g -i 'bookindex' -o $@ $<
 
 # Technically, this should depend on Makefile.global, but then
@@ -123,16 +115,16 @@ $(srcdir)/bookindex.sgml: HTML.index
 # even in distribution tarballs.  So this is cheating a bit, but it
 # will achieve the goal of updating the version number when it
 # changes.
-$(srcdir)/version.sgml: $(top_srcdir)/configure
+version.sgml: $(top_srcdir)/configure
 	{ \
 	  echo "<!entity version \"$(VERSION)\">"; \
 	  echo "<!entity majorversion \"$(MAJORVERSION)\">"; \
 	} >$@
 
-$(srcdir)/features-supported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
+features-supported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
 	$(PERL) $(srcdir)/mk_feature_tables.pl YES $^ > $@
 
-$(srcdir)/features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
+features-unsupported.sgml: $(top_srcdir)/src/backend/catalog/sql_feature_packages.txt $(top_srcdir)/src/backend/catalog/sql_features.txt
 	$(PERL) $(srcdir)/mk_feature_tables.pl NO $^ > $@
 
 
@@ -232,10 +224,6 @@ postgres.xml: postgres.sgml $(ALMOSTALLSGML)
 	  >$@
 # ' hello Emacs
 
-ifeq ($(vpath_build),yes)
-XSLTPROC_HTML_FLAGS = --stringparam base.dir '$(srcdir)/html'
-endif
-
 xslthtml: stylesheet.xsl postgres.xml
 	$(XSLTPROC) $(XSLTPROCFLAGS) $(XSLTPROC_HTML_FLAGS) $^
 
@@ -280,9 +268,11 @@ check: postgres.sgml $(ALMOSTALLSGML)
 ## Install
 ##
 
-found_html = $(wildcard $(srcdir)/html-stamp)
+vpathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,. $(VPATH)))))
+
+found_html = $(wildcard html-stamp $(srcdir)/html-stamp)
 
-ifneq ($(wildcard $(srcdir)/man-stamp),)
+ifneq ($(wildcard man-stamp $(srcdir)/man-stamp),)
 # SCO OpenServer's man system is sufficiently different to not bother.
 ifneq ($(PORTNAME), sco)
 found_man = yes
@@ -301,7 +291,7 @@ uninstall:
 ## Install html
 
 install-html: html installdirs
-	cp -R $(srcdir)/html '$(DESTDIR)$(htmldir)'
+	cp -R $(call vpathsearch,html) '$(DESTDIR)$(htmldir)'
 
 
 ## Install man
@@ -316,7 +306,7 @@ sqlmansectnum = $(shell expr X'$(sqlmansect)' : X'\([0-9]\)')
 #
 ifeq ($(sqlmansectnum),7)
 install-man:
-	cp -R $(addprefix $(srcdir)/,man1 man3 man7) '$(DESTDIR)$(mandir)'
+	cp -R $(foreach dir,man1 man3 man7,$(call vpathsearch,$(dir))) '$(DESTDIR)$(mandir)'
 
 else # sqlmansectnum != 7
 fix_sqlmansectnum = sed -e '/^\.TH/s/"7"/"$(sqlmansect)"/' \
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index e8d63292dc2838a6fa5930ce7ed9c36fa5c958f1..add201d0078e4e283355ecc94f0606a88e083813 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -6,7 +6,7 @@
 # Copyright (c) 1998, Regents of the University of California
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.122 2009/08/27 17:55:53 tgl Exp $
+#    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.123 2009/08/28 20:26:18 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -415,7 +415,7 @@ exports_file = $(DLL_DEFFILE)
 $(exports_file): $(OBJS)
 	$(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $@ $^
 else
-DLL_DEFFILE = $(srcdir)/lib$(NAME)dll.def
+DLL_DEFFILE = lib$(NAME)dll.def
 endif
 
 $(shlib): $(OBJS) $(DLL_DEFFILE)
@@ -436,23 +436,23 @@ endif # enable_shared
 # tarballs.
 
 ifneq (,$(SHLIB_EXPORTS))
-distprep: $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
+distprep: lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
 
 UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
 
-$(srcdir)/lib$(NAME)dll.def: $(SHLIB_EXPORTS)
+lib$(NAME)dll.def: $(SHLIB_EXPORTS)
 	echo '; DEF file for MS VC++' >$@
 	echo 'LIBRARY LIB$(UC_NAME)' >>$@
 	echo 'EXPORTS' >>$@
 	sed -e '/^#/d' -e 's/^\(.*[ 	]\)\([0-9][0-9]*\)/    \1@ \2/' $< >>$@
 
-$(srcdir)/lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
+lib$(NAME)ddll.def: $(SHLIB_EXPORTS)
 	echo '; DEF file for MS VC++' >$@
 	echo 'LIBRARY LIB$(UC_NAME)D' >>$@
 	echo 'EXPORTS' >>$@
 	sed -e '/^#/d' -e 's/^\(.*[ 	]\)\([0-9][0-9]*\)/    \1@ \2/' $< >>$@
 
-$(srcdir)/blib$(NAME)dll.def: $(SHLIB_EXPORTS)
+blib$(NAME)dll.def: $(SHLIB_EXPORTS)
 	echo '; DEF file for Borland C++ Builder' >$@
 	echo 'LIBRARY BLIB$(UC_NAME)' >>$@
 	echo 'EXPORTS' >>$@
@@ -551,5 +551,5 @@ clean-lib:
 
 ifneq (,$(SHLIB_EXPORTS))
 maintainer-clean-lib:
-	rm -f $(srcdir)/lib$(NAME)dll.def $(srcdir)/lib$(NAME)ddll.def $(srcdir)/blib$(NAME)dll.def
+	rm -f lib$(NAME)dll.def lib$(NAME)ddll.def blib$(NAME)dll.def
 endif
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 5ee3c4193dc9ce72d2e9acee4c8b5e7615861732..1621530e95e83e41a71d945f378ce36006a54b04 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/backend/Makefile,v 1.133 2009/08/26 22:24:43 petere Exp $
+# $PostgreSQL: pgsql/src/backend/Makefile,v 1.134 2009/08/28 20:26:18 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -118,7 +118,7 @@ postgres.o: $(OBJS)
 # the make files in our subdirectories. Note that it's important we
 # match the dependencies shown in the subdirectory makefiles!
 
-$(srcdir)/parser/gram.h: parser/gram.y
+parser/gram.h: parser/gram.y
 	$(MAKE) -C parser gram.h
 
 utils/fmgroids.h: utils/Gen_fmgrtab.sh $(top_srcdir)/src/include/catalog/pg_proc.h
@@ -131,7 +131,7 @@ utils/probes.h: utils/probes.d
 # we can cut down on the -I options. Also, a symlink is automatically
 # up to date when we update the base file.
 
-$(top_builddir)/src/include/parser/gram.h: $(srcdir)/parser/gram.h
+$(top_builddir)/src/include/parser/gram.h: parser/gram.h
 	prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
 	  cd $(dir $@) && rm -f $(notdir $@) && \
 	  $(LN_S) "$$prereqdir/$(notdir $<)" .
@@ -252,12 +252,12 @@ distclean: clean
 	rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
 
 maintainer-clean: distclean
-	rm -f $(srcdir)/bootstrap/bootparse.c \
-	      $(srcdir)/bootstrap/bootscanner.c \
-	      $(srcdir)/parser/gram.c \
-	      $(srcdir)/parser/scan.c \
-	      $(srcdir)/parser/gram.h \
-	      $(srcdir)/utils/misc/guc-file.c
+	rm -f bootstrap/bootparse.c \
+	      bootstrap/bootscanner.c \
+	      parser/gram.c \
+	      parser/scan.c \
+	      parser/gram.h \
+	      utils/misc/guc-file.c
 
 
 ##########################################################################
diff --git a/src/backend/bootstrap/Makefile b/src/backend/bootstrap/Makefile
index 3a68367aaee359621587e2110c8429a4bf5337d4..53cc71285e5a6eb5082f76535c9984bd0e8aff0a 100644
--- a/src/backend/bootstrap/Makefile
+++ b/src/backend/bootstrap/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for the bootstrap module
 #
-# $PostgreSQL: pgsql/src/backend/bootstrap/Makefile,v 1.37 2008/08/29 13:02:32 petere Exp $
+# $PostgreSQL: pgsql/src/backend/bootstrap/Makefile,v 1.38 2009/08/28 20:26:18 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -18,16 +18,16 @@ include $(top_srcdir)/src/backend/common.mk
 
 
 # bootscanner is compiled as part of bootparse
-bootparse.o: $(srcdir)/bootscanner.c
+bootparse.o: bootscanner.c
 
-$(srcdir)/bootparse.c: bootparse.y
+bootparse.c: bootparse.y
 ifdef BISON
 	$(BISON) $(BISONFLAGS) -o $@ $<
 else
 	@$(missing) bison $< $@
 endif
 
-$(srcdir)/bootscanner.c: bootscanner.l
+bootscanner.c: bootscanner.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile
index 2d0db5e30786f2979ae9d987813a170e16a31295..1ef3bb24db1a2e85704c2d308b169a0e74a4d4c8 100644
--- a/src/backend/parser/Makefile
+++ b/src/backend/parser/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for parser
 #
-# $PostgreSQL: pgsql/src/backend/parser/Makefile,v 1.50 2009/08/26 22:15:59 petere Exp $
+# $PostgreSQL: pgsql/src/backend/parser/Makefile,v 1.51 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -22,7 +22,7 @@ include $(top_srcdir)/src/backend/common.mk
 
 
 # scan is compiled as part of gram
-gram.o: $(srcdir)/scan.c
+gram.o: scan.c
 
 # Latest flex causes warnings in this file.
 ifeq ($(GCC),yes)
@@ -37,9 +37,9 @@ endif
 # important, otherwise make will choose the built-in rule for
 # gram.y=>gram.c.
 
-$(srcdir)/gram.h: $(srcdir)/gram.c ;
+gram.h: gram.c ;
 
-$(srcdir)/gram.c: gram.y
+gram.c: gram.y
 ifdef BISON
 	$(BISON) -d $(BISONFLAGS) -o $@ $<
 else
@@ -47,7 +47,7 @@ else
 endif
 
 
-$(srcdir)/scan.c: scan.l
+scan.c: scan.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
@@ -56,7 +56,7 @@ endif
 
 
 # Force these dependencies to be known even without dependency info built:
-gram.o keywords.o parser.o: $(srcdir)/gram.h
+gram.o keywords.o parser.o: gram.h
 
 
 # gram.c, gram.h, and scan.c are in the distribution tarball, so they
diff --git a/src/backend/snowball/Makefile b/src/backend/snowball/Makefile
index 1b3d5a5a3f6db43caeaa16c9a6089f1df8f39117..698ef4f94f33e4393902aa976cd28810c1edfeaf 100644
--- a/src/backend/snowball/Makefile
+++ b/src/backend/snowball/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for src/backend/snowball
 #
-# $PostgreSQL: pgsql/src/backend/snowball/Makefile,v 1.7 2009/08/26 22:24:43 petere Exp $
+# $PostgreSQL: pgsql/src/backend/snowball/Makefile,v 1.8 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -71,11 +71,7 @@ LANGUAGES=  \
 SQLSCRIPT= snowball_create.sql
 DICTDIR=tsearch_data
 
-ifdef VPATH
-override VPATH := $(srcdir)/libstemmer:$(VPATH)
-else
-VPATH = $(srcdir)/libstemmer
-endif
+VPATH += $(srcdir)/libstemmer
 
 NAME := dict_snowball
 rpath =
diff --git a/src/backend/utils/misc/Makefile b/src/backend/utils/misc/Makefile
index 4b6068bbf96185e9616383e383732f119057347d..d94530dca1ff04a26678c1fd65e6b428bb8927c4 100644
--- a/src/backend/utils/misc/Makefile
+++ b/src/backend/utils/misc/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for utils/misc
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/backend/utils/misc/Makefile,v 1.28 2008/02/19 10:30:09 petere Exp $
+#    $PostgreSQL: pgsql/src/backend/utils/misc/Makefile,v 1.29 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -12,7 +12,7 @@ subdir = src/backend/utils/misc
 top_builddir = ../../../..
 include $(top_builddir)/src/Makefile.global
 
-override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
+override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 
 OBJS = guc.o help_config.o pg_rusage.o ps_status.o superuser.o tzparser.o
 
@@ -25,9 +25,9 @@ endif
 include $(top_srcdir)/src/backend/common.mk
 
 # guc-file is compiled as part of guc
-guc.o: $(srcdir)/guc-file.c
+guc.o: guc-file.c
 
-$(srcdir)/guc-file.c: guc-file.l
+guc-file.c: guc-file.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile
index aeeeebf649f3d1a8ffde50dff07c8a3a3ab12c11..5a7cade37459424cd61e885f19f93ab37806700a 100644
--- a/src/bin/psql/Makefile
+++ b/src/bin/psql/Makefile
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.64 2009/08/26 22:24:43 petere Exp $
+# $PostgreSQL: pgsql/src/bin/psql/Makefile,v 1.65 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,7 +17,7 @@ include $(top_builddir)/src/Makefile.global
 
 REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref
 
-override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/pg_dump $(CPPFLAGS)
+override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/pg_dump $(CPPFLAGS)
 
 OBJS=	command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
 	startup.o prompt.o variables.o large_obj.o print.o describe.o \
@@ -32,7 +32,7 @@ all: submake-libpq submake-libpgport psql
 psql: $(OBJS) $(libpq_builddir)/libpq.a
 	$(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LIBS) -o $@$(X)
 
-help.o: $(srcdir)/sql_help.h
+help.o: sql_help.h
 
 dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
 	rm -f $@ && $(LN_S) $< .
@@ -40,17 +40,17 @@ dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
 kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
 	rm -f $@ && $(LN_S) $< .
 
-$(srcdir)/sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
+sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
 	$(PERL) $< $(REFDOCDIR) $@
 
-$(srcdir)/psqlscan.c: psqlscan.l
+psqlscan.c: psqlscan.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
 	@$(missing) flex $< $@
 endif
 
-distprep: $(srcdir)/sql_help.h $(srcdir)/psqlscan.c
+distprep: sql_help.h psqlscan.c
 
 install: all installdirs
 	$(INSTALL_PROGRAM) psql$(X) '$(DESTDIR)$(bindir)/psql$(X)'
@@ -67,4 +67,4 @@ clean distclean:
 	rm -f psql$(X) $(OBJS) dumputils.c keywords.c kwlookup.c
 
 maintainer-clean: distclean
-	rm -f $(srcdir)/sql_help.h $(srcdir)/psqlscan.c
+	rm -f sql_help.h psqlscan.c
diff --git a/src/interfaces/ecpg/preproc/Makefile b/src/interfaces/ecpg/preproc/Makefile
index 35332e38ffc0f0177bd36a34795c7420f6f382ce..88ba8c3505c6f0dbca8e49424cf934ee31f381cf 100644
--- a/src/interfaces/ecpg/preproc/Makefile
+++ b/src/interfaces/ecpg/preproc/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1998-2009, PostgreSQL Global Development Group
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.144 2009/08/26 22:24:43 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/Makefile,v 1.145 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -18,7 +18,7 @@ MINOR_VERSION= 6
 PATCHLEVEL=0
 
 override CPPFLAGS := -I../include -I$(top_srcdir)/src/interfaces/ecpg/include \
-	-I$(srcdir) -DMAJOR_VERSION=$(MAJOR_VERSION) \
+	-I. -I$(srcdir) -DMAJOR_VERSION=$(MAJOR_VERSION) \
 	-DMINOR_VERSION=$(MINOR_VERSION) -DPATCHLEVEL=$(PATCHLEVEL) \
 	 $(CPPFLAGS)
 
@@ -34,33 +34,33 @@ ecpg: $(OBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) $^ $(LIBS) $(PTHREAD_LIBS) -o $@$(X)
 
 # pgc is compiled as part of preproc
-preproc.o: $(srcdir)/pgc.c
+preproc.o: pgc.c
 
-$(srcdir)/preproc.h: $(srcdir)/preproc.c ;
+preproc.h: preproc.c ;
 
-$(srcdir)/preproc.c: $(srcdir)/preproc.y
+preproc.c: preproc.y
 ifdef BISON
 	$(BISON) -d $(BISONFLAGS) -o $@ $<
 else
 	@$(missing) bison $< $@
 endif
 
-$(srcdir)/pgc.c: $(srcdir)/pgc.l
+pgc.c: pgc.l
 ifdef FLEX
 	$(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
 	@$(missing) flex $< $@
 endif
 
-$(srcdir)/preproc.y: $(top_srcdir)/src/backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
+preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
 	$(PERL) $(srcdir)/parse.pl $(srcdir) < $< > $@ 
 
 ecpg_keywords.o c_keywords.o keywords.o preproc.o parser.o: preproc.h
 
-kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
+kwlookup.c: % : ../../../backend/parser/%
 	rm -f $@ && $(LN_S) $< .
 
-distprep: $(srcdir)/preproc.y $(srcdir)/preproc.c $(srcdir)/preproc.h $(srcdir)/pgc.c
+distprep: preproc.y preproc.c preproc.h pgc.c
 
 install: all installdirs
 	$(INSTALL_PROGRAM) ecpg$(X) '$(DESTDIR)$(bindir)'
@@ -80,4 +80,4 @@ clean distclean:
 # since we want to ship those files in the distribution for people with
 # inadequate tools.  Instead, `make maintainer-clean' will remove them.
 maintainer-clean: distclean
-	rm -f $(srcdir)/preproc.y $(srcdir)/preproc.c $(srcdir)/preproc.h $(srcdir)/pgc.c
+	rm -f preproc.y preproc.c preproc.h pgc.c
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index b56b640bba9b1133aac52748efcd6918f56e7640..3662ef699e9fc8404461f198b7385d4b207d60de 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -5,7 +5,7 @@
 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 # Portions Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.175 2009/08/26 22:24:43 petere Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.176 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -90,9 +90,9 @@ encnames.c wchar.c : % : $(backend_src)/utils/mb/%
 	rm -f $@ && $(LN_S) $< .
 
 
-distprep: $(srcdir)/libpq-dist.rc
+distprep: libpq-dist.rc
 
-libpq.rc $(srcdir)/libpq-dist.rc: libpq.rc.in
+libpq.rc libpq-dist.rc: libpq.rc.in
 	sed -e 's/\(VERSION.*\),0 *$$/\1,'`date '+%y%j' | sed 's/^0*//'`'/' $< >$@
 
 # Depend on Makefile.global to force rebuild on re-run of configure.
@@ -128,4 +128,4 @@ clean distclean: clean-lib
 	rm -f pg_config_paths.h
 
 maintainer-clean: distclean maintainer-clean-lib
-	rm -f $(srcdir)/libpq-dist.rc
+	rm -f libpq-dist.rc
diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile
index cc2a9fca2d1ac554ad18a333c4b9333b963515a1..da84357e20bbaf074bdbad10da3cecfe398a7c3f 100644
--- a/src/pl/plpgsql/src/Makefile
+++ b/src/pl/plpgsql/src/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for the plpgsql shared object
 #
-# $PostgreSQL: pgsql/src/pl/plpgsql/src/Makefile,v 1.33 2008/08/29 13:02:33 petere Exp $
+# $PostgreSQL: pgsql/src/pl/plpgsql/src/Makefile,v 1.34 2009/08/28 20:26:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,7 +13,7 @@ include $(top_builddir)/src/Makefile.global
 # Shared library parameters
 NAME= plpgsql
 
-override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
+override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
 SHLIB_LINK = $(filter -lintl, $(LIBS))
 rpath =
 
@@ -33,16 +33,16 @@ uninstall: uninstall-lib
 
 
 # Force these dependencies to be known even without dependency info built:
-pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgsql.h $(srcdir)/pl_gram.h
+pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgsql.h pl_gram.h
 
 # pl_scan is compiled as part of pl_gram
-pl_gram.o: $(srcdir)/pl_scan.c
+pl_gram.o: pl_scan.c
 
 # See notes in src/backend/parser/Makefile about the following two rules
 
-$(srcdir)/pl_gram.h: $(srcdir)/pl_gram.c ;
+pl_gram.h: pl_gram.c ;
 
-$(srcdir)/pl_gram.c: gram.y
+pl_gram.c: gram.y
 ifdef BISON
 	$(BISON) -d $(BISONFLAGS) -o $@ $<
 else
@@ -53,14 +53,14 @@ endif
 # depending on what the compile-time locale setting is.  Hence, force
 # it to see LC_CTYPE=C to ensure consistent build results.
 
-$(srcdir)/pl_scan.c: scan.l
+pl_scan.c: scan.l
 ifdef FLEX
 	LC_CTYPE=C $(FLEX) $(FLEXFLAGS) -o'$@' $<
 else
 	@$(missing) flex $< $@
 endif
 
-distprep: $(srcdir)/pl_scan.c $(srcdir)/pl_gram.h $(srcdir)/pl_gram.c
+distprep: pl_scan.c pl_gram.h pl_gram.c
 
 # pl_gram.c, pl_gram.h, and pl_scan.c are in the distribution tarball,
 # so they are not cleaned here.
@@ -68,4 +68,4 @@ clean distclean: clean-lib
 	rm -f $(OBJS)
 
 maintainer-clean: clean
-	rm -f $(srcdir)/pl_gram.c $(srcdir)/pl_gram.h $(srcdir)/pl_scan.c
+	rm -f pl_gram.c pl_gram.h pl_scan.c