浏览代码

add support for OS X in the build script

This was based on suggestions/feedback by @mn4367 and @npinchot
and fixes #1545
Ashish Kulkarni 11 年之前
父节点
当前提交
7fac78cd81
共有 4 个文件被更改,包括 110 次插入4 次删除
  1. 1 0
      AUTHORS
  2. 2 1
      CHANGELOG.md
  3. 22 2
      INSTALL.md
  4. 85 1
      scripts/build.py

+ 1 - 0
AUTHORS

@@ -29,6 +29,7 @@ Benoit Garret       <benoit.garret@gmail.com>
 Adam Thorsen        <adam.thorsen@gmail.com>
 Adam Thorsen        <adam.thorsen@gmail.com>
 Emmanuel Bouthenot  <kolter@openics.org>
 Emmanuel Bouthenot  <kolter@openics.org>
 Artem Butusov       <art.sormy@gmail.com>
 Artem Butusov       <art.sormy@gmail.com>
+Michael Nitze       <michael.nitze@online.de>
 rainabba
 rainabba
 Mehdi Abbad
 Mehdi Abbad
 Lyes Amazouz
 Lyes Amazouz

+ 2 - 1
CHANGELOG.md

@@ -8,6 +8,7 @@ v0.12.1 (unreleased)
 * **#1509**: fix TOC support which was broken after upgrade to latest Qt
 * **#1509**: fix TOC support which was broken after upgrade to latest Qt
 * **#1512**: **[qt]** fix crashes when rendering JPEG images on Windows Server 2008 x64
 * **#1512**: **[qt]** fix crashes when rendering JPEG images on Windows Server 2008 x64
 * **#1544**: use UTF-8 encoding for the HTML generated by the TOC XSL
 * **#1544**: use UTF-8 encoding for the HTML generated by the TOC XSL
+* **#1545**: PDFs rendering without embedded fonts on OS X
 * **#1546**: fix problem with non-ASCII characters in output path on Windows
 * **#1546**: fix problem with non-ASCII characters in output path on Windows
 * **#1585**: delete existing files explicitly in windows installer
 * **#1585**: delete existing files explicitly in windows installer
 * **#1586**: **[qt]** suppress blank page generated if the first cell spans multiple pages
 * **#1586**: **[qt]** suppress blank page generated if the first cell spans multiple pages
@@ -19,7 +20,7 @@ v0.12.1 (unreleased)
 * update URLs in the internal documentation
 * update URLs in the internal documentation
 * generate API documentation for libwkhtmltox (on the website)
 * generate API documentation for libwkhtmltox (on the website)
 * display version in compiled binary properly under various scenarios
 * display version in compiled binary properly under various scenarios
-* complete revamp of the build system, which supports only Windows and Linux for now.
+* complete revamp of the build system
 
 
 v0.12.0 (2014-02-06)
 v0.12.0 (2014-02-06)
 --------------------
 --------------------

+ 22 - 2
INSTALL.md

@@ -43,13 +43,33 @@ Prerequisites: Windows
 * Make sure that you can run "git". If not, add it to the PATH or reinstall
 * Make sure that you can run "git". If not, add it to the PATH or reinstall
   with option "Run Git from the Windows Command Prompt".
   with option "Run Git from the Windows Command Prompt".
 
 
