[Patch] Mingw: Fix import library extension, build actual static libraries

2019-03-07 Thread Sandro Mani
Currently building postgresql for Win32 with a mingw toolchain produces 
import libraries with *.a extension, whereas the extension should be 
*.dll.a. There are various downstream workarounds for this, see i.e. [1] 
and [2]. The attached patch 0001-Fix-import-library-extension.patch 
addresses this.


Related, no actual static libraries are produced alongside the 
respective dlls. The attached patch 0002-Build-static-libraries.patch 
addresses this, in a similar fashion as is already done for the AIX case 
in Makefile.shlib.


Thanks Sandro

[1] 
https://src.fedoraproject.org/rpms/mingw-postgresql/blob/master/f/mingw-postgresql.spec#_144 
[2] 
https://aur.archlinux.org/cgit/aur.git/tree/0001-Use-.dll.a-as-extension-for-import-libraries.patch?h=mingw-w64-postgresql 



>From 9cf2d3076750f0214c448aaabcbcf7ba5aed6594 Mon Sep 17 00:00:00 2001
From: Sandro Mani 
Date: Thu, 7 Mar 2019 14:48:57 +0100
Subject: [PATCH 1/2] Fix import library extension

---
 src/Makefile.shlib   |  5 +++--
 src/backend/Makefile | 24 
 2 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 373d73caef..aeaa46e89b 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -383,12 +383,12 @@ $(stlib): $(shlib)
 # Else we just use --export-all-symbols.
 ifeq (,$(SHLIB_EXPORTS))
 $(shlib): $(OBJS) | $(SHLIB_PREREQS)
-	$(CC) $(CFLAGS)  -shared -static-libgcc -o $@  $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--export-all-symbols -Wl,--out-implib=$(stlib)
+	$(CC) $(CFLAGS)  -shared -static-libgcc -o $@  $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--export-all-symbols -Wl,--out-implib=lib$(NAME).dll.a
 else
 DLL_DEFFILE = lib$(NAME)dll.def
 
 $(shlib): $(OBJS) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
-	$(CC) $(CFLAGS)  -shared -static-libgcc -o $@  $(OBJS) $(DLL_DEFFILE) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--out-implib=$(stlib)
+	$(CC) $(CFLAGS)  -shared -static-libgcc -o $@  $(OBJS) $(DLL_DEFFILE) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--out-implib=lib$(NAME).dll.a
 endif
 
 endif # PORTNAME == cygwin
@@ -482,6 +482,7 @@ endif # not cygwin
 endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
+	$(INSTALL_DATA) $< '$(DESTDIR)$(libdir)/lib$(NAME).dll.a'
 endif
 else # no soname
 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)'
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 478a96db9b..e4f52d0b53 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -69,11 +69,11 @@ endif
 ifeq ($(PORTNAME), cygwin)
 
 postgres: $(OBJS)
-	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@
+	$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.dll.a $(LIBS) -o $@
 
-# libpostgres.a is actually built in the preceding rule, but we need this to
+# libpostgres.dll.a is actually built in the preceding rule, but we need this to
 # ensure it's newer than postgres; see notes in src/backend/parser/Makefile
-libpostgres.a: postgres
+libpostgres.dll.a: postgres
 	touch $@
 
 endif # cygwin
@@ -82,11 +82,11 @@ ifeq ($(PORTNAME), win32)
 LIBS += -lsecur32
 
 postgres: $(OBJS) $(WIN32RES)
-	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@$(X)
+	$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.dll.a $(LIBS) -o $@$(X)
 
-# libpostgres.a is actually built in the preceding rule, but we need this to
+# libpostgres.dll.a is actually built in the preceding rule, but we need this to
 # ensure it's newer than postgres; see notes in src/backend/parser/Makefile
-libpostgres.a: postgres
+libpostgres.dll.a: postgres
 	touch $@
 
 endif # win32
@@ -195,12 +195,12 @@ distprep:
 install: all installdirs install-bin
 ifeq ($(PORTNAME), cygwin)
 ifeq ($(MAKE_DLL), true)
-	$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
+	$(INSTALL_DATA) libpostgres.dll.a '$(DESTDIR)$(libdir)/libpostgres.dll.a'
 endif
 endif
 ifeq ($(PORTNAME), win32)
 ifeq ($(MAKE_DLL), true)
-	$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
+	$(INSTALL_DATA) libpostgres.dll.a '$(DESTDIR)$(libdir)/libpostgres.dll.a'
 endif
 endif
 	$(MAKE) -C catalog install-data
@@ -260,12 +260,12 @@ ifeq ($(MAKE_EXPORTS), true)
 endif
 ifeq ($(PORTNAME), cygwin)
 ifeq ($(MAKE_DLL), true)
-	rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
+	rm -f '$(DESTDIR)$(libdir)/libpos

Re: [Patch] Mingw: Fix import library extension, build actual static libraries

2019-04-02 Thread Sandro Mani
Any chance these patches could be considered?

Thanks
Sandro

On Thu, Mar 7, 2019 at 3:23 PM Sandro Mani  wrote:

> Currently building postgresql for Win32 with a mingw toolchain produces
> import libraries with *.a extension, whereas the extension should be
> *.dll.a. There are various downstream workarounds for this, see i.e. [1]
> and [2]. The attached patch 0001-Fix-import-library-extension.patch
> addresses this.
>
> Related, no actual static libraries are produced alongside the respective
> dlls. The attached patch 0002-Build-static-libraries.patch addresses this,
> in a similar fashion as is already done for the AIX case in Makefile.shlib.
>
> Thanks Sandro
>
> [1]
> https://src.fedoraproject.org/rpms/mingw-postgresql/blob/master/f/mingw-postgresql.spec#_144
> [2]
> https://aur.archlinux.org/cgit/aur.git/tree/0001-Use-.dll.a-as-extension-for-import-libraries.patch?h=mingw-w64-postgresql
>


