From 2858bbfee0626ad84ba2c6510c8f894692d6eb94 Mon Sep 17 00:00:00 2001
From: Martchus <martchus@gmx.net>
Date: Fri, 3 Feb 2017 18:30:51 +0100
Subject: [PATCH 01/32] Adjust win32-g++ profile for cross compilation with
 mingw-w64

Adding a new, separate mkspec instead of patching the existing one
might be the cleaner solution. However, tools like windeployqt and
qbs do checks based on the hardcoded mkspec name to detect MinGW.
So for this to work, the mkspec must be called win32-g++.

Also see the following issues:
* https://github.com/Martchus/PKGBUILDs/issues/59
* https://github.com/Martchus/PKGBUILDs/issues/60

Change-Id: I127bb0516bd4acfea588a5d48c46811525a8fca8
---
 mkspecs/common/g++-win32.conf      | 51 ++++++++++++++++++++----------
 mkspecs/win32-clang-g++/qmake.conf |  4 +--
 mkspecs/win32-g++/qmake.conf       |  4 +--
 3 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/mkspecs/common/g++-win32.conf b/mkspecs/common/g++-win32.conf
index c3a1f3a373..793ff540a1 100644
--- a/mkspecs/common/g++-win32.conf
+++ b/mkspecs/common/g++-win32.conf
@@ -8,18 +8,24 @@
 # Compiler-specific settings go into win32-g++/qmake.conf and
 # win32-clang-g++/qmake.conf
 #
+# The device options CROSS_COMPILE_CUSTOM_CONFIG and CROSS_COMPILE_CFLAGS can be used
+# to specify custom config/flags for cross compilation.
+#
 
 load(device_config)
 include(gcc-base.conf)
 include(g++-base.conf)
 
+include(angle.conf)
+include(windows-vulkan.conf)
+
 # modifications to gcc-base.conf and g++-base.conf
 
 MAKEFILE_GENERATOR      = MINGW
 QMAKE_PLATFORM          = win32 mingw
-CONFIG                 += debug_and_release debug_and_release_target precompile_header
-DEFINES                += UNICODE _UNICODE WIN32 MINGW_HAS_SECURE_API=1
-QMAKE_COMPILER_DEFINES += __GNUC__ _WIN32
+CONFIG                 += debug_and_release debug_and_release_target precompile_header $${CROSS_COMPILE_CUSTOM_CONFIG}
+DEFINES                += UNICODE _UNICODE MINGW_HAS_SECURE_API=1
+QMAKE_COMPILER_DEFINES += __GNUC__ _WIN32 WIN32
 # can't add 'DEFINES += WIN64' and 'QMAKE_COMPILER_DEFINES += _WIN64' defines for
 # x86_64 platform similar to 'msvc-desktop.conf' toolchain, because, unlike for MSVC,
 # 'QMAKE_TARGET.arch' is inherently unavailable.
@@ -32,6 +38,7 @@ QMAKE_YACCFLAGS         = -d
 QMAKE_CFLAGS_SSE2      += -mstackrealign
 
 QMAKE_CXXFLAGS_EXCEPTIONS_ON = -fexceptions -mthreads
+QMAKE_CXXFLAGS_EXCEPTIONS_OFF = -fno-exceptions
 
 QMAKE_INCDIR            =
 
@@ -41,40 +48,50 @@ QMAKE_RUN_CXX           = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $obj $src
 QMAKE_RUN_CXX_IMP       = $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
 
 QMAKE_LFLAGS_EXCEPTIONS_ON = -mthreads
-QMAKE_LFLAGS_RELEASE    = -Wl,-s
+QMAKE_LFLAGS_RELEASE    =
+QMAKE_LFLAGS_DEBUG      =
 QMAKE_LFLAGS_CONSOLE    = -Wl,-subsystem,console
 QMAKE_LFLAGS_WINDOWS    = -Wl,-subsystem,windows
 QMAKE_LFLAGS_DLL        = -shared
 QMAKE_LFLAGS_GCSECTIONS = -Wl,--gc-sections
-equals(QMAKE_HOST.os, Windows) {
-    QMAKE_LINK_OBJECT_MAX = 10
-    QMAKE_LINK_OBJECT_SCRIPT = object_script
-}
+QMAKE_LINK_OBJECT_MAX   = 10
+QMAKE_LINK_OBJECT_SCRIPT = object_script
 QMAKE_EXT_OBJ           = .o
 QMAKE_EXT_RES           = _res.o
 QMAKE_PREFIX_SHLIB      =
 QMAKE_EXTENSION_SHLIB   = dll
 QMAKE_PREFIX_STATICLIB  = lib
 QMAKE_EXTENSION_STATICLIB = a
-QMAKE_LIB_EXTENSIONS    = a dll.a
+QMAKE_EXTENSION_IMPORTLIB = dll.a
+
+PKG_CONFIG              = $${CROSS_COMPILE}pkg-config
+QMAKE_PKG_CONFIG        = $${CROSS_COMPILE}pkg-config
 
 QMAKE_LIBS              =
