Browse Source

convert the MinGW build to shared instead of static

This makes building and distribution easier, as this is the
preferred way of building Qt.
Ashish Kulkarni 8 years ago
parent
commit
b72f31b64c
3 changed files with 44 additions and 24 deletions
  1. 1 2
      common.pri
  2. 28 21
      scripts/build.py
  3. 15 1
      wkhtmltox.nsi

+ 1 - 2
common.pri

@@ -23,8 +23,7 @@ CONFIG(static, shared|static):lessThan(QT_MAJOR_VERSION, 5) {
 INCLUDEPATH += ../../include
 INCLUDEPATH += ../../include
 RESOURCES    = $$PWD/wkhtmltopdf.qrc
 RESOURCES    = $$PWD/wkhtmltopdf.qrc
 
 
-win32:      CONFIG += console
-win32-g++*: QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++
+win32: CONFIG += console
 
 
 QT += webkit network xmlpatterns svg
 QT += webkit network xmlpatterns svg
 greaterThan(QT_MAJOR_VERSION, 4) {
 greaterThan(QT_MAJOR_VERSION, 4) {

+ 28 - 21
scripts/build.py

@@ -139,6 +139,8 @@ QT_CONFIG = {
     ],
     ],
 
 
     'mingw-w64-cross' : [
     'mingw-w64-cross' : [
+        'remove:-static',
+        '-shared',
         '-silent',                  # perform a silent build
         '-silent',                  # perform a silent build
         '-openssl-linked',          # static linkage for OpenSSL
         '-openssl-linked',          # static linkage for OpenSSL
         '-no-reduce-exports',
         '-no-reduce-exports',
@@ -203,7 +205,7 @@ DEPENDENT_LIBS = {
             'mingw-w64-cross-win*': {
             'mingw-w64-cross-win*': {
                 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
                 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
                 'commands': [
                 'commands': [
-                    'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw_w64)s- no-shared no-asm mingw64',
+                    'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw_w64)s- shared no-asm mingw64',
                     'make',
                     'make',
                     'make install_sw']
                     'make install_sw']
             }
             }
@@ -226,9 +228,10 @@ DEPENDENT_LIBS = {
             },
             },
             'mingw-w64-cross-win*': {
             'mingw-w64-cross-win*': {
                 'result': {
                 'result': {
+                    'bin/zlib1.dll'  : 'zlib1.dll',
                     'include/zlib.h' : 'zlib.h',
                     'include/zlib.h' : 'zlib.h',
                     'include/zconf.h': 'zconf.h',
                     'include/zconf.h': 'zconf.h',
-                    'lib/libz.a'     : 'libz.a'
+                    'lib/libz.dll.a' : 'libz.dll.a'
                 },
                 },
                 'replace':  [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw_w64)s-')],
                 'replace':  [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw_w64)s-')],
                 'commands': ['make -f win32/Makefile.gcc']
                 'commands': ['make -f win32/Makefile.gcc']
@@ -255,19 +258,10 @@ DEPENDENT_LIBS = {
                 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
                 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
             },
             },
             'mingw-w64-cross-win*': {
             'mingw-w64-cross-win*': {
-                'result': {
-                    'include/png.h'       : 'png.h',
-                    'include/pngconf.h'   : 'pngconf.h',
-                    'include/pnglibconf.h': 'pnglibconf.h',
-                    'lib/libpng.a'        : 'libpng.a'
-                },
-                'replace': [
-                    ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
-                    ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
-                    ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw_w64)s-gcc'),
-                    ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw_w64)s-ar'),
-                    ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw_w64)s-ranlib')],
-                'commands': ['make -f scripts/makefile.gcc libpng.a']
+                'result': ['include/png.h', 'include/pngconf.h',  'include/pnglibconf.h',
+                           'lib/libpng.dll.a', 'bin/libpng16-16.dll'],
+                'commands': ['%(destenv)s ./configure --host=%(mingw_w64)s --disable-static --enable-shared --prefix=%(destdir)s',
+                             'make install']
             },
             },
             'osx-carbon-i386': {
             'osx-carbon-i386': {
                 'result': ['include/png.h', 'include/pngconf.h', 'lib/libpng.a'],
                 'result': ['include/png.h', 'include/pngconf.h', 'lib/libpng.a'],
@@ -311,9 +305,9 @@ DEPENDENT_LIBS = {
                     'nmake /f makefile.vc libjpeg.lib']
                     'nmake /f makefile.vc libjpeg.lib']
             },
             },
             'mingw-w64-cross-win*': {
             'mingw-w64-cross-win*': {
-                'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
+                'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.dll.a', 'bin/libjpeg-9.dll'],
                 'commands': [
                 'commands': [
-                    './configure --host=%(mingw_w64)s --disable-shared --prefix=%(destdir)s',
+                    '%(destenv)s ./configure --host=%(mingw_w64)s --disable-static --enable-shared --prefix=%(destdir)s',
                     'make install']
                     'make install']
             },
             },
             'osx-carbon-i386': {
             'osx-carbon-i386': {
@@ -384,7 +378,7 @@ EXCLUDE_SRC_TARBALL = [
 
 
 # --------------------------------------------------------------- HELPERS
 # --------------------------------------------------------------- HELPERS
 
 
-import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
+import os, sys, platform, subprocess, shutil, re, fnmatch, glob, multiprocessing, urllib, hashlib, tarfile
 
 
 from os.path import exists
 from os.path import exists
 
 
@@ -534,7 +528,8 @@ def build_deplibs(config, basedir, **kwargs):
     mkdir_p(os.path.join(basedir, config))
     mkdir_p(os.path.join(basedir, config))
 
 
     dstdir = os.path.join(basedir, config, 'deplibs')
     dstdir = os.path.join(basedir, config, 'deplibs')
-    vars   = {'destdir': dstdir }
+    vars   = {'destdir': dstdir,
+              'destenv': 'CPPFLAGS="-I%s/include" LDFLAGS="-L%s/lib"' % (dstdir, dstdir) }
     vars.update(kwargs)
     vars.update(kwargs)
     for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
     for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
         cfg = None
         cfg = None
@@ -844,10 +839,10 @@ def build_mingw64_cross(config, basedir):
     configure_args = qt_config('mingw-w64-cross',
     configure_args = qt_config('mingw-w64-cross',
         '--prefix=%s'   % qtdir,
         '--prefix=%s'   % qtdir,
         '-I%s/include'  % libdir,
         '-I%s/include'  % libdir,
-        '-L%s/lib'      % libdir,
         '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
         '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
 
 
-    os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L%s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
+    os.environ['LDFLAGS'] = '-lwinmm -L%s/lib' % libdir
+    os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L%s/lib -lws2_32 -lgdi32 -lcrypt32 -lwinmm' % libdir
 
 
     mkdir_p(qtdir)
     mkdir_p(qtdir)
     os.chdir(qtdir)
     os.chdir(qtdir)
@@ -866,6 +861,18 @@ def build_mingw64_cross(config, basedir):
     shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
     shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
     shell('make')
     shell('make')
     shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
     shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
+    shell('rm -fr bin-dep && mkdir bin-dep')
+    for dll in ['libgcc_s_sjlj-1.dll', 'libgcc_s_seh-1.dll', 'libstdc++-6.dll']:
+        dll_path = get_output('dpkg', '-S', dll)
+        if dll_path:
+            for line in dll_path.split('\n'):
+                loc = line[1+line.index(':'):].strip()
+                if exists(loc) and MINGW_W64_PREFIX[rchop(config, '-dbg')] in loc and '-posix' not in loc:
+                    shell('cp %s bin-dep/' % loc)
+    for module in ['Core', 'Gui', 'Network', 'Svg', 'WebKit', 'XmlPatterns']:
+        shell('cp %s/bin/Qt%s4.dll bin-dep/' % (qtdir, module))
+    for loc in glob.glob('%s/bin/*.dll' % libdir):
+        shell('cp %s bin-dep/' % loc)
 
 
     if config.endswith('-dbg'):
     if config.endswith('-dbg'):
         return
         return

+ 15 - 1
wkhtmltox.nsi

@@ -36,11 +36,22 @@ Function ${un}DeleteFiles
   Delete "$INSTDIR\libeay32.dll"
   Delete "$INSTDIR\libeay32.dll"
   Delete "$INSTDIR\wkhtmltopdf.exe"
   Delete "$INSTDIR\wkhtmltopdf.exe"
   Delete "$INSTDIR\wkhtmltoimage.exe"
   Delete "$INSTDIR\wkhtmltoimage.exe"
+; remove as per current installer layout
   Delete "$INSTDIR\bin\libgcc_s_sjlj-1.dll"
   Delete "$INSTDIR\bin\libgcc_s_sjlj-1.dll"
   Delete "$INSTDIR\bin\libgcc_s_seh-1.dll"
   Delete "$INSTDIR\bin\libgcc_s_seh-1.dll"
   Delete "$INSTDIR\bin\libstdc++-6.dll"
   Delete "$INSTDIR\bin\libstdc++-6.dll"
   Delete "$INSTDIR\bin\libwinpthread-1.dll"
   Delete "$INSTDIR\bin\libwinpthread-1.dll"
-; remove as per current installer layout
+  Delete "$INSTDIR\bin\ssleay32.dll"
+  Delete "$INSTDIR\bin\libeay32.dll"
+  Delete "$INSTDIR\bin\zlib1.dll"
+  Delete "$INSTDIR\bin\libpng16-16.dll"
+  Delete "$INSTDIR\bin\libjpeg-9.dll"
+  Delete "$INSTDIR\bin\QtCore4.dll"
+  Delete "$INSTDIR\bin\QtGui4.dll"
+  Delete "$INSTDIR\bin\QtNetwork4.dll"
+  Delete "$INSTDIR\bin\QtSvg4.dll"
+  Delete "$INSTDIR\bin\QtWebKit4.dll"
+  Delete "$INSTDIR\bin\QtXmlPatterns4.dll"
   Delete "$INSTDIR\bin\wkhtmltoimage.exe"
   Delete "$INSTDIR\bin\wkhtmltoimage.exe"
   Delete "$INSTDIR\bin\wkhtmltopdf.exe"
   Delete "$INSTDIR\bin\wkhtmltopdf.exe"
   Delete "$INSTDIR\bin\wkhtmltox.dll"
   Delete "$INSTDIR\bin\wkhtmltox.dll"
@@ -87,6 +98,9 @@ skip_vcruntime:
   File static-build\${TARGET}\app\bin\wkhtmltoimage.exe
   File static-build\${TARGET}\app\bin\wkhtmltoimage.exe
   File static-build\${TARGET}\app\bin\wkhtmltopdf.exe
   File static-build\${TARGET}\app\bin\wkhtmltopdf.exe
   File static-build\${TARGET}\app\bin\wkhtmltox.dll
   File static-build\${TARGET}\app\bin\wkhtmltox.dll
+!ifdef MINGW
+  File static-build\${TARGET}\app\bin-dep\*.dll
+!endif
 
 
   SetOutPath "$INSTDIR\lib"
   SetOutPath "$INSTDIR\lib"
   File static-build\${TARGET}\app\bin\wkhtmltox.lib
   File static-build\${TARGET}\app\bin\wkhtmltox.lib