diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 37a99dbf9518228f199680fad13fb9006e78e0ef..b4f46da00ac975efb0680adb8bdc751ae5be3a3f 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.119 2008/12/11 07:34:07 petere Exp $
+#    $PostgreSQL: pgsql/src/Makefile.shlib,v 1.120 2009/01/05 09:27:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -406,15 +406,16 @@ else # PORTNAME == cygwin || PORTNAME == win32
 
 # Cygwin or Win32 case
 
-DLL_DEFFILE = lib$(NAME)dll.def
-
 # If SHLIB_EXPORTS is set, the rules below will build a .def file from
 # that.  Else we build a temporary one here.
 ifeq (,$(SHLIB_EXPORTS))
+DLL_DEFFILE = lib$(NAME)dll.def
 exports_file = $(DLL_DEFFILE)
 
 $(exports_file): $(OBJS)
 	$(DLLTOOL) --export-all $(DLLTOOL_DEFFLAGS) --output-def $@ $^
+else
+DLL_DEFFILE = $(srcdir)/lib$(NAME)dll.def
 endif
 
 $(shlib): $(OBJS) $(DLL_DEFFILE)
diff --git a/src/bin/pgevent/Makefile b/src/bin/pgevent/Makefile
index 3512e6e642d8e165978f25258573664c96363798..6b61b93bdc98e52dc10bab179fb9cd59222356ee 100644
--- a/src/bin/pgevent/Makefile
+++ b/src/bin/pgevent/Makefile
@@ -21,11 +21,11 @@ all: $(NAME)
 
 install: all install-lib
 
-pgevent.dll: $(OBJS) pgevent.def
-	$(DLLWRAP) --def pgevent.def -o $(NAME) $(OBJS)
+pgevent.dll: pgevent.def $(OBJS)
+	$(DLLWRAP) --def $< -o $(NAME) $(OBJS)
 
 pgmsgevent.o: pgmsgevent.rc win32ver.rc
-	$(WINDRES) pgmsgevent.rc -o pgmsgevent.o --include-dir=$(top_builddir)/src/include
+	$(WINDRES) $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(top_srcdir)/src/include --include-dir=$(srcdir)
 
 all-lib: $(NAME)
 
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index bd630e4aef1245daa5a94128a7d449edf650912b..6c9f6920918a581b5b108d985c9332e2b43a93ff 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.172 2009/01/01 17:24:03 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.173 2009/01/05 09:27:19 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -19,7 +19,7 @@ NAME= pq
 SO_MAJOR_VERSION= 5
 SO_MINOR_VERSION= 2
 
-override CPPFLAGS :=  -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port
+override CPPFLAGS :=  -DFRONTEND -DUNSAFE_STAT_OK -I$(srcdir) $(CPPFLAGS) -I$(top_builddir)/src/port -I$(top_srcdir)/src/port
 ifneq ($(PORTNAME), win32)
 override CFLAGS += $(PTHREAD_CFLAGS)
 endif
diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32
index 75619c7e4664169ee3e26fdd9d8450ca92ea48e6..f3dd215b19e6cb837166fe1df19f720b5db6c3c4 100644
--- a/src/makefiles/Makefile.win32
+++ b/src/makefiles/Makefile.win32
@@ -1,4 +1,4 @@
-# $PostgreSQL: pgsql/src/makefiles/Makefile.win32,v 1.12 2008/12/07 08:36:22 petere Exp $
+# $PostgreSQL: pgsql/src/makefiles/Makefile.win32,v 1.13 2009/01/05 09:27:20 petere Exp $
 
 # Use replacement include files for those missing on Win32
 override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"
@@ -67,4 +67,4 @@ win32ver.rc: $(top_srcdir)/src/port/win32ver.rc
 	sed -e 's;FILEDESC;$(PGFILEDESC);' -e 's;VFT_APP;$(PGFTYPE);' -e 's;_ICO_;$(PGICOSTR);' -e 's;\(VERSION.*\),0 *$$;\1,'`date '+%y%j' | sed 's/^0*//'`';' $< >$@
 
 win32ver.o: win32ver.rc
-	$(WINDRES) -i $< -o $@ --include-dir=$(top_builddir)/src/include
+	$(WINDRES) -i $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(srcdir)