+Prerequisites: OS X
+-------------------
+
+Building is supported for 32-bit Carbon on OS X 10.6 or newer, and for
+64-bit Cocoa on OS X 10.7 or newer. You will need to have the following
+installed:
+
+* The latest Xcode for your OS X version
+* [xz 5.0.5](http://downloads.sourceforge.net/project/macpkg/XZ/5.0.5/XZ.pkg)
+* If you are using OS X 10.6, you will need to install [git 1.8.4.2](https://git-osx-installer.googlecode.com/files/git-1.8.4.2-intel-universal-snow-leopard.dmg)
+  and [Python 2.7.6](https://www.python.org/ftp/python/2.7.6/python-2.7.6-macosx10.6.dmg).
+  After installing, you should run the `Update Shell Profile.command`
+  in `/Applications/Python 2.7` to make it the default Python in the shell.
+
+The Carbon build is recommended because it generates PDFs with smaller
+file sizes and selectable text as compared to the Cocoa version, see
+[QTBUG-10094](https://bugreports.qt-project.org/browse/QTBUG-10094).
+You will need to have the OS X 10.6 SDK installed for the Carbon build,
+which is not available in later versions of OS X.
+
 Building
 Building
 --------
 --------
 
 
 * Ensure that you are using the correct Qt version by running ```git submodule update```
 * Ensure that you are using the correct Qt version by running ```git submodule update```
 * Run the command ```scripts/build.py``` (or ```scripts\build.py``` if you
 * Run the command ```scripts/build.py``` (or ```scripts\build.py``` if you
-  are on Windows) to get a list of all targets which can be built. If you
-  want to compile on a distribution not listed above or for another
+  are on Windows) to get a list of all targets which can be built.
+* If you want to compile on a distribution not listed above or for another
   Unix-like OS, please use the ```posix-local``` target -- it assumes
   Unix-like OS, please use the ```posix-local``` target -- it assumes
   that you have already installed all build dependencies beforehand.
   that you have already installed all build dependencies beforehand.
 * If you want to customize the default Qt configuration options for your
 * If you want to customize the default Qt configuration options for your

+ 85 - 1
scripts/build.py

@@ -150,6 +150,15 @@ QT_CONFIG = {
         '-no-reduce-exports',
         '-no-reduce-exports',
         '-no-rpath',
         '-no-rpath',
         '-xplatform win32-g++-4.6'
         '-xplatform win32-g++-4.6'
+    ],
+
+    'osx': [
+        '-no-framework',
+        '-no-dwarf2',
+        '-xrender',                 # xrender support is required
+        '-openssl',                 # load OpenSSL binaries at runtime
+        '-largefile',
+        '-rpath'
     ]
     ]
 }
 }
 
 
@@ -183,7 +192,9 @@ BUILDERS = {
     'precise-amd64':         'linux_schroot',
     'precise-amd64':         'linux_schroot',
     'mingw-w64-cross-win32': 'mingw64_cross',
     'mingw-w64-cross-win32': 'mingw64_cross',
     'mingw-w64-cross-win64': 'mingw64_cross',
     'mingw-w64-cross-win64': 'mingw64_cross',
-    'posix-local':           'posix_local'
+    'posix-local':           'posix_local',
+    'osx-cocoa-x86-64':      'osx',
+    'osx-carbon-i386':       'osx'
 }
 }
 
 
 CHROOT_SETUP  = {
 CHROOT_SETUP  = {
@@ -741,6 +752,79 @@ def build_posix_local(config, basedir):
     shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
     shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
     shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
     shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
 
 
+# --------------------------------------------------------------- OS X
+
+OSX_CONFIG = {
+    'osx-10.6-carbon-i386':  '-carbon  -platform macx-g++42',
+    'osx-10.7-carbon-i386':  '-carbon  -platform unsupported/macx-clang -reduce-exports',
+    'osx-10.8-carbon-i386':  '-carbon  -platform unsupported/macx-clang -reduce-exports',
+    'osx-10.9-carbon-i386':  '-carbon  -platform unsupported/macx-clang -reduce-exports',
+    'osx-10.7-cocoa-x86-64': '-cocoa   -platform unsupported/macx-clang',
+    'osx-10.8-cocoa-x86-64': '-cocoa   -platform unsupported/macx-clang',
+    'osx-10.9-cocoa-x86-64': '-cocoa   -platform unsupported/macx-clang-libc++'
+}
+
+def check_osx(config):
+    if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
+        error('This can only be run on a OS X system!')
+
+    osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
+    osxcfg = config.replace('osx-', 'osx-%s-' % osxver)
+    if not osxcfg in OSX_CONFIG:
+        error('This target is not supported: %s' % osxcfg)
+    if 'carbon' in osxcfg and osxver != '10.6':
+        sdk_dir = get_output('xcodebuild', '-sdk', 'macosx10.6', '-version', 'Path')
+        if not sdk_dir:
+            error('Unable to find OS X 10.6 SDK for the carbon build, aborting.')
+        if not os.path.isfile('%s/usr/lib/libstdc++.dylib' % sdk_dir):
+            error('Symlink for libstdc++.dylib has not been created, aborting.')
+
+def build_osx(config, basedir):
+    version, simple_version = get_version(basedir)
+
+    osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
+    osxcfg = config.replace('osx-', 'osx-%s-' % osxver)
+    args   = OSX_CONFIG[osxcfg]
+    flags  = ''
+
+    if 'carbon' in osxcfg and osxver != '10.6':
+        args += ' -sdk %s' % get_output('xcodebuild', '-sdk', 'macosx10.6', '-version', 'Path')
+        for item in ['CFLAGS', 'CXXFLAGS']:
+            flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
+
+    qt     = os.path.join(basedir, config, 'qt')
+    app    = os.path.join(basedir, config, 'app')
+    dist   = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
+
+    mkdir_p(qt)
+    mkdir_p(app)
+
+    rmdir(dist)
+    mkdir_p(os.path.join(dist, 'bin'))
+    mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
+    mkdir_p(os.path.join(dist, 'lib'))
+
+    os.chdir(qt)
+    if not exists('is_configured'):
+        shell('../../../qt/configure %s' % qt_config('osx', '--prefix=%s' % qt, args))
+        shell('touch is_configured')
+
+    shell('make -j%d' % CPU_COUNT)
+
+    os.chdir(app)
+    shell('rm -f bin/*')
+    os.environ['WKHTMLTOX_VERSION'] = version
+    shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
+    shell('make -j%d' % CPU_COUNT)
+    shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
+    shell('cp -P bin/libwkhtmltox*.dylib* ../wkhtmltox-%s/lib' % version)
+    shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
+    shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
+
+    os.chdir(os.path.join(basedir, config))
+    shell('tar -c -v -f ../wkhtmltox-%s_%s.tar wkhtmltox-%s/' % (version, osxcfg, version))
+    shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_%s.tar' % (version, osxcfg))
+
 # --------------------------------------------------------------- command line
 # --------------------------------------------------------------- command line
 
 
 def usage(exit_code=2):
 def usage(exit_code=2):