From dcbf39774ff3159e17c614a24740ce00fdb14620 Mon Sep 17 00:00:00 2001
From: Tom Lane <tgl@sss.pgh.pa.us>
Date: Fri, 14 Feb 2014 13:13:06 -0500
Subject: [PATCH] In mingw builds, make our own import library for libtcl, too.

Per buildfarm results.
---
 src/pl/tcl/Makefile | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/pl/tcl/Makefile b/src/pl/tcl/Makefile
index 8a6325aa469..3f9df550341 100644
--- a/src/pl/tcl/Makefile
+++ b/src/pl/tcl/Makefile
@@ -29,10 +29,29 @@ endif
 endif
 
 
-SHLIB_LINK = $(TCL_LIB_SPEC)
 ifneq ($(PORTNAME), win32)
-SHLIB_LINK += $(TCL_LIBS) -lc
-endif
+
+SHLIB_LINK = $(TCL_LIB_SPEC) $(TCL_LIBS) -lc
+
+else # win32
+
+# Tcl on win32 ships with import libraries only for Microsoft Visual C++,
+# which are not compatible with mingw gcc. Therefore we need to build a
+# new import library to link with.
+
+tclwithver = $(subst -l,,$(filter -l%, $(TCL_LIB_SPEC)))
+TCLDLL = $(subst -L,,$(filter -L%, $(TCL_LIB_SPEC)))/$(tclwithver).dll
+
+OBJS += lib$(tclwithver).a
+
+lib$(tclwithver).a: $(tclwithver).def
+	dlltool --dllname $(tclwithver).dll --def $(tclwithver).def --output-lib lib$(tclwithver).a
+
+$(tclwithver).def: $(TCLDLL)
+	pexports $^ > $@
+
+endif # win32
+
 
 NAME = pltcl
 
@@ -96,4 +115,7 @@ endif # TCL_SHARED_BUILD = 0
 clean distclean maintainer-clean: clean-lib
 	rm -f $(OBJS)
 	rm -rf $(pg_regress_clean_files)
+ifeq ($(PORTNAME), win32)
+	rm -f $(tclwithver).def
+endif
 	$(MAKE) -C modules $@
-- 
GitLab