From 66de72169a94203c7efc3fb4b3242cd526dc1bff Mon Sep 17 00:00:00 2001
From: Boris Pek <tehnick-8@yandex.ru>
Date: Wed, 21 Mar 2018 02:10:30 +0300
Subject: fix qt5-freeze example after e69081f70f1c4d3d2ec5e54ac1aab2b84532450c

---
 plugins/examples/qt5-freeze/openssl-1-fixes.patch  | 593 +++++++++++++++++++++
 plugins/examples/qt5-freeze/openssl.mk             |  42 ++
 .../examples/qt5-freeze/postgresql-1-fixes.patch   | 137 +++++
 .../postgresql-2-autoconf-min-version.patch        |  29 +
 .../qt5-freeze/postgresql-3-mingw-errno.patch      | 152 ++++++
 plugins/examples/qt5-freeze/postgresql.mk          |  87 +++
 6 files changed, 1040 insertions(+)
 create mode 100644 plugins/examples/qt5-freeze/openssl-1-fixes.patch
 create mode 100644 plugins/examples/qt5-freeze/openssl.mk
 create mode 100644 plugins/examples/qt5-freeze/postgresql-1-fixes.patch
 create mode 100644 plugins/examples/qt5-freeze/postgresql-2-autoconf-min-version.patch
 create mode 100644 plugins/examples/qt5-freeze/postgresql-3-mingw-errno.patch
 create mode 100644 plugins/examples/qt5-freeze/postgresql.mk

