瀏覽代碼

generate native PKG for OS X using "fpm"

On OS X, packages are very limited and do not have the functionality that is
provided by package managers on Linux/BSD systems -- installation is supported,
but no uninstallation. Also, the compression support for packages is very poor
-- a 92MiB package is generated instead of a 14MiB tarball compressed using xz.

Thus, we use a very ugly hack to get the package down to a reasonable size. We
actually create a compressed tarball using xz (as before) and include a after-
install script which decompresses this tarball into /usr/local. To support the
scenario where the end-user might not have xz installed on the machine, a copy
of unxz is also bundled in the package.
Ashish Kulkarni 11 年之前
父節點
當前提交
c67fbc765c
共有 2 個文件被更改,包括 67 次插入22 次删除
  1. 7 5
      INSTALL.md
  2. 60 17
      scripts/build.py

+ 7 - 5
INSTALL.md

@@ -106,11 +106,13 @@ OS X
 Building is supported only on OS X 10.6 or newer. You will need to have the
 the latest Xcode for your OS X version and also install
 [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.
+Additionally, you will need the command `sudo gem install fpm --no-ri --no-rdoc`
+in the terminal to install [fpm](https://github.com/jordansissel/fpm), which is
+used for building the package. Note that if you are using OS X 10.6, you will
+additionally 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)
+(you may need to 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

+ 60 - 17
scripts/build.py

@@ -220,6 +220,13 @@ FPM_SETUP = {
         '--rpm-compression': 'bzip2',
         '--depends':         ['fontconfig', 'freetype', 'libpng', 'zlib', 'libjpeg', 'openssl',
                               'libX11', 'libXext', 'libXrender', 'libstdc++', 'glibc']
+    },
+    'osx': {
+        '-t':                         'osxpkg',
+        '-C':                         'pkg',
+        '--prefix':                   '/usr/local/share/installer/wkhtmltox',
+        '--osxpkg-identifier-prefix': 'org.wkhtmltopdf',
+        '--after-install':            'extract.sh'
     }
 }
 
@@ -1045,6 +1052,9 @@ def check_osx(config):
     if not get_output('xcode-select', '--print-path'):
         error('Xcode is not installed, aborting.')
 
+    if not get_output('which', 'fpm'):
+        error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
+
 def build_osx(config, basedir):
     version, simple_version = get_version(basedir)
     build_deplibs(config, basedir)
@@ -1061,28 +1071,28 @@ def build_osx(config, basedir):
         for item in ['CFLAGS', 'CXXFLAGS']:
             flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
 
-    qt     = os.path.join(basedir, config, 'qt')
-    libs   = os.path.join(basedir, config, 'deplibs')
-    app    = os.path.join(basedir, config, 'app')
-    dist   = os.path.join(basedir, config, 'dist')
+    def get_dir(name):
+        return os.path.join(basedir, config, name)
 
     configure_args = qt_config('osx', osxcfg,
-        '--prefix=%s' % qt,
-        '-I %s/include' % libs,
-        '-L %s/lib' % libs)
+        '--prefix=%s'   % get_dir('qt'),
+        '-I %s/include' % get_dir('deplibs'),
+        '-L %s/lib'     % get_dir('deplibs'))
 
-    mkdir_p(qt)
-    mkdir_p(app)
-    rmdir(dist)
+    rmdir(get_dir('dist'))
+    rmdir(get_dir('pkg'))
+    mkdir_p(get_dir('qt'))
+    mkdir_p(get_dir('app'))
+    mkdir_p(get_dir('pkg'))
 
-    os.chdir(qt)
+    os.chdir(get_dir('qt'))
     if not exists('is_configured'):
         shell('../../../qt/configure %s' % configure_args)
         shell('touch is_configured')
 
     shell('make -j%d' % CPU_COUNT)
 
-    os.chdir(app)
+    os.chdir(get_dir('app'))
     shell('rm -f bin/*')
     os.environ['WKHTMLTOX_VERSION'] = version
     shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
@@ -1096,11 +1106,44 @@ def build_osx(config, basedir):
                 '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
                 'bin/'+item]))
 
-    shell('make install INSTALL_ROOT=%s' % dist)
-
-    os.chdir(dist)
-    shell('tar -c -v -f ../../wkhtmltox-%s_%s.tar .' % (version, config))
-    shell('xz --compress --force --verbose -9 ../../wkhtmltox-%s_%s.tar' % (version, config))
+    shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
+
+    def _osx_tar(info):
+        info.uid   = info.gid   = 0
+        info.uname = 'root'
+        info.gname = 'wheel'
+        return info
+
+    # create tarballs for application and unxz
+    os.chdir(get_dir('dist'))
+    with tarfile.open('../pkg/app.tar', 'w') as tar:
+        tar.add('.', './', filter=_osx_tar)
+    shell('xz --compress --force --verbose -9 ../pkg/app.tar')
+
+    with tarfile.open('../pkg/unxz.tar.gz', 'w:gz') as tar:
+        unxz = get_output('which', 'unxz')
+        lzma = os.path.join(os.path.dirname(unxz), '..', 'lib', 'liblzma.5.dylib')
+        tar.add(unxz, './bin/unxz', filter=_osx_tar)
+        tar.add(lzma, './lib/liblzma.5.dylib', filter=_osx_tar)
+
+    args, cfg = fpm_setup('osx')
+    open('../extract.sh', 'w').write("""#!/bin/bash
+TGTDIR=/usr/local
+BASEDIR=%s
+if [ -x $TGTDIR/bin/unxz ]
+  then
+    cd $TGTDIR;
+    tar zxf $BASEDIR/unxz.tar.gz
+fi
+cd $BASEDIR
+$TGTDIR/bin/unxz -k $BASEDIR/app.tar.xz
+cd $TGTDIR
+tar xf $BASEDIR/app.tar
+rm -f $BASEDIR/app.tar
+""" % cfg['--prefix'])
+
+    os.chdir(os.path.join(basedir, config))
+    shell('fpm --force %s --package ../%s-%s_%s.pkg .' % (args.replace('$1', version), cfg['--name'], version, config))
 
 # --------------------------------------------------------------- command line