[Patch] Use internal pthreads reimplementation only when building with MSVC

2020-04-08 Thread Sandro Mani

Hi

The following patch, which we added to build mingw-postgresql on Fedora, 
makes the internal minimal pthreads reimplementation only used when 
building with MSVC, as on MINGW it causes symbol collisions with the 
symbols provided my winpthreads.


Thanks
Sandro


diff -rupN postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 
postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c
--- postgresql-11.5/src/interfaces/ecpg/ecpglib/misc.c 2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/ecpglib/misc.c 2020-04-08 
11:20:39.850738296 +0200

@@ -449,7 +449,7 @@ ECPGis_noind_null(enum ECPGttype type, c
 return false;
 }

-#ifdef WIN32
+#ifdef _MSC_VER
 #ifdef ENABLE_THREAD_SAFETY

 void
diff -rupN 
postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h
--- postgresql-11.5/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2019-08-05 23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/ecpg/include/ecpg-pthread-win32.h 
2020-04-08 11:20:39.851738296 +0200

@@ -7,7 +7,7 @@

 #ifdef ENABLE_THREAD_SAFETY

-#ifndef WIN32
+#ifndef _MSC_VER

 #include 
 #else
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-connect.c 
postgresql-11.5-new/src/interfaces/libpq/fe-connect.c
--- postgresql-11.5/src/interfaces/libpq/fe-connect.c 2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-connect.c 2020-04-08 
11:20:39.853738297 +0200

@@ -50,7 +50,7 @@
 #endif

 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include 
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure.c    2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure.c 2020-04-08 
11:20:39.854738297 +0200

@@ -48,7 +48,7 @@
 #include 

 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include 
diff -rupN postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 
postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c
--- postgresql-11.5/src/interfaces/libpq/fe-secure-openssl.c 2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/fe-secure-openssl.c 
2020-04-08 11:20:39.855738298 +0200

@@ -47,7 +47,7 @@
 #include 

 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include 
diff -rupN postgresql-11.5/src/interfaces/libpq/libpq-int.h 
postgresql-11.5-new/src/interfaces/libpq/libpq-int.h
--- postgresql-11.5/src/interfaces/libpq/libpq-int.h    2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/libpq-int.h 2020-04-08 
11:20:39.855738298 +0200

@@ -29,7 +29,7 @@
 #endif

 #ifdef ENABLE_THREAD_SAFETY
-#ifdef WIN32
+#ifdef _MSC_VER
 #include "pthread-win32.h"
 #else
 #include 
diff -rupN postgresql-11.5/src/interfaces/libpq/pthread-win32.c 
postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c
--- postgresql-11.5/src/interfaces/libpq/pthread-win32.c 2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/pthread-win32.c 2020-04-08 
11:21:51.674766968 +0200

@@ -10,10 +10,13 @@
 *-
 */

+#ifdef _MSC_VER
+
 #include "postgres_fe.h"

 #include "pthread-win32.h"

+
 DWORD
 pthread_self(void)
 {
@@ -58,3 +61,5 @@ pthread_mutex_unlock(pthread_mutex_t *mp
 LeaveCriticalSection(*mp);
 return 0;
 }
+
+#endif // _MSC_VER





[Patch] Add missing libraries to Libs.private of libpq.pc

2020-04-08 Thread Sandro Mani

Hello

The following patch, which we added to build mingw-postgresql on Fedora, 
adds some missing libraries to Libs.private of libpq.pc, discovered when 
attempting to statically link with libpq:


-lz: is required by -lcrypto
-liconv: is required by -lintl (though possibly depends on whether 
gettext was compiled with iconv support)


Thanks
Sandro


diff -rupN postgresql-11.5/src/interfaces/libpq/Makefile 
postgresql-11.5-new/src/interfaces/libpq/Makefile
--- postgresql-11.5/src/interfaces/libpq/Makefile    2019-08-05 
23:14:59.0 +0200
+++ postgresql-11.5-new/src/interfaces/libpq/Makefile 2020-04-07 
13:49:00.801203610 +0200

@@ -80,10 +80,10 @@ endif
 ifneq ($(PORTNAME), win32)
 SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto 
-lkrb5 -lgssapi_krb5 -lgss -lgssapi -lssl -lsocket -lnsl -lresolv 
-lintl, $(LIBS)) $(LDAP_LIBS_FE) $(PTHREAD_LIBS)

 else
-SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lk5crypto 
-lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), 
$(LIBS)) $(LDAP_LIBS_FE)
+SHLIB_LINK += $(filter -lcrypt -ldes -lcom_err -lcrypto -lz -lk5crypto 
-lkrb5 -lgssapi32 -lssl -lsocket -lnsl -lresolv -lintl $(PTHREAD_LIBS), 
$(LIBS)) $(LDAP_LIBS_FE)

 endif
 ifeq ($(PORTNAME), win32)
-SHLIB_LINK += -lshell32 -lws2_32 -lsecur32 $(filter -leay32 -lssleay32 
-lcomerr32 -lkrb5_32, $(LIBS))
+SHLIB_LINK += -lshell32 -lws2_32 -lsecur32 -liconv $(filter -leay32 
-lssleay32 -lcomerr32 -lkrb5_32, $(LIBS))

 endif

 SHLIB_EXPORTS = exports.txt