-QMAKE_LIBS_GUI          = -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lws2_32 -lole32 -luuid -luser32 -ladvapi32
-QMAKE_LIBS_NETWORK      = -lws2_32
+QMAKE_LIBS_CORE         = -lz -lpcre2-16 -liconv -lversion -lnetapi32 -luserenv -lole32 -luuid -lwinmm -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
+QMAKE_LIBS_GUI          = $$system($${QMAKE_PKG_CONFIG} --libs harfbuzz) $$system($${QMAKE_PKG_CONFIG} --libs freetype2) \
+                          -ljpeg -lpng -lopengl32 -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lws2_32 -lole32 -luuid -luser32 -ladvapi32
+QMAKE_LIBS_GUI_STATIC   = $$system($${QMAKE_PKG_CONFIG} --static --libs harfbuzz | sed -e "'s/\\([^ ]*\\)brotli\\([^ ]*\\)/\\1brotli\\2-static/g'" ) \
+                          $$system($${QMAKE_PKG_CONFIG} --static --libs freetype2 | sed -e "'s/\\([^ ]*\\)brotli\\([^ ]*\\)/\\1brotli\\2-static/g'" ) \
+                          -ljpeg -lpng -lopengl32 -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lws2_32 -lole32 -luuid -luser32 -ladvapi32 -ldxgi -ld3d11
+QMAKE_LIBS_NETWORK      = -lws2_32 -lcrypt32 -ldnsapi -liphlpapi
+QMAKE_LIBS_NETWORK_STATIC = $$system($${QMAKE_PKG_CONFIG} --static --libs openssl) -lws2_32 -lcrypt32 -ldnsapi -liphlpapi
+QMAKE_LIBS_DBUS         = $$system($${QMAKE_PKG_CONFIG} --libs dbus-1)
+QMAKE_LIBS_DBUS_STATIC  = $$system($${QMAKE_PKG_CONFIG} --static --libs dbus-1)
+QMAKE_LIBS_WIDGETS_STATIC = -ldwmapi -luxtheme
 QMAKE_LIBS_OPENGL       = -lglu32 -lopengl32 -lgdi32 -luser32
-QMAKE_LIBS_OPENGL_ES2   = -lgdi32 -luser32
-QMAKE_LIBS_OPENGL_ES2_DEBUG = -lgdi32 -luser32
+QMAKE_LIBS_OPENGL_ES2   = -l$${LIBEGL_NAME} -l$${LIBGLESV2_NAME} -ld3d9 -ldxguid -lgdi32 -luser32
+QMAKE_LIBS_OPENGL_ES2_DEBUG = -l$${LIBEGL_NAME} -l$${LIBGLESV2_NAME} -ld3d9 -ldxguid -lgdi32 -luser32
 QMAKE_LIBS_COMPAT       = -ladvapi32 -lshell32 -lcomdlg32 -luser32 -lgdi32 -lws2_32
 QMAKE_LIBS_QT_ENTRY     = -lmingw32 -lqtmain
 
-QMAKE_IDL               = midl
+QMAKE_IDL               = $${CROSS_COMPILE}widl
 QMAKE_LIB               = $${CROSS_COMPILE}ar -rc
 QMAKE_RC                = $${CROSS_COMPILE}windres
+QMAKE_DLLTOOL           = $${CROSS_COMPILE}dlltool
+QMAKE_LRELEASE          = $${CROSS_COMPILE}lrelease-qt5
 
 QMAKE_STRIP             = $${CROSS_COMPILE}strip
 QMAKE_STRIPFLAGS_LIB   += --strip-unneeded
 QMAKE_OBJCOPY           = $${CROSS_COMPILE}objcopy
 QMAKE_NM                = $${CROSS_COMPILE}nm -P
-
-include(angle.conf)
-include(windows-vulkan.conf)
diff --git a/mkspecs/win32-clang-g++/qmake.conf b/mkspecs/win32-clang-g++/qmake.conf
index 59d42176f0..f8cb9859f2 100644
--- a/mkspecs/win32-clang-g++/qmake.conf
+++ b/mkspecs/win32-clang-g++/qmake.conf
@@ -14,11 +14,11 @@ include(../common/g++-win32.conf)
 QMAKE_COMPILER         += clang llvm   # clang pretends to be gcc
 
 QMAKE_CC                = $${CROSS_COMPILE}clang
-QMAKE_CFLAGS           +=
+QMAKE_CFLAGS           += $${CROSS_COMPILE_CFLAGS}
 QMAKE_CFLAGS_WARN_ON   += -Wextra -Wno-ignored-attributes
 
 QMAKE_CXX               = $${CROSS_COMPILE}clang++
-QMAKE_CXXFLAGS         +=
+QMAKE_CXXFLAGS         += $${CROSS_COMPILE_CXXFLAGS}
 QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON
 
 QMAKE_LINK              = $${CROSS_COMPILE}clang++
diff --git a/mkspecs/win32-g++/qmake.conf b/mkspecs/win32-g++/qmake.conf
index 5de482f23b..3c3d22c699 100644
--- a/mkspecs/win32-g++/qmake.conf
+++ b/mkspecs/win32-g++/qmake.conf
@@ -13,11 +13,11 @@ include(../common/windows-desktop.conf)
 # modifications to g++-win32.conf
 
 QMAKE_CC                = $${CROSS_COMPILE}gcc
-QMAKE_CFLAGS           += -fno-keep-inline-dllexport
+QMAKE_CFLAGS           += $${CROSS_COMPILE_CFLAGS}
 QMAKE_CFLAGS_WARN_ON   += -Wextra
 
 QMAKE_CXX               = $${CROSS_COMPILE}g++
-QMAKE_CXXFLAGS         += -fno-keep-inline-dllexport
+QMAKE_CXXFLAGS         += $${CROSS_COMPILE_CXXFLAGS}
 QMAKE_CXXFLAGS_WARN_ON  = $$QMAKE_CFLAGS_WARN_ON
 
 QMAKE_LINK              = $${CROSS_COMPILE}g++
-- 
2.41.0

