diff --git a/src/interfaces/ecpg/pgtypeslib/Makefile b/src/interfaces/ecpg/pgtypeslib/Makefile
index fadcef3906947d04089562ae30f153e5d8e8dd55..5bf237a6a49b04702dddd09aa628d7426ac7e6ee 100644
--- a/src/interfaces/ecpg/pgtypeslib/Makefile
+++ b/src/interfaces/ecpg/pgtypeslib/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.26 2005/03/14 17:27:50 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/Makefile,v 1.27 2005/12/06 05:26:21 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,28 +17,30 @@ SO_MAJOR_VERSION= 2
 SO_MINOR_VERSION= 1
 DLTYPE= library
 
-override CPPFLAGS := -I$(top_srcdir)/src/interfaces/ecpg/include \
-	-I$(top_srcdir)/src/include/utils -I$(libpq_srcdir) $(CPPFLAGS) \
-	$(PTHREAD_CFLAGS) -DFRONTEND
+override CPPFLAGS := -DFRONTEND -I$(top_srcdir)/src/interfaces/ecpg/include \
+	-I$(top_srcdir)/src/include/utils -I$(libpq_srcdir) $(CPPFLAGS)
+override CFLAGS += $(PTHREAD_CFLAGS)
 
-# Need to recomple any libpgport object files
-LIBS := $(patsubst -lpgport,, $(LIBS))
+# Need to recompile any libpgport object files
+LIBS := $(filter-out -lpgport, $(LIBS))
 
 SHLIB_LINK += -lm
 
 OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
 	pgstrcasecmp.o \
-	$(filter rint.o, $(LIBOBJS))
+	$(filter rint.o snprintf.o, $(LIBOBJS))
 
 all: all-lib
 
 # Shared library stuff
 include $(top_srcdir)/src/Makefile.shlib
 
-rint.c: %.c : $(top_srcdir)/src/port/%.c
-	rm -f $@ && $(LN_S) $< .
+# We use some port modules verbatim, but since we need to
+# compile with appropriate options to build a shared lib, we can't
+# necessarily use the same object files as the backend uses. Instead,
+# symlink the source files in here and build our own object file.
 
-pgstrcasecmp.c: %.c : $(top_srcdir)/src/port/%.c
+pgstrcasecmp.c rint.c snprintf.c: % : $(top_srcdir)/src/port/%
 	rm -f $@ && $(LN_S) $< .
 
 install: all installdirs install-lib
@@ -49,7 +51,7 @@ installdirs:
 uninstall: uninstall-lib
 
 clean distclean maintainer-clean: clean-lib
-	rm -f $(OBJS) rint.c pgstrcasecmp.c
+	rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend