Skip to content

Instantly share code, notes, and snippets.

@sirn
Forked from 2bits/wkhtmltopdf.rb
Created November 7, 2012 09:58
Show Gist options
  • Save sirn/4030545 to your computer and use it in GitHub Desktop.
Save sirn/4030545 to your computer and use it in GitHub Desktop.
wkhtmltopdf - build formula for Homebrew supporting 0.9.9, 0.11.0_rc1, and their patched Qt4
require 'formula'
class WkhtmltopdfQt < Formula
# This is the latest staging branch commit, dated 6 JAN 2012.
url 'https://qt.gitorious.org/qt/wkhtmltopdf-qt/archive-tarball/6053b687d24956d0a7eac21a015172b29cf0f451'
sha1 '3a48649a2082ced3153bd2841d1e8a94a5e74a4f'
version '6053b68'
end
class Wkhtmltopdf < Formula
url 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9.tar.bz2'
homepage 'http://code.google.com/p/wkhtmltopdf/'
sha1 '41f598c0103326e7c13101391447b0284b4ba3cb'
devel do
url 'http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1.tar.bz2'
sha1 'db03922d281856e503b3d562614e3936285728c7'
version '0.11.0_rc1'
end
depends_on 'qt' unless ARGV.include? '--build-patched-qt'
def options
[['--build-patched-qt', '(Devel only) Download and build a special patched Qt4 (~1hr)']]
end
def startup_script name
<<-EOS.undent
#!/bin/bash
exec "#{libexec}/#{name}.app/Contents/MacOS/#{name}" "$@"
EOS
end
def install
if ARGV.build_devel?
# fix that missing TEMP= include.
inreplace 'common.pri' do |s|
s.gsub! 'TEMP = $$[QT_INSTALL_LIBS] libQtGui.prl', ''
s.gsub! 'include($$join(TEMP, "/"))', ''
end
# If we are 64bit, do not compile with -arch i386 so we match Qt's arch.
if MacOS.prefer_64_bit?
inreplace 'src/pdf/pdf.pro', 'x86', 'x86_64'
inreplace 'src/image/image.pro', 'x86', 'x86_64'
end
# Let it bundle everything into an .app so that we can put qt_menu.nib
# in the Resources folder where it has to live when building patched qt.
# Otherwise the nib has to live in bin, which is not acceptable.
# The line being replaced is: 'CONFIG -= app_bundle'
inreplace 'src/pdf/pdf.pro', 'CONFIG -=', '#CONFIG -='
inreplace 'src/image/image.pro', 'CONFIG -=', '#CONFIG -='
else
# fix that missing TEMP= include and a deprecated variable
inreplace 'wkhtmltopdf.pro' do |s|
s.gsub! 'TEMP = $$[QT_INSTALL_LIBS] libQtGui.prl', ''
s.gsub! 'include($$join(TEMP, "/"))', ''
s.gsub! 'QMAKE_EXTRA_UNIX_TARGETS', 'QMAKE_EXTRA_TARGETS'
end
# Fix a typo in the 0.9.9 source. Use the correct variable name from Qt.
inreplace 'src/pageconverter.cc',
'PKK_UseCompression',
'PPK_UseCompression'
end
# build their patched qt if the user options that
if ARGV.include? '--build-patched-qt' and ARGV.build_devel?
WkhtmltopdfQt.new('wkhtmltopdfqt').brew {(buildpath+'wkhtmltopdf-qt').install Dir['*']}
cd 'wkhtmltopdf-qt' do
# Fixes build error with clang, cannot initialize return object, cf.
# http://lists.qt.nokia.com/pipermail/qt-interest/2011-September/035824.html
inreplace 'src/gui/kernel/qt_cocoa_helpers_mac_p.h',
'reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr))',
'const_cast<NSString*>(reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)))'
inreplace 'src/plugins/bearer/corewlan/qcorewlanengine.mm',
'reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr))',
'const_cast<NSString*>(reinterpret_cast<const NSString *>(QCFString::toCFStringRef(qstr)))'
ENV.append "CXXFLAGS", "-fvisibility=hidden"
ENV['QTDIR'] = buildpath+'wkhtmltopdf-qt'
ENV['LD'] = ENV['CXX']
ENV.x11
system './bin/syncqt'
args = %w[
-release -static -fast -exceptions -no-accessibility -no-stl
-no-sql-ibase -no-sql-mysql -no-sql-odbc -no-sql-psql -no-sql-sqlite
-no-sql-sqlite2 -no-qt3support -xmlpatterns -no-phonon
-no-phonon-backend -webkit -no-scripttools -system-zlib
-system-libpng -L/usr/X11/lib -I/usr/X11/include
-openssl -graphicssystem raster -opensource -nomake tools
-nomake examples -nomake demos -nomake docs -nomake translations
-no-opengl -no-dbus -no-framework -no-dwarf2 -no-multimedia
-no-declarative -largefile -rpath -no-nis -no-cups -no-iconv -no-pch
-no-gtkstyle -no-nas-sound -no-sm -no-xshape -no-xinerama -no-xfixes
-no-xrandr -no-xrender -no-mitshm -no-xkb -no-glib -no-openvg
-no-xsync -no-javascript-jit -no-egl -no-3dnow -no-sse -no-mmx
-no-ssse3 -confirm-license
--prefix=../wkqt/ -arch
]
MacOS.prefer_64_bit? ? (args << 'x86_64') : (args << 'x86')
system './configure', *args
system 'make'
system 'make install'
end
system './wkqt/bin/qmake'
else
system 'qmake', '-spec', 'macx-g++'
end
system 'make'
# The app is needed for --build-patched-qt. Use a shim script to run things.
wk2pdf_bin = 'wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf'
wk2img_bin = 'wkhtmltoimage.app/Contents/MacOS/wkhtmltoimage'
wk2pdf_man = 'wkhtmltopdf.1'
wk2img_man = 'wkhtmltoimage.1'
nib = 'wkhtmltopdf-qt/src/gui/mac/qt_menu.nib'
if ARGV.build_devel?
ENV['DYLD_LIBRARY_PATH'] = './bin'
system "bin/#{wk2pdf_bin} --manpage > #{wk2pdf_man}"
system "bin/#{wk2img_bin} --manpage > #{wk2img_man}"
d = Pathname.new "#{buildpath}/bin/wkhtmltopdf.app/Contents/Resources"
d.install nib if ARGV.include? '--build-patched-qt'
prefix.install %w(README_WKHTMLTOPDF README_WKHTMLTOIMAGE COPYING)
libexec.install Dir[ "bin/wkh*" ]
lib.install Dir[ "bin/lib*" ]
[wk2pdf_man, wk2img_man].each {|f| man1.install gzip(f)}
(bin+'wkhtmltopdf').write startup_script('wkhtmltopdf')
(bin+'wkhtmltoimage').write startup_script('wkhtmltoimage')
else
system "#{wk2pdf_bin} --manpage > #{wk2pdf_man}"
prefix.install %w(README COPYING)
libexec.install %w(wkhtmltopdf.app)
man1.install gzip(wk2pdf_man)
(bin+'wkhtmltopdf').write startup_script('wkhtmltopdf')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment