build.py 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  1. #!/usr/bin/env python
  2. #
  3. # Copyright 2014 wkhtmltopdf authors
  4. #
  5. # This file is part of wkhtmltopdf.
  6. #
  7. # wkhtmltopdf is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # wkhtmltopdf is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Lesser General Public License
  18. # along with wkhtmltopdf. If not, see <http:#www.gnu.org/licenses/>.
  19. # --------------------------------------------------------------- CONFIGURATION
  20. BUILDERS = {
  21. 'source-tarball': 'source_tarball',
  22. 'msvc2008-win32': 'msvc',
  23. 'msvc2008-win64': 'msvc',
  24. 'msvc2010-win32': 'msvc',
  25. 'msvc2010-win64': 'msvc',
  26. 'msvc2012-win32': 'msvc',
  27. 'msvc2012-win64': 'msvc',
  28. 'msvc2013-win32': 'msvc',
  29. 'msvc2013-win64': 'msvc',
  30. 'msvc-winsdk71-win32': 'msvc_winsdk71',
  31. 'msvc-winsdk71-win64': 'msvc_winsdk71',
  32. 'setup-mingw-w64': 'setup_mingw64',
  33. 'setup-schroot-centos5': 'setup_schroot',
  34. 'setup-schroot-centos6': 'setup_schroot',
  35. 'setup-schroot-wheezy': 'setup_schroot',
  36. 'setup-schroot-trusty': 'setup_schroot',
  37. 'setup-schroot-precise': 'setup_schroot',
  38. 'update-all-schroots': 'update_schroot',
  39. 'centos5-i386': 'linux_schroot',
  40. 'centos5-amd64': 'linux_schroot',
  41. 'centos6-i386': 'linux_schroot',
  42. 'centos6-amd64': 'linux_schroot',
  43. 'wheezy-i386': 'linux_schroot',
  44. 'wheezy-amd64': 'linux_schroot',
  45. 'trusty-i386': 'linux_schroot',
  46. 'trusty-amd64': 'linux_schroot',
  47. 'precise-i386': 'linux_schroot',
  48. 'precise-amd64': 'linux_schroot',
  49. 'mingw-w64-cross-win32': 'mingw64_cross',
  50. 'mingw-w64-cross-win64': 'mingw64_cross',
  51. 'posix-local': 'posix_local',
  52. 'osx-cocoa-x86-64': 'osx',
  53. 'osx-carbon-i386': 'osx'
  54. }
  55. QT_CONFIG = {
  56. 'common' : [
  57. '-opensource',
  58. '-confirm-license',
  59. '-fast',
  60. '-release',
  61. '-static',
  62. '-graphicssystem raster',
  63. '-webkit',
  64. '-exceptions', # required by XmlPatterns
  65. '-xmlpatterns', # required for TOC support
  66. '-system-zlib',
  67. '-system-libpng',
  68. '-system-libjpeg',
  69. '-no-libmng',
  70. '-no-libtiff',
  71. '-no-accessibility',
  72. '-no-stl',
  73. '-no-qt3support',
  74. '-no-phonon',
  75. '-no-phonon-backend',
  76. '-no-opengl',
  77. '-no-declarative',
  78. '-no-script',
  79. '-no-scripttools',
  80. '-no-sql-ibase',
  81. '-no-sql-mysql',
  82. '-no-sql-odbc',
  83. '-no-sql-psql',
  84. '-no-sql-sqlite',
  85. '-no-sql-sqlite2',
  86. '-no-mmx',
  87. '-no-3dnow',
  88. '-no-sse',
  89. '-no-sse2',
  90. '-no-multimedia',
  91. '-nomake demos',
  92. '-nomake docs',
  93. '-nomake examples',
  94. '-nomake tools',
  95. '-nomake tests',
  96. '-nomake translations'
  97. ],
  98. 'msvc': [
  99. '-mp',
  100. '-qt-style-windows',
  101. '-qt-style-cleanlooks',
  102. '-no-style-windowsxp',
  103. '-no-style-windowsvista',
  104. '-no-style-plastique',
  105. '-no-style-motif',
  106. '-no-style-cde',
  107. '-openssl-linked' # static linkage for OpenSSL
  108. ],
  109. 'posix': [
  110. '-silent', # perform a silent build
  111. '-xrender', # xrender support is required
  112. '-largefile',
  113. '-iconv', # iconv support is required for text codecs
  114. '-openssl', # load OpenSSL binaries at runtime
  115. '-no-rpath',
  116. '-no-dbus',
  117. '-no-nis',
  118. '-no-cups',
  119. '-no-pch',
  120. '-no-gtkstyle',
  121. '-no-nas-sound',
  122. '-no-sm',
  123. '-no-xshape',
  124. '-no-xinerama',
  125. '-no-xcursor',
  126. '-no-xfixes',
  127. '-no-xrandr',
  128. '-no-mitshm',
  129. '-no-xinput',
  130. '-no-xkb',
  131. '-no-glib',
  132. '-no-gstreamer',
  133. '-D ENABLE_VIDEO=0', # required as otherwise gstreamer gets linked in
  134. '-no-openvg',
  135. '-no-xsync',
  136. '-no-audio-backend',
  137. '-no-sse3',
  138. '-no-ssse3',
  139. '-no-sse4.1',
  140. '-no-sse4.2',
  141. '-no-avx',
  142. '-no-neon'
  143. ],
  144. 'mingw-w64-cross' : [
  145. '-silent', # perform a silent build
  146. '-openssl-linked', # static linkage for OpenSSL
  147. '-no-reduce-exports',
  148. '-no-rpath',
  149. '-xplatform win32-g++-4.6'
  150. ],
  151. 'osx': [
  152. '-silent', # perform a silent build
  153. '-no-framework',
  154. '-no-dwarf2',
  155. '-xrender', # xrender support is required
  156. '-openssl', # load OpenSSL binaries at runtime
  157. '-largefile',
  158. '-no-rpath'
  159. ]
  160. }
  161. FPM_SETUP = {
  162. 'common': {
  163. '--name': 'wkhtmltox',
  164. '--description': 'convert HTML to PDF and various image formats using QtWebkit',
  165. '--version': '$1',
  166. '--license': 'LGPLv3',
  167. '--vendor': 'wkhtmltopdf.org',
  168. '--url': 'http://wkhtmltopdf.org',
  169. '--maintainer': 'Ashish Kulkarni <kulkarni.ashish@gmail.com>',
  170. '-s': 'dir',
  171. '-C': 'dist',
  172. '--prefix': '/usr/local',
  173. '--category': 'utils'
  174. },
  175. 'wheezy': {
  176. '-t': 'deb',
  177. '--deb-compression': 'xz',
  178. '--provides': 'wkhtmltopdf',
  179. '--conflicts': 'wkhtmltopdf',
  180. '--replaces': 'wkhtmltopdf',
  181. '--depends': ['fontconfig', 'libfontconfig1', 'libfreetype6', 'libpng12-0', 'zlib1g', 'libjpeg8',
  182. 'libssl1.0.0', 'libx11-6', 'libxext6', 'libxrender1', 'libstdc++6', 'libc6']
  183. },
  184. 'trusty': {
  185. '-t': 'deb',
  186. '--deb-compression': 'xz',
  187. '--provides': 'wkhtmltopdf',
  188. '--conflicts': 'wkhtmltopdf',
  189. '--replaces': 'wkhtmltopdf',
  190. '--depends': ['fontconfig', 'libfontconfig1', 'libfreetype6', 'libpng12-0', 'zlib1g', 'libjpeg-turbo8',
  191. 'libssl1.0.0', 'libx11-6', 'libxext6', 'libxrender1', 'libstdc++6', 'libc6']
  192. },
  193. 'precise': {
  194. '-t': 'deb',
  195. '--deb-compression': 'xz',
  196. '--provides': 'wkhtmltopdf',
  197. '--conflicts': 'wkhtmltopdf',
  198. '--replaces': 'wkhtmltopdf',
  199. '--depends': ['fontconfig', 'libfontconfig1', 'libfreetype6', 'libpng12-0', 'zlib1g', 'libjpeg8',
  200. 'libssl1.0.0', 'libx11-6', 'libxext6', 'libxrender1', 'libstdc++6', 'libc6']
  201. },
  202. 'centos5': {
  203. '-t': 'rpm',
  204. '--epoch': '1',
  205. '--rpm-compression': 'bzip2',
  206. '--depends': ['fontconfig', 'freetype', 'libpng', 'zlib', 'libjpeg', 'openssl',
  207. 'libX11', 'libXext', 'libXrender', 'libstdc++', 'glibc']
  208. },
  209. 'centos6': {
  210. '-t': 'rpm',
  211. '--epoch': '1',
  212. '--rpm-compression': 'bzip2',
  213. '--depends': ['fontconfig', 'freetype', 'libpng', 'zlib', 'libjpeg', 'openssl',
  214. 'libX11', 'libXext', 'libXrender', 'libstdc++', 'glibc']
  215. },
  216. 'osx': {
  217. '-t': 'osxpkg',
  218. '-C': 'pkg',
  219. '--prefix': '/usr/local/share/installer/wkhtmltox',
  220. '--osxpkg-identifier-prefix': 'org.wkhtmltopdf',
  221. '--after-install': 'extract.sh'
  222. }
  223. }
  224. CHROOT_SETUP = {
  225. 'wheezy': [
  226. ('debootstrap', 'wheezy', 'http://ftp.us.debian.org/debian/'),
  227. ('write_file', 'etc/apt/sources.list', """
  228. deb http://ftp.debian.org/debian/ wheezy main contrib non-free
  229. deb http://ftp.debian.org/debian/ wheezy-updates main contrib non-free
  230. deb http://security.debian.org/ wheezy/updates main contrib non-free"""),
  231. ('shell', 'apt-get update'),
  232. ('shell', 'apt-get dist-upgrade --assume-yes'),
  233. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  234. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  235. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  236. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  237. ('fpm_setup', 'fpm_package.sh'),
  238. ('schroot_conf', 'Debian Wheezy')
  239. ],
  240. 'trusty': [
  241. ('debootstrap', 'trusty', 'http://archive.ubuntu.com/ubuntu/'),
  242. ('write_file', 'etc/apt/sources.list', """
  243. deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
  244. deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
  245. deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse"""),
  246. ('shell', 'apt-get update'),
  247. ('shell', 'apt-get dist-upgrade --assume-yes'),
  248. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg-turbo8-dev zlib1g-dev ruby-dev'),
  249. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  250. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  251. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  252. ('fpm_setup', 'fpm_package.sh'),
  253. ('schroot_conf', 'Ubuntu Trusty')
  254. ],
  255. 'precise': [
  256. ('debootstrap', 'precise', 'http://archive.ubuntu.com/ubuntu/'),
  257. ('write_file', 'etc/apt/sources.list', """
  258. deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
  259. deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
  260. deb http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse"""),
  261. ('shell', 'apt-get update'),
  262. ('shell', 'apt-get dist-upgrade --assume-yes'),
  263. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  264. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  265. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  266. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  267. ('fpm_setup', 'fpm_package.sh'),
  268. ('schroot_conf', 'Ubuntu Precise')
  269. ],
  270. 'centos5': [
  271. ('rinse', 'centos-5'),
  272. ('download_file', 'http://centos.karan.org/el5/ruby187/kbs-el5-ruby187.repo', 'etc/yum.repos.d'),
  273. ('download_file', 'http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm', 'tmp'),
  274. ('shell', 'rpm -i /tmp/epel-release-5-4.noarch.rpm'),
  275. ('shell', 'yum update -y'),
  276. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  277. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl ruby-devel rubygems rpm-build libffi-devel'),
  278. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  279. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  280. ('write_file', 'update.sh', 'yum update -y\n'),
  281. ('fpm_setup', 'fpm_package.sh'),
  282. ('schroot_conf', 'CentOS 5')
  283. ],
  284. 'centos6': [
  285. ('rinse', 'centos-6'),
  286. ('shell', 'yum update -y'),
  287. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  288. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl ruby-devel rubygems rpm-build libffi-devel'),
  289. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  290. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  291. ('write_file', 'update.sh', 'yum update -y\n'),
  292. ('fpm_setup', 'fpm_package.sh'),
  293. ('schroot_conf', 'CentOS 6')
  294. ]
  295. }
  296. DEPENDENT_LIBS = {
  297. 'openssl': {
  298. 'order' : 1,
  299. 'url' : 'http://www.openssl.org/source/openssl-1.0.1h.tar.gz',
  300. 'sha1' : 'b2239599c8bf8f7fc48590a55205c26abe560bf8',
  301. 'build' : {
  302. 'msvc*-win32*': {
  303. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  304. 'commands': [
  305. 'perl Configure --openssldir=%(destdir)s VC-WIN32 no-asm',
  306. 'ms\\do_ms.bat',
  307. 'nmake /f ms\\nt.mak install'],
  308. },
  309. 'msvc*-win64*': {
  310. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  311. 'commands': [
  312. 'perl Configure --openssldir=%(destdir)s VC-WIN64A',
  313. 'ms\\do_win64a.bat',
  314. 'nmake /f ms\\nt.mak install']
  315. },
  316. 'mingw-w64-cross-win*': {
  317. 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
  318. 'commands': [
  319. 'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw-w64)s- no-shared no-asm mingw64',
  320. 'make',
  321. 'make install_sw']
  322. }
  323. }
  324. },
  325. 'zlib': {
  326. 'order' : 2,
  327. 'url' : 'http://downloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz',
  328. 'sha1' : 'a4d316c404ff54ca545ea71a27af7dbc29817088',
  329. 'build' : {
  330. 'msvc*': {
  331. 'result': {
  332. 'include/zlib.h' : 'zlib.h',
  333. 'include/zconf.h': 'zconf.h',
  334. 'lib/zdll.lib' : 'zlib.lib'
  335. },
  336. 'replace': [('win32/Makefile.msc', '-MD', '-MT')],
  337. 'commands': ['nmake /f win32/Makefile.msc zlib.lib']
  338. },
  339. 'mingw-w64-cross-win*': {
  340. 'result': {
  341. 'include/zlib.h' : 'zlib.h',
  342. 'include/zconf.h': 'zconf.h',
  343. 'lib/libz.a' : 'libz.a'
  344. },
  345. 'replace': [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw-w64)s-')],
  346. 'commands': ['make -f win32/Makefile.gcc']
  347. }
  348. }
  349. },
  350. 'libpng': {
  351. 'order' : 3,
  352. 'url' : 'http://downloads.sourceforge.net/libpng/libpng-1.5.18.tar.gz',
  353. 'sha1': '7ddf6865aa70d2d79faf65ebc611919a0b573654',
  354. 'build' : {
  355. 'msvc*': {
  356. 'result': {
  357. 'include/png.h' : 'png.h',
  358. 'include/pngconf.h' : 'pngconf.h',
  359. 'include/pnglibconf.h': 'pnglibconf.h',
  360. 'lib/libpng.lib' : 'libpng.lib'
  361. },
  362. 'replace': [
  363. ('scripts/makefile.vcwin32', '-MD', '-MT'),
  364. ('scripts/makefile.vcwin32', '-I..\\zlib', '-I..\\deplibs\\include'),
  365. ('scripts/makefile.vcwin32', '..\\zlib\\zlib.lib', '..\\deplibs\\lib\\zdll.lib')],
  366. 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
  367. },
  368. 'mingw-w64-cross-win*': {
  369. 'result': {
  370. 'include/png.h' : 'png.h',
  371. 'include/pngconf.h' : 'pngconf.h',
  372. 'include/pnglibconf.h': 'pnglibconf.h',
  373. 'lib/libpng.a' : 'libpng.a'
  374. },
  375. 'replace': [
  376. ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
  377. ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
  378. ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw-w64)s-gcc'),
  379. ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw-w64)s-ar'),
  380. ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw-w64)s-ranlib')],
  381. 'commands': ['make -f scripts/makefile.gcc libpng.a']
  382. },
  383. 'osx-carbon-i386': {
  384. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  385. 'commands': [
  386. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  387. 'make install']
  388. },
  389. 'osx-cocoa-x86-64': {
  390. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  391. 'commands': [
  392. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  393. 'make install']
  394. }
  395. }
  396. },
  397. 'libjpeg': {
  398. 'order' : 4,
  399. 'url' : 'http://ijg.org/files/jpegsrc.v9a.tar.gz',
  400. 'sha1': 'd65ed6f88d318f7380a3a5f75d578744e732daca',
  401. 'build' : {
  402. 'msvc*': {
  403. 'result': {
  404. 'include/jpeglib.h' : 'jpeglib.h',
  405. 'include/jmorecfg.h': 'jmorecfg.h',
  406. 'include/jerror.h' : 'jerror.h',
  407. 'include/jconfig.h' : 'jconfig.h',
  408. 'lib/libjpeg.lib' : 'libjpeg.lib'
  409. },
  410. 'replace': [('makefile.vc', '!include <win32.mak>', ''),
  411. ('makefile.vc', '$(cc)', 'cl'),
  412. ('makefile.vc', '$(cflags) $(cdebug) $(cvars)', '-c -nologo -D_CRT_SECURE_NO_DEPRECATE -MT -O2 -W3')],
  413. 'commands': [
  414. 'copy /y jconfig.vc jconfig.h',
  415. 'nmake /f makefile.vc libjpeg.lib']
  416. },
  417. 'mingw-w64-cross-win*': {
  418. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  419. 'commands': [
  420. './configure --host=%(mingw-w64)s --disable-shared --prefix=%(destdir)s',
  421. 'make install']
  422. },
  423. 'osx-carbon-i386': {
  424. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  425. 'commands': [
  426. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  427. 'make install']
  428. },
  429. 'osx-cocoa-x86-64': {
  430. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  431. 'commands': [
  432. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  433. 'make install']
  434. }
  435. }
  436. }
  437. }
  438. EXCLUDE_SRC_TARBALL = [
  439. 'qt/config.profiles*',
  440. 'qt/demos*',
  441. 'qt/dist*',
  442. 'qt/doc*',
  443. 'qt/examples*',
  444. 'qt/imports*',
  445. 'qt/templates*',
  446. 'qt/tests*',
  447. 'qt/translations*',
  448. 'qt/util*',
  449. 'qt/lib/fonts*',
  450. 'qt/src/3rdparty/*ChangeLog*',
  451. 'qt/src/3rdparty/ce-compat*',
  452. 'qt/src/3rdparty/clucene*',
  453. 'qt/src/3rdparty/fonts*',
  454. 'qt/src/3rdparty/freetype*',
  455. 'qt/src/3rdparty/javascriptcore*',
  456. 'qt/src/3rdparty/libgq*',
  457. 'qt/src/3rdparty/libmng*',
  458. 'qt/src/3rdparty/libtiff*',
  459. 'qt/src/3rdparty/patches*',
  460. 'qt/src/3rdparty/phonon*',
  461. 'qt/src/3rdparty/pixman*',
  462. 'qt/src/3rdparty/powervr*',
  463. 'qt/src/3rdparty/ptmalloc*',
  464. 'qt/src/3rdparty/s60*',
  465. 'qt/src/3rdparty/wayland*'
  466. ]
  467. # --------------------------------------------------------------- HELPERS
  468. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  469. from os.path import exists
  470. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  471. def rchop(s, e):
  472. if s.endswith(e):
  473. return s[:-len(e)]
  474. return s
  475. def message(msg):
  476. sys.stdout.write(msg)
  477. sys.stdout.flush()
  478. def error(msg):
  479. message(msg+'\n')
  480. sys.exit(1)
  481. def shell(cmd):
  482. ret = os.system(cmd)
  483. if ret != 0:
  484. error("%s\ncommand failed: exit code %d" % (cmd, ret))
  485. def get_output(*cmd):
  486. try:
  487. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  488. except:
  489. return None
  490. def rmdir(path):
  491. if exists(path):
  492. if platform.system() == 'Windows':
  493. shell('attrib -R %s\* /S' % path)
  494. shutil.rmtree(path)
  495. def mkdir_p(path):
  496. if not exists(path):
  497. os.makedirs(path)
  498. def get_version(basedir):
  499. mkdir_p(basedir)
  500. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  501. if '-' not in text:
  502. return (text, text)
  503. version = text[:text.index('-')]
  504. os.chdir(os.path.join(basedir, '..'))
  505. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  506. if not hash:
  507. return (text, version)
  508. return ('%s-%s' % (version, hash), version)
  509. def qt_config(key, *opts):
  510. input, output = [], []
  511. input.extend(QT_CONFIG['common'])
  512. input.extend(QT_CONFIG[key])
  513. input.extend(opts)
  514. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  515. if cfg:
  516. input.extend(cfg.split())
  517. for arg in input:
  518. if not arg.startswith('remove:-'):
  519. output.append(arg)
  520. elif arg[1+arg.index(':'):] in output:
  521. output.remove(arg[1+arg.index(':'):])
  522. return ' '.join(output)
  523. def fpm_setup(cfg):
  524. input, output = {}, ''
  525. input.update(FPM_SETUP['common'])
  526. input.update(FPM_SETUP[cfg])
  527. for key in input:
  528. if type(input[key]) is list:
  529. for val in input[key]:
  530. output += ' %s "%s"' % (key, val)
  531. else:
  532. output += ' %s "%s"' % (key, input[key])
  533. return output, input
  534. def download_file(url, sha1, dir):
  535. name = url.split('/')[-1]
  536. loc = os.path.join(dir, name)
  537. if os.path.exists(loc):
  538. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  539. if hash == sha1:
  540. return loc
  541. os.remove(loc)
  542. message('Checksum mismatch for %s, re-downloading.\n' % name)
  543. def hook(cnt, bs, total):
  544. pct = int(cnt*bs*100/total)
  545. message("\rDownloading: %s [%d%%]" % (name, pct))
  546. urllib.urlretrieve(url, loc, reporthook=hook)
  547. message("\r")
  548. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  549. if hash != sha1:
  550. os.remove(loc)
  551. error('Checksum mismatch for %s, aborting.' % name)
  552. message("\rDownloaded: %s [checksum OK]\n" % name)
  553. return loc
  554. def download_tarball(url, sha1, dir, name):
  555. loc = download_file(url, sha1, dir)
  556. tar = tarfile.open(loc)
  557. sub = tar.getnames()[0]
  558. if '/' in sub:
  559. sub = sub[:sub.index('/')]
  560. src = os.path.join(dir, sub)
  561. tgt = os.path.join(dir, name)
  562. rmdir(src)
  563. tar.extractall(dir)
  564. rmdir(tgt)
  565. os.rename(src, tgt)
  566. return tgt
  567. def _is_compiled(dst, loc):
  568. present = True
  569. for name in loc['result']:
  570. present = present and exists(os.path.join(dst, name))
  571. return present
  572. def build_deplibs(config, basedir):
  573. mkdir_p(os.path.join(basedir, config))
  574. dstdir = os.path.join(basedir, config, 'deplibs')
  575. vars = {'destdir': dstdir, 'mingw-w64': MINGW_W64_PREFIX.get(rchop(config, '-dbg'), '')}
  576. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  577. cfg = None
  578. for key in DEPENDENT_LIBS[lib]['build']:
  579. if fnmatch.fnmatch(config, key):
  580. cfg = key
  581. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  582. continue
  583. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  584. message('========== building: %s\n' % lib)
  585. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  586. basedir, os.path.join(config, lib))
  587. for location, source, target in build_cfg.get('replace', []):
  588. data = open(os.path.join(srcdir, location), 'r').read()
  589. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  590. os.chdir(srcdir)
  591. for command in build_cfg['commands']:
  592. shell(command % vars)
  593. if not type(build_cfg['result']) is list:
  594. for target in build_cfg['result']:
  595. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  596. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  597. os.chdir(dstdir)
  598. if not _is_compiled(dstdir, build_cfg):
  599. error("Unable to compile %s for your system, aborting." % lib)
  600. rmdir(srcdir)
  601. def check_running_on_debian():
  602. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  603. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  604. if os.geteuid() != 0:
  605. error('This script must be run as root.')
  606. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  607. ARCH.insert(0, 'amd64')
  608. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  609. def install_packages(*names):
  610. lines = get_output('dpkg-query', '--list').split('\n')
  611. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  612. inst = [name for name in names if name in avail]
  613. if len(inst) != len(names):
  614. shell('apt-get update')
  615. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  616. # --------------------------------------------------------------- Linux chroot
  617. ARCH = ['i386']
  618. def check_setup_schroot(config):
  619. check_running_on_debian()
  620. login = os.environ.get('SUDO_USER') or get_output('logname')
  621. if not login or login == 'root':
  622. error('Unable to determine the login for which schroot access is to be given.')
  623. def build_setup_schroot(config, basedir):
  624. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  625. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  626. login = os.environ.get('SUDO_USER') or get_output('logname')
  627. chroot = config[1+config.rindex('-'):]
  628. for arch in ARCH:
  629. message('******************* %s-%s\n' % (chroot, arch))
  630. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  631. root_dir = os.path.join(base_dir, 'wkhtmltopdf-%s-%s' % (chroot, arch))
  632. rmdir(root_dir)
  633. mkdir_p(root_dir)
  634. for command in CHROOT_SETUP[chroot]:
  635. # handle architecture-specific commands
  636. name = command[0]
  637. if ':' in name:
  638. if name[1+name.rindex(':'):] != arch:
  639. continue
  640. else:
  641. name = name[:name.rindex(':')]
  642. # handle commands
  643. if name == 'debootstrap':
  644. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  645. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  646. elif name == 'rinse':
  647. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  648. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  649. elif name == 'shell':
  650. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  651. shell('%s %s %s' % (cmd, root_dir, command[1]))
  652. elif name == 'write_file':
  653. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  654. elif name == 'append_file':
  655. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  656. elif name == 'download_file':
  657. name = command[1].split('/')[-1]
  658. loc = os.path.join(root_dir, command[2], name)
  659. if exists(loc): os.remove(loc)
  660. def hook(cnt, bs, total):
  661. pct = int(cnt*bs*100/total)
  662. message("\rDownloading: %s [%d%%]" % (name, pct))
  663. urllib.urlretrieve(command[1], loc, reporthook=hook)
  664. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  665. elif name == 'fpm_setup':
  666. args, cfg = fpm_setup(chroot)
  667. cmd = '#!/bin/sh\nXZ_OPT=-9 fpm --force %s --package ../%s-$1_linux-%s-$2.%s .\n'
  668. loc = os.path.join(root_dir, command[1])
  669. open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
  670. shell('chmod a+x %s' % loc)
  671. elif name == 'schroot_conf':
  672. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
  673. cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))
  674. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  675. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  676. cfg.write('users=%s\nroot-users=root\n' % login)
  677. if arch == 'i386' and 'amd64' in ARCH:
  678. cfg.write('personality=linux32\n')
  679. cfg.close()
  680. def check_update_schroot(config):
  681. check_running_on_debian()
  682. if not get_output('schroot', '--list'):
  683. error('Unable to determine the list of available schroots.')
  684. def build_update_schroot(config, basedir):
  685. for name in get_output('schroot', '--list').split('\n'):
  686. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  687. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  688. def check_setup_mingw64(config):
  689. check_running_on_debian()
  690. def build_setup_mingw64(config, basedir):
  691. install_packages('build-essential', 'mingw-w64', 'nsis')
  692. def check_source_tarball(config):
  693. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  694. error("This can only be run inside a git checkout.")
  695. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  696. error("Please initialize and download the Qt submodule before running this.")
  697. def _filter_tar(info):
  698. name = info.name[1+info.name.index('/'):]
  699. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  700. return None
  701. info.uid = info.gid = 1000
  702. info.uname = info.gname = 'wkhtmltopdf'
  703. return info
  704. def build_source_tarball(config, basedir):
  705. version, simple_version = get_version(basedir)
  706. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  707. os.chdir(os.path.join(root_dir, 'qt'))
  708. shell('git clean -fdx')
  709. shell('git reset --hard HEAD')
  710. os.chdir(root_dir)
  711. shell('git clean -fdx')
  712. shell('git reset --hard HEAD')
  713. shell('git submodule update')
  714. open('VERSION', 'w').write(version)
  715. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  716. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  717. shell('git reset --hard HEAD')
  718. # --------------------------------------------------------------- MSVC (2008-2013)
  719. MSVC_LOCATION = {
  720. 'msvc2008': 'VS90COMNTOOLS',
  721. 'msvc2010': 'VS100COMNTOOLS',
  722. 'msvc2012': 'VS110COMNTOOLS',
  723. 'msvc2013': 'VS120COMNTOOLS'
  724. }
  725. def check_msvc(config):
  726. version, arch = rchop(config, '-dbg').split('-')
  727. env_var = MSVC_LOCATION[version]
  728. if not env_var in os.environ:
  729. error("%s does not seem to be installed." % version)
  730. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  731. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  732. error("%s: unable to find vcvarsall.bat" % version)
  733. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  734. error("%s: unable to find the x86 compiler" % version)
  735. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  736. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  737. error("%s: unable to find the amd64 compiler" % version)
  738. def build_msvc(config, basedir):
  739. msvc, arch = rchop(config, '-dbg').split('-')
  740. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  741. vcarg = 'x86'
  742. if arch == 'win64':
  743. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  744. vcarg = 'amd64'
  745. else:
  746. vcarg = 'x86_amd64'
  747. python = sys.executable
  748. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  749. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  750. stdout, _ = process.communicate()
  751. exitcode = process.wait()
  752. if exitcode != 0:
  753. error("%s: unable to initialize the environment" % msvc)
  754. os.environ.update(eval(stdout.strip()))
  755. build_msvc_common(config, basedir)
  756. # --------------------------------------------------------------- MSVC via Windows SDK 7.1
  757. def check_msvc_winsdk71(config):
  758. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  759. if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
  760. return
  761. error("Unable to detect the location of Windows SDK 7.1")
  762. def build_msvc_winsdk71(config, basedir):
  763. arch = config[config.rindex('-'):]
  764. setenv = None
  765. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  766. if not pfile in os.environ:
  767. continue
  768. setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
  769. mode = debug and '/Debug' or '/Release'
  770. if arch == 'win64':
  771. args = '/2008 /x64 %s' % mode
  772. else:
  773. args = '/2008 /x86 %s' % mode
  774. python = sys.executable
  775. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  776. setenv, args, python), stdout=subprocess.PIPE, shell=True)
  777. stdout, _ = process.communicate()
  778. exitcode = process.wait()
  779. if exitcode != 0:
  780. error("unable to initialize the environment for Windows SDK 7.1")
  781. os.environ.update(eval(stdout.strip()))
  782. build_msvc_common(config, basedir)
  783. def build_msvc_common(config, basedir):
  784. version, simple_version = get_version(basedir)
  785. build_deplibs(config, basedir)
  786. libdir = os.path.join(basedir, config, 'deplibs')
  787. qtdir = os.path.join(basedir, config, 'qt')
  788. mkdir_p(qtdir)
  789. configure_args = qt_config('msvc',
  790. '-I %s\\include' % libdir,
  791. '-L %s\\lib' % libdir,
  792. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  793. os.chdir(qtdir)
  794. if not exists('is_configured'):
  795. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  796. open('is_configured', 'w').write('')
  797. shell('nmake')
  798. appdir = os.path.join(basedir, config, 'app')
  799. mkdir_p(appdir)
  800. os.chdir(appdir)
  801. rmdir('bin')
  802. mkdir_p('bin')
  803. os.environ['WKHTMLTOX_VERSION'] = version
  804. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  805. shell('nmake')
  806. found = False
  807. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  808. if not pfile in os.environ or not exists(os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')):
  809. continue
  810. found = True
  811. makensis = os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')
  812. os.chdir(os.path.join(basedir, '..'))
  813. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s wkhtmltox.nsi' % \
  814. (makensis, version, simple_version, config))
  815. if not found:
  816. message("\n\nCould not build installer as NSIS was not found.\n")
  817. # ------------------------------------------------ MinGW-W64 Cross Environment
  818. MINGW_W64_PREFIX = {
  819. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  820. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  821. }
  822. def check_mingw64_cross(config):
  823. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  824. def build_mingw64_cross(config, basedir):
  825. version, simple_version = get_version(basedir)
  826. build_deplibs(config, basedir)
  827. libdir = os.path.join(basedir, config, 'deplibs')
  828. qtdir = os.path.join(basedir, config, 'qt')
  829. configure_args = qt_config('mingw-w64-cross',
  830. '--prefix=%s' % qtdir,
  831. '-I %s/include' % libdir,
  832. '-L %s/lib' % libdir,
  833. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  834. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  835. mkdir_p(qtdir)
  836. os.chdir(qtdir)
  837. if not exists('is_configured'):
  838. for var in ['CFLAGS', 'CXXFLAGS']:
  839. os.environ[var] = '-w'
  840. shell('%s/../qt/configure %s' % (basedir, configure_args))
  841. shell('touch is_configured')
  842. shell('make -j%d' % CPU_COUNT)
  843. appdir = os.path.join(basedir, config, 'app')
  844. mkdir_p(appdir)
  845. os.chdir(appdir)
  846. shell('rm -f bin/*')
  847. # set up cross compiling prefix correctly
  848. os.environ['WKHTMLTOX_VERSION'] = version
  849. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  850. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  851. shell('make')
  852. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  853. os.chdir(os.path.join(basedir, '..'))
  854. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s wkhtmltox.nsi' % \
  855. (version, simple_version, config))
  856. # -------------------------------------------------- Linux schroot environment
  857. def check_linux_schroot(config):
  858. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  859. def build_linux_schroot(config, basedir):
  860. version, simple_version = get_version(basedir)
  861. dir = os.path.join(basedir, config)
  862. script = os.path.join(dir, 'build.sh')
  863. dist = os.path.join(dir, 'dist')
  864. mkdir_p(dir)
  865. rmdir(dist)
  866. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  867. lines = ['#!/bin/bash']
  868. lines.append('# start of autogenerated build script')
  869. lines.append('mkdir -p app qt')
  870. lines.append('cd qt')
  871. if config == 'centos5-i386':
  872. lines.append('export CFLAGS="-march=i486 -w"')
  873. lines.append('export CXXFLAGS="-march=i486 -w"')
  874. else:
  875. for var in ['CFLAGS', 'CXXFLAGS']:
  876. lines.append('export %s="-w"' % var)
  877. lines.append('if [ ! -f is_configured ]; then')
  878. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  879. lines.append(' touch is_configured')
  880. lines.append('fi')
  881. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  882. lines.append('cd ../app')
  883. lines.append('rm -f bin/*')
  884. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  885. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  886. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  887. lines.append('cd ..')
  888. lines.append('/fpm_package.sh %s %s' % (version, config[1+config.index('-'):]))
  889. lines.append('# end of build script')
  890. open(script, 'w').write('\n'.join(lines))
  891. os.chdir(dir)
  892. shell('chmod +x build.sh')
  893. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  894. # -------------------------------------------------- POSIX local environment
  895. def check_posix_local(config):
  896. pass
  897. def build_posix_local(config, basedir):
  898. version, simple_version = get_version(basedir)
  899. app = os.path.join(basedir, config, 'app')
  900. qtdir = os.path.join(basedir, config, 'qt')
  901. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  902. make = get_output('which gmake') and 'gmake' or 'make'
  903. mkdir_p(qt)
  904. mkdir_p(app)
  905. rmdir(dist)
  906. mkdir_p(os.path.join(dist, 'bin'))
  907. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  908. mkdir_p(os.path.join(dist, 'lib'))
  909. os.chdir(qt)
  910. if not exists('is_configured'):
  911. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qtdir))
  912. shell('touch is_configured')
  913. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  914. shell('%s -j%d' % (make, CPU_COUNT))
  915. os.chdir(app)
  916. shell('rm -f bin/*')
  917. os.environ['WKHTMLTOX_VERSION'] = version
  918. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  919. shell('%s -j%d' % (make, CPU_COUNT))
  920. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  921. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  922. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  923. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  924. os.chdir(basedir)
  925. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  926. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  927. # --------------------------------------------------------------- OS X
  928. def check_osx(config):
  929. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  930. error('This can only be run on a OS X system!')
  931. if not get_output('xcode-select', '--print-path'):
  932. error('Xcode is not installed, aborting.')
  933. if not get_output('which', 'fpm'):
  934. error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
  935. def build_osx(config, basedir):
  936. version, simple_version = get_version(basedir)
  937. build_deplibs(config, basedir)
  938. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  939. framework = config.split('-')[1]
  940. if osxver == '10.6':
  941. osxcfg = '-%s -platform macx-g++42' % framework
  942. else:
  943. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  944. flags = ''
  945. if framework == 'carbon' and osxver != '10.6':
  946. for item in ['CFLAGS', 'CXXFLAGS']:
  947. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  948. def get_dir(name):
  949. return os.path.join(basedir, config, name)
  950. configure_args = qt_config('osx', osxcfg,
  951. '--prefix=%s' % get_dir('qt'),
  952. '-I %s/include' % get_dir('deplibs'),
  953. '-L %s/lib' % get_dir('deplibs'))
  954. rmdir(get_dir('dist'))
  955. rmdir(get_dir('pkg'))
  956. mkdir_p(get_dir('qt'))
  957. mkdir_p(get_dir('app'))
  958. mkdir_p(get_dir('pkg'))
  959. os.chdir(get_dir('qt'))
  960. if not exists('is_configured'):
  961. shell('../../../qt/configure %s' % configure_args)
  962. shell('touch is_configured')
  963. shell('make -j%d' % CPU_COUNT)
  964. os.chdir(get_dir('app'))
  965. shell('rm -f bin/*')
  966. os.environ['WKHTMLTOX_VERSION'] = version
  967. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  968. shell('make -j%d' % CPU_COUNT)
  969. if osxver not in ['10.6', '10.7']:
  970. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  971. shell(' '.join([
  972. 'install_name_tool', '-change',
  973. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  974. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  975. 'bin/'+item]))
  976. shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
  977. def _osx_tar(info):
  978. info.uid = info.gid = 0
  979. info.uname = 'root'
  980. info.gname = 'wheel'
  981. return info
  982. # create tarballs for application and unxz
  983. os.chdir(get_dir('dist'))
  984. with tarfile.open('../pkg/app.tar', 'w') as tar:
  985. tar.add('.', './', filter=_osx_tar)
  986. shell('xz --compress --force --verbose -9 ../pkg/app.tar')
  987. with tarfile.open('../pkg/unxz.tar.gz', 'w:gz') as tar:
  988. unxz = get_output('which', 'unxz')
  989. lzma = os.path.join(os.path.dirname(unxz), '..', 'lib', 'liblzma.5.dylib')
  990. tar.add(unxz, './bin/unxz', filter=_osx_tar)
  991. tar.add(lzma, './lib/liblzma.5.dylib', filter=_osx_tar)
  992. args, cfg = fpm_setup('osx')
  993. open('../extract.sh', 'w').write("""#!/bin/bash
  994. TGTDIR=/usr/local
  995. BASEDIR=%s
  996. if [ -x $TGTDIR/bin/unxz ]
  997. then
  998. cd $TGTDIR;
  999. tar zxf $BASEDIR/unxz.tar.gz
  1000. fi
  1001. cd $BASEDIR
  1002. $TGTDIR/bin/unxz -k $BASEDIR/app.tar.xz
  1003. cd $TGTDIR
  1004. tar xf $BASEDIR/app.tar
  1005. rm -f $BASEDIR/app.tar
  1006. """ % cfg['--prefix'])
  1007. os.chdir(os.path.join(basedir, config))
  1008. shell('fpm --force %s --package ../%s-%s_%s.pkg .' % (args.replace('$1', version), cfg['--name'], version, config))
  1009. # --------------------------------------------------------------- command line
  1010. def usage(exit_code=2):
  1011. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  1012. opts = list(BUILDERS.keys())
  1013. opts.sort()
  1014. for opt in opts:
  1015. message('* %s\n' % opt)
  1016. sys.exit(exit_code)
  1017. def main():
  1018. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  1019. basedir = os.path.join(rootdir, 'static-build')
  1020. if len(sys.argv) == 1:
  1021. usage(0)
  1022. config = sys.argv[1]
  1023. if config not in BUILDERS:
  1024. usage()
  1025. for arg in sys.argv[2:]:
  1026. if not arg in ['-clean', '-debug']:
  1027. usage()
  1028. final_config = config
  1029. if '-debug' in sys.argv[2:]:
  1030. final_config += '-dbg'
  1031. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  1032. if '-clean' in sys.argv[2:]:
  1033. rmdir(os.path.join(basedir, config))
  1034. os.chdir(rootdir)
  1035. globals()['check_%s' % BUILDERS[config]](final_config)
  1036. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  1037. if __name__ == '__main__':
  1038. main()