diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index f70d5f7..42e3654 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -61,18 +61,21 @@ ifdef PGXS
 top_builddir := $(dir $(PGXS))../..
 include $(top_builddir)/src/Makefile.global
 
-# If Makefile is not in current directory we are building the extension with
-# VPATH so we set the variable here
-# XXX what about top_srcdir ?
-ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
 top_srcdir = $(top_builddir)
+# If USE_VPATH is set or Makefile is not in current directory we are building 
+# the extension with VPATH so we set the variable here
+ifdef USE_VPATH
+srcdir = $(USE_VPATH)
+VPATH = $(USE_VPATH)
+else
+ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
 srcdir = .
 VPATH =
 else
-top_srcdir = $(top_builddir)
 srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
 VPATH = $(srcdir)
 endif
+endif
 
 # These might be set in Makefile.global, but if they were not found
 # during the build of PostgreSQL, supply default values so that users