diff --git a/plugins/examples/qt5-freeze/openssl-1-fixes.patch b/plugins/examples/qt5-freeze/openssl-1-fixes.patch
new file mode 100644
index 0000000..132f1b4
--- /dev/null
+++ b/plugins/examples/qt5-freeze/openssl-1-fixes.patch
@@ -0,0 +1,593 @@
+This file is part of MXE. See LICENSE.md for licensing information.
+
+Contains ad hoc patches for cross building.
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Mark Brand <mabrand@mabrand.nl>
+Date: Wed, 8 Jan 2014 02:19:10 +0100
+Subject: [PATCH 1/2] winsock2
+
+-This patch has been taken from:
+-http://rt.openssl.org/Ticket/Display.html?id=2285&user=guest&pass=guest
+
+diff --git a/ssl/dtls1.h b/ssl/dtls1.h
+index 1111111..2222222 100644
+--- a/ssl/dtls1.h
++++ b/ssl/dtls1.h
+@@ -68,7 +68,7 @@
+ # endif
+ # ifdef OPENSSL_SYS_WIN32
+ /* Needed for struct timeval */
+-#  include <winsock.h>
++#  include <winsock2.h>
+ # elif defined(OPENSSL_SYS_NETWARE) && !defined(_WINSOCK2API_)
+ #  include <sys/timeval.h>
+ # else
+diff --git a/ssl/ssltest.c b/ssl/ssltest.c
+index 1111111..2222222 100644
+--- a/ssl/ssltest.c
++++ b/ssl/ssltest.c
+@@ -198,7 +198,7 @@
+ #define _XOPEN_SOURCE_EXTENDED  1
+ 
+ #ifdef OPENSSL_SYS_WINDOWS
+-# include <winsock.h>
++# include <winsock2.h>
+ #else
+ # include OPENSSL_UNISTD
+ #endif
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Tom Molesworth <tom@entitymodel.com>
+Date: Wed, 8 Jan 2014 02:20:21 +0100
+Subject: [PATCH 2/2] Patch OpenSSL POD docs for perl-5.16+
+
+Stricter validation in recent Perl versions means the install
+stage fails without these applied.
+
+Should be harmless for earlier versions of perl.
+
+diff --git a/doc/apps/cms.pod b/doc/apps/cms.pod
+index 1111111..2222222 100644
+--- a/doc/apps/cms.pod
++++ b/doc/apps/cms.pod
+@@ -483,28 +483,28 @@ with caution. For a fuller description see L<CMS_decrypt(3)|CMS_decrypt(3)>).
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ the operation was completely successfully.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ an error occurred parsing the command options.
+ 
+-=item Z<>2
++=item * Z<>2
+ 
+ one of the input files could not be read.
+ 
+-=item Z<>3
++=item * Z<>3
+ 
+ an error occurred creating the CMS file or when reading the MIME
+ message.
+ 
+-=item Z<>4
++=item * Z<>4
+ 
+ an error occurred decrypting or verifying the message.
+ 
+-=item Z<>5
++=item * Z<>5
+ 
+ the message was verified correctly but an error occurred writing out
+ the signers certificates.
+diff --git a/doc/apps/smime.pod b/doc/apps/smime.pod
+index 1111111..2222222 100644
+--- a/doc/apps/smime.pod
++++ b/doc/apps/smime.pod
+@@ -313,28 +313,28 @@ remains DER.
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ the operation was completely successfully.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ an error occurred parsing the command options.
+ 
+-=item Z<>2
++=item * Z<>2
+ 
+ one of the input files could not be read.
+ 
+-=item Z<>3
++=item * Z<>3
+ 
+ an error occurred creating the PKCS#7 file or when reading the MIME
+ message.
+ 
+-=item Z<>4
++=item * Z<>4
+ 
+ an error occurred decrypting or verifying the message.
+ 
+-=item Z<>5
++=item * Z<>5
+ 
+ the message was verified correctly but an error occurred writing out
+ the signers certificates.
+diff --git a/doc/crypto/rand.pod b/doc/crypto/rand.pod
+index 1111111..2222222 100644
+--- a/doc/crypto/rand.pod
++++ b/doc/crypto/rand.pod
+@@ -74,16 +74,16 @@ First up I will state the things I believe I need for a good RNG.
+ 
+ =over 4
+ 
+-=item 1
++=item * 1
+ 
+ A good hashing algorithm to mix things up and to convert the RNG 'state'
+ to random numbers.
+ 
+-=item 2
++=item * 2
+ 
+ An initial source of random 'state'.
+ 
+-=item 3
++=item * 3
+ 
+ The state should be very large.  If the RNG is being used to generate
+ 4096 bit RSA keys, 2 2048 bit random strings are required (at a minimum).
+@@ -93,13 +93,13 @@ carried away on this last point but it does indicate that it may not be
+ a bad idea to keep quite a lot of RNG state.  It should be easier to
+ break a cipher than guess the RNG seed data.
+ 
+-=item 4
++=item * 4
+ 
+ Any RNG seed data should influence all subsequent random numbers
+ generated.  This implies that any random seed data entered will have
+ an influence on all subsequent random numbers generated.
+ 
+-=item 5
++=item * 5
+ 
+ When using data to seed the RNG state, the data used should not be
+ extractable from the RNG state.  I believe this should be a
+@@ -108,12 +108,12 @@ data would be a private key or a password.  This data must
+ not be disclosed by either subsequent random numbers or a
+ 'core' dump left by a program crash.
+ 
+-=item 6
++=item * 6
+ 
+ Given the same initial 'state', 2 systems should deviate in their RNG state
+ (and hence the random numbers generated) over time if at all possible.
+ 
+-=item 7
++=item * 7
+ 
+ Given the random number output stream, it should not be possible to determine
+ the RNG state or the next random number.
+diff --git a/doc/ssl/SSL_COMP_add_compression_method.pod b/doc/ssl/SSL_COMP_add_compression_method.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_COMP_add_compression_method.pod
++++ b/doc/ssl/SSL_COMP_add_compression_method.pod
+@@ -59,11 +59,11 @@ SSL_COMP_add_compression_method() may return the following values:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The operation succeeded.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation failed. Check the error queue to find out the reason.
+ 
+diff --git a/doc/ssl/SSL_CTX_add_session.pod b/doc/ssl/SSL_CTX_add_session.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_add_session.pod
++++ b/doc/ssl/SSL_CTX_add_session.pod
+@@ -52,13 +52,13 @@ The following values are returned by all functions:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+  The operation failed. In case of the add operation, it was tried to add
+  the same (identical) session twice. In case of the remove operation, the
+  session was not found in the cache.
+ 
+-=item Z<>1
++=item * Z<>1
+  
+  The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_CTX_load_verify_locations.pod b/doc/ssl/SSL_CTX_load_verify_locations.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_load_verify_locations.pod
++++ b/doc/ssl/SSL_CTX_load_verify_locations.pod
+@@ -100,13 +100,13 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The operation failed because B<CAfile> and B<CApath> are NULL or the
+ processing at one of the locations specified failed. Check the error
+ stack to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_CTX_set_client_CA_list.pod b/doc/ssl/SSL_CTX_set_client_CA_list.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_set_client_CA_list.pod
++++ b/doc/ssl/SSL_CTX_set_client_CA_list.pod
+@@ -66,13 +66,13 @@ values:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ A failure while manipulating the STACK_OF(X509_NAME) object occurred or
+ the X509_NAME could not be extracted from B<cacert>. Check the error stack
+ to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_CTX_set_session_id_context.pod b/doc/ssl/SSL_CTX_set_session_id_context.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_set_session_id_context.pod
++++ b/doc/ssl/SSL_CTX_set_session_id_context.pod
+@@ -64,13 +64,13 @@ return the following values:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The length B<sid_ctx_len> of the session id context B<sid_ctx> exceeded
+ the maximum allowed length of B<SSL_MAX_SSL_SESSION_ID_LENGTH>. The error
+ is logged to the error stack.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_CTX_set_ssl_version.pod b/doc/ssl/SSL_CTX_set_ssl_version.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_set_ssl_version.pod
++++ b/doc/ssl/SSL_CTX_set_ssl_version.pod
+@@ -42,11 +42,11 @@ and SSL_set_ssl_method():
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The new choice failed, check the error stack to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_CTX_use_psk_identity_hint.pod b/doc/ssl/SSL_CTX_use_psk_identity_hint.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_CTX_use_psk_identity_hint.pod
++++ b/doc/ssl/SSL_CTX_use_psk_identity_hint.pod
+@@ -83,7 +83,7 @@ Return values from the server callback are interpreted as follows:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ PSK identity was not found. An "unknown_psk_identity" alert message
+ will be sent and the connection setup fails.
+diff --git a/doc/ssl/SSL_accept.pod b/doc/ssl/SSL_accept.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_accept.pod
++++ b/doc/ssl/SSL_accept.pod
+@@ -41,18 +41,18 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The TLS/SSL handshake was not successful but was shut down controlled and
+ by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+ return value B<ret> to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+ established.
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ The TLS/SSL handshake was not successful because a fatal error occurred either
+ at the protocol level or a connection failure occurred. The shutdown was
+diff --git a/doc/ssl/SSL_clear.pod b/doc/ssl/SSL_clear.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_clear.pod
++++ b/doc/ssl/SSL_clear.pod
+@@ -56,12 +56,12 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The SSL_clear() operation could not be performed. Check the error stack to
+ find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The SSL_clear() operation was successful.
+ 
+diff --git a/doc/ssl/SSL_connect.pod b/doc/ssl/SSL_connect.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_connect.pod
++++ b/doc/ssl/SSL_connect.pod
+@@ -41,18 +41,18 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The TLS/SSL handshake was not successful but was shut down controlled and
+ by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+ return value B<ret> to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+ established.
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ The TLS/SSL handshake was not successful, because a fatal error occurred either
+ at the protocol level or a connection failure occurred. The shutdown was
+diff --git a/doc/ssl/SSL_do_handshake.pod b/doc/ssl/SSL_do_handshake.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_do_handshake.pod
++++ b/doc/ssl/SSL_do_handshake.pod
+@@ -42,18 +42,18 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The TLS/SSL handshake was not successful but was shut down controlled and
+ by the specifications of the TLS/SSL protocol. Call SSL_get_error() with the
+ return value B<ret> to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The TLS/SSL handshake was successfully completed, a TLS/SSL connection has been
+ established.
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ The TLS/SSL handshake was not successful because a fatal error occurred either
+ at the protocol level or a connection failure occurred. The shutdown was
+diff --git a/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod b/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
++++ b/doc/ssl/SSL_get_ex_data_X509_STORE_CTX_idx.pod
+@@ -36,11 +36,11 @@ before the SSL index is created.
+ 
+ =over 4
+ 
+-=item E<gt>=0
++=item * E<gt>=0
+ 
+ The index value to access the pointer.
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ An error occurred, check the error stack for a detailed error message.
+ 
+diff --git a/doc/ssl/SSL_get_fd.pod b/doc/ssl/SSL_get_fd.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_get_fd.pod
++++ b/doc/ssl/SSL_get_fd.pod
+@@ -26,12 +26,12 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item -1
++=item * -1
+ 
+ The operation failed, because the underlying BIO is not of the correct type
+ (suitable for file descriptors).
+ 
+-=item E<gt>=0
++=item * E<gt>=0
+ 
+ The file descriptor linked to B<ssl>.
+ 
+diff --git a/doc/ssl/SSL_read.pod b/doc/ssl/SSL_read.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_read.pod
++++ b/doc/ssl/SSL_read.pod
+@@ -81,16 +81,16 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item E<gt> 0
++=item * E<gt> 0
+ 
+ The read operation was successful.
+ The return value is the number of bytes actually read from the TLS/SSL
+ connection.
+ 
+-=item Z<><= 0
++=item * Z<><= 0
+ 
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ The read operation was not successful, because either the connection was closed,
+ an error occurred or action must be taken by the calling process.
+diff --git a/doc/ssl/SSL_session_reused.pod b/doc/ssl/SSL_session_reused.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_session_reused.pod
++++ b/doc/ssl/SSL_session_reused.pod
+@@ -27,11 +27,11 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ A new session was negotiated.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ A session was reused.
+ 
+diff --git a/doc/ssl/SSL_set_fd.pod b/doc/ssl/SSL_set_fd.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_set_fd.pod
++++ b/doc/ssl/SSL_set_fd.pod
+@@ -35,11 +35,11 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The operation failed. Check the error stack to find out why.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_set_session.pod b/doc/ssl/SSL_set_session.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_set_session.pod
++++ b/doc/ssl/SSL_set_session.pod
+@@ -37,11 +37,11 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The operation failed; check the error stack to find out the reason.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The operation succeeded.
+ 
+diff --git a/doc/ssl/SSL_set_shutdown.pod b/doc/ssl/SSL_set_shutdown.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_set_shutdown.pod
++++ b/doc/ssl/SSL_set_shutdown.pod
+@@ -24,16 +24,16 @@ The shutdown state of an ssl connection is a bitmask of:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ No shutdown setting, yet.
+ 
+-=item SSL_SENT_SHUTDOWN
++=item * SSL_SENT_SHUTDOWN
+ 
+ A "close notify" shutdown alert was sent to the peer, the connection is being
+ considered closed and the session is closed and correct.
+ 
+-=item SSL_RECEIVED_SHUTDOWN
++=item * SSL_RECEIVED_SHUTDOWN
+ 
+ A shutdown alert was received form the peer, either a normal "close notify"
+ or a fatal error.
+diff --git a/doc/ssl/SSL_shutdown.pod b/doc/ssl/SSL_shutdown.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_shutdown.pod
++++ b/doc/ssl/SSL_shutdown.pod
+@@ -92,19 +92,19 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item Z<>0
++=item * Z<>0
+ 
+ The shutdown is not yet finished. Call SSL_shutdown() for a second time,
+ if a bidirectional shutdown shall be performed.
+ The output of L<SSL_get_error(3)|SSL_get_error(3)> may be misleading, as an
+ erroneous SSL_ERROR_SYSCALL may be flagged even though no error occurred.
+ 
+-=item Z<>1
++=item * Z<>1
+ 
+ The shutdown was successfully completed. The "close notify" alert was sent
+ and the peer's "close notify" alert was received.
+ 
+-=item E<lt>0
++=item * E<lt>0
+ 
+ The shutdown was not successful because a fatal error occurred either
+ at the protocol level or a connection failure occurred. It can also occur if
+diff --git a/doc/ssl/SSL_write.pod b/doc/ssl/SSL_write.pod
+index 1111111..2222222 100644
+--- a/doc/ssl/SSL_write.pod
++++ b/doc/ssl/SSL_write.pod
+@@ -74,12 +74,12 @@ The following return values can occur:
+ 
+ =over 4
+ 
+-=item E<gt> 0
++=item * E<gt> 0
+ 
+ The write operation was successful, the return value is the number of
+ bytes actually written to the TLS/SSL connection.
+ 
+-=item Z<><= 0
++=item * Z<><= 0
+ 
+ The write operation was not successful, because either the connection was
+ closed, an error occurred or action must be taken by the calling process.
diff --git a/plugins/examples/qt5-freeze/openssl.mk b/plugins/examples/qt5-freeze/openssl.mk
new file mode 100644
index 0000000..0027d94
--- /dev/null
+++ b/plugins/examples/qt5-freeze/openssl.mk
@@ -0,0 +1,42 @@
+# This file is part of MXE. See LICENSE.md for licensing information.
+
+PKG             := openssl
+$(PKG)_WEBSITE  := https://www.openssl.org/
+$(PKG)_IGNORE   :=
+$(PKG)_VERSION  := 1.0.2n
+$(PKG)_CHECKSUM := 370babb75f278c39e0c50e8c4e7493bc0f18db6867478341a832a982fd15a8fe
+$(PKG)_PATCHES  := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/$(PKG)-[0-9]*.patch)))
+$(PKG)_SUBDIR   := openssl-$($(PKG)_VERSION)
+$(PKG)_FILE     := openssl-$($(PKG)_VERSION).tar.gz
+$(PKG)_URL      := https://www.openssl.org/source/$($(PKG)_FILE)
+$(PKG)_URL_2    := https://www.openssl.org/source/old/$(call tr,$([a-z]),,$($(PKG)_VERSION))/$($(PKG)_FILE)
+$(PKG)_DEPS     := cc zlib
+
+define $(PKG)_UPDATE
+    $(WGET) -q -O- 'https://www.openssl.org/source/' | \
+    $(SED) -n 's,.*openssl-\([0-9][0-9a-z.]*\)\.tar.*,\1,p' | \
+    $(SORT) -V | \
+    tail -1
+endef
+
+define $(PKG)_BUILD
+    cd '$(1)' && CC='$(TARGET)-gcc' RC='$(TARGET)-windres' ./Configure \
+        @openssl-target@ \
+        zlib \
+        $(if $(BUILD_STATIC),no-,)shared \
+        no-capieng \
+        --prefix='$(PREFIX)/$(TARGET)'
+    $(MAKE) -C '$(1)' all install_sw -j 1 \
+        CC='$(TARGET)-gcc' \
+        RANLIB='$(TARGET)-ranlib' \
+        AR='$(TARGET)-ar rcu' \
+        CROSS_COMPILE='$(TARGET)-'
+
+    # no way to configure engines subdir install
+    $(if $(BUILD_SHARED),
+        rm -rf '$(PREFIX)/$(TARGET)/bin/engines' && \
+        mv -vf '$(PREFIX)/$(TARGET)/lib/engines' '$(PREFIX)/$(TARGET)/bin/')
+endef
+
+$(PKG)_BUILD_i686-w64-mingw32   = $(subst @openssl-target@,mingw,$($(PKG)_BUILD))
+$(PKG)_BUILD_x86_64-w64-mingw32 = $(subst @openssl-target@,mingw64,$($(PKG)_BUILD))
diff --git a/plugins/examples/qt5-freeze/postgresql-1-fixes.patch b/plugins/examples/qt5-freeze/postgresql-1-fixes.patch
new file mode 100644
index 0000000..6270046
--- /dev/null
+++ b/plugins/examples/qt5-freeze/postgresql-1-fixes.patch
@@ -0,0 +1,137 @@
+This file is part of MXE. See LICENSE.md for licensing information.
+
+Contains ad hoc patches for cross building.
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: "a@a.org" <a@a.org>
+Date: Mon, 24 Oct 2011 14:02:33 +0200
+Subject: [PATCH 1/4] use unix style names for openssl on mingw-cross-env
+
+
+diff --git a/configure.in b/configure.in
+index 1111111..2222222 100644
+--- a/configure.in
++++ b/configure.in
+@@ -926,13 +926,8 @@ fi
+ 
+ if test "$with_openssl" = yes ; then
+   dnl Order matters!
+-  if test "$PORTNAME" != "win32"; then
+-     AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])])
+-     AC_CHECK_LIB(ssl,    SSL_library_init, [], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])])
+-  else
+-     AC_SEARCH_LIBS(CRYPTO_new_ex_data, eay32 crypto, [], [AC_MSG_ERROR([library 'eay32' or 'crypto' is required for OpenSSL])])
+-     AC_SEARCH_LIBS(SSL_library_init, ssleay32 ssl, [], [AC_MSG_ERROR([library 'ssleay32' or 'ssl' is required for OpenSSL])])
+-  fi
++  AC_CHECK_LIB(crypto, CRYPTO_new_ex_data, [], [AC_MSG_ERROR([library 'crypto' is required for OpenSSL])])
++  AC_CHECK_LIB(ssl,    SSL_library_init, [], [AC_MSG_ERROR([library 'ssl' is required for OpenSSL])])
+ fi
+ 
+ if test "$with_pam" = yes ; then
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: "a@a.org" <a@a.org>
+Date: Mon, 24 Oct 2011 14:09:38 +0200
+Subject: [PATCH 2/4] do not check autoconf version
+
+
+diff --git a/configure.in b/configure.in
+index 1111111..2222222 100644
+--- a/configure.in
++++ b/configure.in
+@@ -19,10 +19,6 @@ m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
+ 
+ AC_INIT([PostgreSQL], [9.2.4], [pgsql-bugs@postgresql.org])
+ 
+-m4_if(m4_defn([m4_PACKAGE_VERSION]), [2.63], [], [m4_fatal([Autoconf version 2.63 is required.
+-Untested combinations of 'autoconf' and PostgreSQL versions are not
+-recommended.  You can remove the check from 'configure.in' but it is then
+-your responsibility whether the result works or not.])])
+ AC_COPYRIGHT([Copyright (c) 1996-2012, PostgreSQL Global Development Group])
+ AC_CONFIG_SRCDIR([src/backend/access/common/heaptuple.c])
+ AC_CONFIG_AUX_DIR(config)
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Timothy Gu <timothygu99@gmail.com>
+Date: Tue, 1 Jul 2014 14:27:21 -0700
+Subject: [PATCH 3/4] Fix shared lib install location
+
+Signed-off-by: Timothy Gu <timothygu99@gmail.com>
+
+diff --git a/src/Makefile.shlib b/src/Makefile.shlib
+index 1111111..2222222 100644
+--- a/src/Makefile.shlib
++++ b/src/Makefile.shlib
+@@ -293,6 +293,7 @@ endif
+ ifeq ($(PORTNAME), win32)
+   ifdef SO_MAJOR_VERSION
+     shlib		= lib$(NAME)$(DLSUFFIX)
++    stlib		= lib$(NAME)$(DLSUFFIX).a
+   endif
+   haslibarule   = yes
+ endif
+@@ -447,14 +448,16 @@ ifeq ($(PORTNAME), darwin)
+ endif
+ 
+ ifeq ($(enable_shared), yes)
+-install-lib-shared: $(shlib) installdirs-lib
++install-lib-shared: $(shlib)
++ifeq (, $(filter $(PORTNAME), win32 cygwin))
++install-lib-shared: installdirs-lib
++endif # not win32 or cygwin
+ ifdef soname
+ # we don't install $(shlib) on AIX
+ # (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ ifneq ($(PORTNAME), aix)
++ifeq (, $(filter $(PORTNAME), win32 cygwin))
+ 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
+-ifneq ($(PORTNAME), cygwin)
+-ifneq ($(PORTNAME), win32)
+ ifneq ($(shlib), $(shlib_major))
+ 	cd '$(DESTDIR)$(libdir)' && \
+ 	rm -f $(shlib_major) && \
+@@ -465,8 +468,9 @@ ifneq ($(shlib), $(shlib_bare))
+ 	rm -f $(shlib_bare) && \
+ 	$(LN_S) $(shlib) $(shlib_bare)
+ endif
+-endif # not win32
+-endif # not cygwin
++else  # win32 or cygwin
++	$(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
++endif # not win32 or cygwin
+ endif # not aix
+ else # no soname
+ 	$(INSTALL_SHLIB) $< '$(DESTDIR)$(pkglibdir)/$(shlib)'
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Timothy Gu <timothygu99@gmail.com>
+Date: Tue, 1 Jul 2014 14:41:44 -0700
+Subject: [PATCH 4/4] Don't build shared lib on win32 if --disable-shared is
+ set
+
+Signed-off-by: Timothy Gu <timothygu99@gmail.com>
+
+diff --git a/src/Makefile.shlib b/src/Makefile.shlib
+index 1111111..2222222 100644
+--- a/src/Makefile.shlib
++++ b/src/Makefile.shlib
+@@ -291,11 +291,15 @@ ifeq ($(PORTNAME), cygwin)
+ endif
+ 
+ ifeq ($(PORTNAME), win32)
+-  ifdef SO_MAJOR_VERSION
+-    shlib		= lib$(NAME)$(DLSUFFIX)
+-    stlib		= lib$(NAME)$(DLSUFFIX).a
++  ifeq ($(enable_shared), yes)
++    ifdef SO_MAJOR_VERSION
++      shlib		= lib$(NAME)$(DLSUFFIX)
++      stlib		= lib$(NAME)$(DLSUFFIX).a
++    endif
++    haslibarule   = yes
++  else
++    shlib		=
+   endif
+-  haslibarule   = yes
+ endif
+ 
+ 
diff --git a/plugins/examples/qt5-freeze/postgresql-2-autoconf-min-version.patch b/plugins/examples/qt5-freeze/postgresql-2-autoconf-min-version.patch
new file mode 100644
index 0000000..f61f7fe
--- /dev/null
+++ b/plugins/examples/qt5-freeze/postgresql-2-autoconf-min-version.patch
@@ -0,0 +1,29 @@
+This file is part of MXE. See LICENSE.md for licensing information.
+
+Contains ad hoc patches for cross building.
+see https://github.com/mxe/mxe/issues/672
+
+From b18fec680ef90c65247d998e3f68e7574d45e83e Mon Sep 17 00:00:00 2001
+From: "Avi Halachmi (:avih)" <avihpit@yahoo.com>
+Date: Fri, 24 Apr 2015 07:25:04 +0300
+Subject: [PATCH] autoconf: require minimum version 2.50
+
+---
+ configure.in | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/configure.in b/configure.in
+index 1257071..24f91cd 100644
+--- a/configure.in
++++ b/configure.in
+@@ -17,6 +17,7 @@ dnl Read the Autoconf manual for details.
+ dnl
+ m4_pattern_forbid(^PGAC_)dnl to catch undefined macros
+ 
++AC_PREREQ(2.63)
+ AC_INIT([PostgreSQL], [9.2.4], [pgsql-bugs@postgresql.org])
+ 
+ AC_COPYRIGHT([Copyright (c) 1996-2012, PostgreSQL Global Development Group])
+-- 
+1.9.1
+
diff --git a/plugins/examples/qt5-freeze/postgresql-3-mingw-errno.patch b/plugins/examples/qt5-freeze/postgresql-3-mingw-errno.patch
new file mode 100644
index 0000000..ae3bfe0
--- /dev/null
+++ b/plugins/examples/qt5-freeze/postgresql-3-mingw-errno.patch
@@ -0,0 +1,152 @@
+--- postgresql-9.2.4/src/interfaces/libpq/fe-connect.c.orig	2013-08-15 09:08:59.850609595 -0500
++++ postgresql-9.2.4/src/interfaces/libpq/fe-connect.c	2013-08-15 09:42:59.001463906 -0500
+@@ -1778,10 +1778,16 @@
+ 					if (connect(conn->sock, addr_cur->ai_addr,
+ 								addr_cur->ai_addrlen) < 0)
+ 					{
++#ifndef WIN32
+ 						if (SOCK_ERRNO == EINPROGRESS ||
+ 							SOCK_ERRNO == EWOULDBLOCK ||
+ 							SOCK_ERRNO == EINTR ||
++#else
++						if (SOCK_ERRNO == WSAEINPROGRESS ||
++							SOCK_ERRNO == WSAEWOULDBLOCK ||
++							SOCK_ERRNO == WSAEINTR ||
+ 							SOCK_ERRNO == 0)
++#endif
+ 						{
+ 							/*
+ 							 * This is fine - we're in non-blocking mode, and
+--- postgresql-9.2.4/src/interfaces/libpq/fe-misc.c.orig	2013-04-01 13:20:36.000000000 -0500
++++ postgresql-9.2.4/src/interfaces/libpq/fe-misc.c	2013-08-15 10:08:03.190928760 -0500
+@@ -656,7 +656,11 @@
+ 						  conn->inBufSize - conn->inEnd);
+ 	if (nread < 0)
+ 	{
++#ifndef WIN32
+ 		if (SOCK_ERRNO == EINTR)
++#else
++		if (SOCK_ERRNO == WSAEINTR)
++#endif
+ 			goto retry3;
+ 		/* Some systems return EAGAIN/EWOULDBLOCK for no data */
+ #ifdef EAGAIN
+@@ -664,12 +668,20 @@
+ 			return someread;
+ #endif
+ #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
++#ifndef WIN32
+ 		if (SOCK_ERRNO == EWOULDBLOCK)
++#else
++		if (SOCK_ERRNO == WSAEWOULDBLOCK)
++#endif
+ 			return someread;
+ #endif
+ 		/* We might get ECONNRESET here if using TCP and backend died */
+ #ifdef ECONNRESET
++#ifndef WIN32
+ 		if (SOCK_ERRNO == ECONNRESET)
++#else
++		if (SOCK_ERRNO == WSAECONNRESET)
++#endif
+ 			goto definitelyFailed;
+ #endif
+ 		/* pqsecure_read set the error message for us */
+@@ -749,7 +761,11 @@
+ 						  conn->inBufSize - conn->inEnd);
+ 	if (nread < 0)
+ 	{
++#ifndef WIN32
+ 		if (SOCK_ERRNO == EINTR)
++#else
++		if (SOCK_ERRNO == WSAEINTR)
++#endif
+ 			goto retry4;
+ 		/* Some systems return EAGAIN/EWOULDBLOCK for no data */
+ #ifdef EAGAIN
+@@ -757,12 +773,20 @@
+ 			return 0;
+ #endif
+ #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
++#ifndef WIN32
+ 		if (SOCK_ERRNO == EWOULDBLOCK)
++#else
++		if (SOCK_ERRNO == WSAEWOULDBLOCK)
++#endif
+ 			return 0;
+ #endif
+ 		/* We might get ECONNRESET here if using TCP and backend died */
+ #ifdef ECONNRESET
++#ifndef WIN32
+ 		if (SOCK_ERRNO == ECONNRESET)
++#else
++		if (SOCK_ERRNO == WSAECONNRESET)
++#endif
+ 			goto definitelyFailed;
+ #endif
+ 		/* pqsecure_read set the error message for us */
+@@ -838,10 +862,18 @@
+ 					break;
+ #endif
+ #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
++#ifndef WIN32
+ 				case EWOULDBLOCK:
++#else
++				case WSAEWOULDBLOCK:
++#endif
+ 					break;
+ #endif
++#ifndef WIN32
+ 				case EINTR:
++#else
++				case WSAEINTR:
++#endif
+ 					continue;
+ 
+ 				default:
+--- postgresql-9.2.4/src/interfaces/libpq/fe-secure.c.orig	2013-08-15 10:10:44.039355056 -0500
++++ postgresql-9.2.4/src/interfaces/libpq/fe-secure.c	2013-08-15 10:22:57.767650717 -0500
+@@ -433,12 +433,20 @@
+ #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
+ 				case EWOULDBLOCK:
+ #endif
++#ifndef WIN32
+ 				case EINTR:
++#else
++				case WSAEWOULDBLOCK:
++				case WSAEINTR:
++#endif
+ 					/* no error message, caller is expected to retry */
+ 					break;
+ 
+ #ifdef ECONNRESET
+ 				case ECONNRESET:
++#ifdef WIN32
++				case WSAECONNRESET:
++#endif
+ 					printfPQExpBuffer(&conn->errorMessage,
+ 									  libpq_gettext(
+ 								"server closed the connection unexpectedly\n"
+@@ -617,7 +625,12 @@
+ #if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
+ 				case EWOULDBLOCK:
+ #endif
++#ifndef WIN32
+ 				case EINTR:
++#else
++				case WSAEWOULDBLOCK:
++				case WSAEINTR:
++#endif
+ 					/* no error message, caller is expected to retry */
+ 					break;
+ 
+@@ -629,6 +642,9 @@
+ #ifdef ECONNRESET
+ 				case ECONNRESET:
+ #endif
++#ifdef WIN32
++				case WSAECONNRESET:
++#endif
+ 					printfPQExpBuffer(&conn->errorMessage,
+ 									  libpq_gettext(
+ 								"server closed the connection unexpectedly\n"
diff --git a/plugins/examples/qt5-freeze/postgresql.mk b/plugins/examples/qt5-freeze/postgresql.mk
new file mode 100644
index 0000000..40a3a8a
--- /dev/null
+++ b/plugins/examples/qt5-freeze/postgresql.mk
@@ -0,0 +1,87 @@
+# This file is part of MXE. See LICENSE.md for licensing information.
+
+PKG             := postgresql
+$(PKG)_WEBSITE  := https://www.postgresql.org/
+$(PKG)_DESCR    := PostgreSQL
+$(PKG)_IGNORE   :=
+$(PKG)_VERSION  := 9.2.4
+$(PKG)_CHECKSUM := d97dd918a88a4449225998f46aafa85216a3f89163a3411830d6890507ffae93
+$(PKG)_PATCHES  := $(realpath $(sort $(wildcard $(dir $(lastword $(MAKEFILE_LIST)))/$(PKG)-[0-9]*.patch)))
+$(PKG)_SUBDIR   := postgresql-$($(PKG)_VERSION)
+$(PKG)_FILE     := postgresql-$($(PKG)_VERSION).tar.bz2
+$(PKG)_URL      := https://ftp.postgresql.org/pub/source/v$($(PKG)_VERSION)/$($(PKG)_FILE)
+$(PKG)_DEPS     := cc openssl pthreads zlib
+
+define $(PKG)_UPDATE
+    $(WGET) -q -O- 'https://git.postgresql.org/gitweb?p=postgresql.git;a=tags' | \
+    grep 'refs/tags/REL9[0-9_]*"' | \
+    $(SED) 's,.*refs/tags/REL\(.*\)".*,\1,g;' | \
+    $(SED) 's,_,.,g' | \
+    $(SORT) -V | \
+    tail -1
+endef
+
+define $(PKG)_BUILD
+    cd '$(1)' && autoconf
+    cp -Rp '$(1)' '$(1).native'
+    # Since we build only client library, use bogus tzdata to satisfy configure.
+    # pthreads is needed in both LIBS and PTHREAD_LIBS
+    cd '$(1)' && ./configure \
+        $(MXE_CONFIGURE_OPTS) \
+        --disable-rpath \
+        --without-tcl \
+        --without-perl \
+        --without-python \
+        --without-gssapi \
+        --without-krb5 \
+        --without-pam \
+        --without-ldap \
+        --without-bonjour \
+        --with-openssl \
+        --without-readline \
+        --without-ossp-uuid \
+        --without-libxml \
+        --without-libxslt \
+        --with-zlib \
+        --with-system-tzdata=/dev/null \
+        LIBS="-lsecur32 `'$(TARGET)-pkg-config' openssl pthreads --libs`" \
+        ac_cv_func_getaddrinfo=no
+
+    # enable_thread_safety means "build internal pthreads" on windows
+    # disable it and link mingw-w64 pthreads to and avoid name conflicts
+    $(MAKE) -C '$(1)'/src/interfaces/libpq -j '$(JOBS)' \
+        install \
+        enable_thread_safety=no \
+        PTHREAD_LIBS="`'$(TARGET)-pkg-config' pthreads --libs`"
+    $(MAKE) -C '$(1)'/src/port             -j '$(JOBS)'
+    $(MAKE) -C '$(1)'/src/bin/psql         -j '$(JOBS)' install
+    $(INSTALL) -m644 '$(1)/src/include/pg_config.h'    '$(PREFIX)/$(TARGET)/include/'
+    $(INSTALL) -m644 '$(1)/src/include/postgres_ext.h' '$(PREFIX)/$(TARGET)/include/'
+    $(INSTALL) -d    '$(PREFIX)/$(TARGET)/include/libpq'
+    $(INSTALL) -m644 '$(1)'/src/include/libpq/*        '$(PREFIX)/$(TARGET)/include/libpq/'
+    # Build a native pg_config.
+    $(SED) -i 's,-DVAL_,-D_DISABLED_VAL_,g' '$(1).native'/src/bin/pg_config/Makefile
+    cd '$(1).native' && ./configure \
+        --prefix='$(PREFIX)/$(TARGET)' \
+        --disable-shared \
+        --disable-rpath \
+        --without-tcl \
+        --without-perl \
+        --without-python \
+        --without-gssapi \
+        --without-krb5 \
+        --without-pam \
+        --without-ldap \
+        --without-bonjour \
+        --without-openssl \
+        --without-readline \
+        --without-ossp-uuid \
+        --without-libxml \
+        --without-libxslt \
+        --without-zlib \
+        --with-system-tzdata=/dev/null
+    $(MAKE) -C '$(1).native'/src/port          -j '$(JOBS)'
+    $(MAKE) -C '$(1).native'/src/bin/pg_config -j '$(JOBS)' install
+    ln -sf '$(PREFIX)/$(TARGET)/bin/pg_config' '$(PREFIX)/bin/$(TARGET)-pg_config'
+endef
+
-- 
cgit v0.12