Skip to content

Instantly share code, notes, and snippets.

@2bits
Created May 18, 2012 08:36
Show Gist options
  • Save 2bits/2724019 to your computer and use it in GitHub Desktop.
Save 2bits/2724019 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 -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
@2bits
Copy link
Author

2bits commented Jun 27, 2012

When there's a sha1 mismatch, you delete the offending files out of your cache and try again. It will download everything again and most likely work.

rm /Library/Caches/Homebrew/wkhtmltopdf*
brew install --devel --build-patched-qt wkhtmltopdf

@mareczek
Copy link

I'm trying to install with patched qt on 10.8.2 with above formula and after compiling I get: Error: Failed executing: make (wkhtmltopdf.rb:100)

fatal error: error in backend: Cannot select: intrinsic %llvm.x86.mmx.femms
make[2]: *** [.obj/release-static/qdrawhelper_mmx3dnow.o] Error 1
make[2]: *** Waiting for unfinished jobs....
fatal error: error in backend: Cannot select: intrinsic %llvm.x86.mmx.femms
make[2]: *** [.obj/release-static/qdrawhelper_sse3dnow.o] Error 1
make[1]: *** [release] Error 2
make: *** [sub-gui-make_default-ordered] Error 2
==> Build Environment
HOMEBREW_VERSION: 0.9.3
HEAD: 7a494e8d4dce785df58a663b54eaa84b20436e89
CPU: quad-core 64-bit ivybridge
OS X: 10.8.2-x86_64
Xcode: 4.4.1
CLT: 4.4.0.0.1.1249367152
X11: 2.7.2 in /opt/X11
CC: cc
CXX: c++
LD: c++
CXXFLAGS: -fvisibility=hidden
MAKEFLAGS: -j4
CMAKE_PREFIX_PATH: /usr/local
CMAKE_INCLUDE_PATH: /usr/include/libxml2:/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers/
CMAKE_LIBRARY_PATH: /System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
PKG_CONFIG_PATH: /usr/local/lib/pkgconfig:/usr/local/Library/Homebrew/pkgconfig
ACLOCAL_PATH: /usr/local/share/aclocal
PATH: /usr/local/Library/ENV/4.3:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Error: Failed executing: make (wkhtmltopdf.rb:100)

I would greatly appreciate any help. :-)

@simmsy
Copy link

simmsy commented Oct 31, 2012

Hi, did you manage to get this working on 10.8.2 in the end as I am having the exact same problems. Any help appreciated, cheers.

@simmsy
Copy link

simmsy commented Oct 31, 2012

I got this working on 10.8.2, this article helped: Homebrew/legacy-homebrew#14813

If you insert the following before line 99 then it should work:

  args << '-no-3dnow'                                                                              
  args << '-no-sse'                                                                                
  args << '-no-mmx'                                                                                
  args << '-no-ssse3' 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment