build.py 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142
  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. }
  217. CHROOT_SETUP = {
  218. 'wheezy': [
  219. ('debootstrap', 'wheezy', 'http://ftp.us.debian.org/debian/'),
  220. ('write_file', 'etc/apt/sources.list', """
  221. deb http://ftp.debian.org/debian/ wheezy main contrib non-free
  222. deb http://ftp.debian.org/debian/ wheezy-updates main contrib non-free
  223. deb http://security.debian.org/ wheezy/updates main contrib non-free"""),
  224. ('shell', 'apt-get update'),
  225. ('shell', 'apt-get dist-upgrade --assume-yes'),
  226. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  227. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  228. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  229. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  230. ('fpm_setup', 'fpm_package.sh'),
  231. ('schroot_conf', 'Debian Wheezy')
  232. ],
  233. 'trusty': [
  234. ('debootstrap', 'trusty', 'http://archive.ubuntu.com/ubuntu/'),
  235. ('write_file', 'etc/apt/sources.list', """
  236. deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
  237. deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
  238. deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse"""),
  239. ('shell', 'apt-get update'),
  240. ('shell', 'apt-get dist-upgrade --assume-yes'),
  241. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg-turbo8-dev zlib1g-dev ruby-dev'),
  242. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  243. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  244. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  245. ('fpm_setup', 'fpm_package.sh'),
  246. ('schroot_conf', 'Ubuntu Trusty')
  247. ],
  248. 'precise': [
  249. ('debootstrap', 'precise', 'http://archive.ubuntu.com/ubuntu/'),
  250. ('write_file', 'etc/apt/sources.list', """
  251. deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
  252. deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
  253. deb http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse"""),
  254. ('shell', 'apt-get update'),
  255. ('shell', 'apt-get dist-upgrade --assume-yes'),
  256. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  257. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  258. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  259. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  260. ('fpm_setup', 'fpm_package.sh'),
  261. ('schroot_conf', 'Ubuntu Precise')
  262. ],
  263. 'centos5': [
  264. ('rinse', 'centos-5'),
  265. ('download_file', 'http://centos.karan.org/el5/ruby187/kbs-el5-ruby187.repo', 'etc/yum.repos.d'),
  266. ('download_file', 'http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm', 'tmp'),
  267. ('shell', 'rpm -i /tmp/epel-release-5-4.noarch.rpm'),
  268. ('shell', 'yum update -y'),
  269. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  270. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl ruby-devel rubygems rpm-build libffi-devel'),
  271. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  272. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  273. ('write_file', 'update.sh', 'yum update -y\n'),
  274. ('fpm_setup', 'fpm_package.sh'),
  275. ('schroot_conf', 'CentOS 5')
  276. ],
  277. 'centos6': [
  278. ('rinse', 'centos-6'),
  279. ('shell', 'yum update -y'),
  280. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  281. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl ruby-devel rubygems rpm-build libffi-devel'),
  282. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  283. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  284. ('write_file', 'update.sh', 'yum update -y\n'),
  285. ('fpm_setup', 'fpm_package.sh'),
  286. ('schroot_conf', 'CentOS 6')
  287. ]
  288. }
  289. DEPENDENT_LIBS = {
  290. 'openssl': {
  291. 'order' : 1,
  292. 'url' : 'http://www.openssl.org/source/openssl-1.0.1h.tar.gz',
  293. 'sha1' : 'b2239599c8bf8f7fc48590a55205c26abe560bf8',
  294. 'build' : {
  295. 'msvc*-win32*': {
  296. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  297. 'commands': [
  298. 'perl Configure --openssldir=%(destdir)s VC-WIN32 no-asm',
  299. 'ms\\do_ms.bat',
  300. 'nmake /f ms\\nt.mak install'],
  301. },
  302. 'msvc*-win64*': {
  303. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  304. 'commands': [
  305. 'perl Configure --openssldir=%(destdir)s VC-WIN64A',
  306. 'ms\\do_win64a.bat',
  307. 'nmake /f ms\\nt.mak install']
  308. },
  309. 'mingw-w64-cross-win*': {
  310. 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
  311. 'commands': [
  312. 'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw-w64)s- no-shared no-asm mingw64',
  313. 'make',
  314. 'make install_sw']
  315. }
  316. }
  317. },
  318. 'zlib': {
  319. 'order' : 2,
  320. 'url' : 'http://downloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz',
  321. 'sha1' : 'a4d316c404ff54ca545ea71a27af7dbc29817088',
  322. 'build' : {
  323. 'msvc*': {
  324. 'result': {
  325. 'include/zlib.h' : 'zlib.h',
  326. 'include/zconf.h': 'zconf.h',
  327. 'lib/zdll.lib' : 'zlib.lib'
  328. },
  329. 'replace': [('win32/Makefile.msc', '-MD', '-MT')],
  330. 'commands': ['nmake /f win32/Makefile.msc zlib.lib']
  331. },
  332. 'mingw-w64-cross-win*': {
  333. 'result': {
  334. 'include/zlib.h' : 'zlib.h',
  335. 'include/zconf.h': 'zconf.h',
  336. 'lib/libz.a' : 'libz.a'
  337. },
  338. 'replace': [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw-w64)s-')],
  339. 'commands': ['make -f win32/Makefile.gcc']
  340. }
  341. }
  342. },
  343. 'libpng': {
  344. 'order' : 3,
  345. 'url' : 'http://downloads.sourceforge.net/libpng/libpng-1.5.18.tar.gz',
  346. 'sha1': '7ddf6865aa70d2d79faf65ebc611919a0b573654',
  347. 'build' : {
  348. 'msvc*': {
  349. 'result': {
  350. 'include/png.h' : 'png.h',
  351. 'include/pngconf.h' : 'pngconf.h',
  352. 'include/pnglibconf.h': 'pnglibconf.h',
  353. 'lib/libpng.lib' : 'libpng.lib'
  354. },
  355. 'replace': [
  356. ('scripts/makefile.vcwin32', '-MD', '-MT'),
  357. ('scripts/makefile.vcwin32', '-I..\\zlib', '-I..\\deplibs\\include'),
  358. ('scripts/makefile.vcwin32', '..\\zlib\\zlib.lib', '..\\deplibs\\lib\\zdll.lib')],
  359. 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
  360. },
  361. 'mingw-w64-cross-win*': {
  362. 'result': {
  363. 'include/png.h' : 'png.h',
  364. 'include/pngconf.h' : 'pngconf.h',
  365. 'include/pnglibconf.h': 'pnglibconf.h',
  366. 'lib/libpng.a' : 'libpng.a'
  367. },
  368. 'replace': [
  369. ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
  370. ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
  371. ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw-w64)s-gcc'),
  372. ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw-w64)s-ar'),
  373. ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw-w64)s-ranlib')],
  374. 'commands': ['make -f scripts/makefile.gcc libpng.a']
  375. },
  376. 'osx-carbon-i386': {
  377. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  378. 'commands': [
  379. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  380. 'make install']
  381. },
  382. 'osx-cocoa-x86-64': {
  383. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  384. 'commands': [
  385. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  386. 'make install']
  387. }
  388. }
  389. },
  390. 'libjpeg': {
  391. 'order' : 4,
  392. 'url' : 'http://ijg.org/files/jpegsrc.v9a.tar.gz',
  393. 'sha1': 'd65ed6f88d318f7380a3a5f75d578744e732daca',
  394. 'build' : {
  395. 'msvc*': {
  396. 'result': {
  397. 'include/jpeglib.h' : 'jpeglib.h',
  398. 'include/jmorecfg.h': 'jmorecfg.h',
  399. 'include/jerror.h' : 'jerror.h',
  400. 'include/jconfig.h' : 'jconfig.h',
  401. 'lib/libjpeg.lib' : 'libjpeg.lib'
  402. },
  403. 'replace': [('makefile.vc', '!include <win32.mak>', ''),
  404. ('makefile.vc', '$(cc)', 'cl'),
  405. ('makefile.vc', '$(cflags) $(cdebug) $(cvars)', '-c -nologo -D_CRT_SECURE_NO_DEPRECATE -MT -O2 -W3')],
  406. 'commands': [
  407. 'copy /y jconfig.vc jconfig.h',
  408. 'nmake /f makefile.vc libjpeg.lib']
  409. },
  410. 'mingw-w64-cross-win*': {
  411. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  412. 'commands': [
  413. './configure --host=%(mingw-w64)s --disable-shared --prefix=%(destdir)s',
  414. 'make install']
  415. },
  416. 'osx-carbon-i386': {
  417. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  418. 'commands': [
  419. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  420. 'make install']
  421. },
  422. 'osx-cocoa-x86-64': {
  423. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  424. 'commands': [
  425. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  426. 'make install']
  427. }
  428. }
  429. }
  430. }
  431. EXCLUDE_SRC_TARBALL = [
  432. 'qt/config.profiles*',
  433. 'qt/demos*',
  434. 'qt/dist*',
  435. 'qt/doc*',
  436. 'qt/examples*',
  437. 'qt/imports*',
  438. 'qt/templates*',
  439. 'qt/tests*',
  440. 'qt/translations*',
  441. 'qt/util*',
  442. 'qt/lib/fonts*',
  443. 'qt/src/3rdparty/*ChangeLog*',
  444. 'qt/src/3rdparty/ce-compat*',
  445. 'qt/src/3rdparty/clucene*',
  446. 'qt/src/3rdparty/fonts*',
  447. 'qt/src/3rdparty/freetype*',
  448. 'qt/src/3rdparty/javascriptcore*',
  449. 'qt/src/3rdparty/libgq*',
  450. 'qt/src/3rdparty/libmng*',
  451. 'qt/src/3rdparty/libtiff*',
  452. 'qt/src/3rdparty/patches*',
  453. 'qt/src/3rdparty/phonon*',
  454. 'qt/src/3rdparty/pixman*',
  455. 'qt/src/3rdparty/powervr*',
  456. 'qt/src/3rdparty/ptmalloc*',
  457. 'qt/src/3rdparty/s60*',
  458. 'qt/src/3rdparty/wayland*'
  459. ]
  460. # --------------------------------------------------------------- HELPERS
  461. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  462. from os.path import exists
  463. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  464. def rchop(s, e):
  465. if s.endswith(e):
  466. return s[:-len(e)]
  467. return s
  468. def message(msg):
  469. sys.stdout.write(msg)
  470. sys.stdout.flush()
  471. def error(msg):
  472. message(msg+'\n')
  473. sys.exit(1)
  474. def shell(cmd):
  475. ret = os.system(cmd)
  476. if ret != 0:
  477. error("command failed: exit code %d" % ret)
  478. def get_output(*cmd):
  479. try:
  480. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  481. except:
  482. return None
  483. def rmdir(path):
  484. if exists(path):
  485. if platform.system() == 'Windows':
  486. shell('attrib -R %s\* /S' % path)
  487. shutil.rmtree(path)
  488. def mkdir_p(path):
  489. if not exists(path):
  490. os.makedirs(path)
  491. def get_version(basedir):
  492. mkdir_p(basedir)
  493. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  494. if '-' not in text:
  495. return (text, text)
  496. version = text[:text.index('-')]
  497. os.chdir(os.path.join(basedir, '..'))
  498. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  499. if not hash:
  500. return (text, version)
  501. return ('%s-%s' % (version, hash), version)
  502. def qt_config(key, *opts):
  503. input, output = [], []
  504. input.extend(QT_CONFIG['common'])
  505. input.extend(QT_CONFIG[key])
  506. input.extend(opts)
  507. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  508. if cfg:
  509. input.extend(cfg.split())
  510. for arg in input:
  511. if not arg.startswith('remove:-'):
  512. output.append(arg)
  513. elif arg[1+arg.index(':'):] in output:
  514. output.remove(arg[1+arg.index(':'):])
  515. return ' '.join(output)
  516. def fpm_setup(cfg):
  517. input, output = {}, ''
  518. input.update(FPM_SETUP['common'])
  519. input.update(FPM_SETUP[cfg])
  520. for key in input:
  521. if type(input[key]) is list:
  522. for val in input[key]:
  523. output += ' %s "%s"' % (key, val)
  524. else:
  525. output += ' %s "%s"' % (key, input[key])
  526. return output, input
  527. def download_file(url, sha1, dir):
  528. name = url.split('/')[-1]
  529. loc = os.path.join(dir, name)
  530. if os.path.exists(loc):
  531. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  532. if hash == sha1:
  533. return loc
  534. os.remove(loc)
  535. message('Checksum mismatch for %s, re-downloading.\n' % name)
  536. def hook(cnt, bs, total):
  537. pct = int(cnt*bs*100/total)
  538. message("\rDownloading: %s [%d%%]" % (name, pct))
  539. urllib.urlretrieve(url, loc, reporthook=hook)
  540. message("\r")
  541. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  542. if hash != sha1:
  543. os.remove(loc)
  544. error('Checksum mismatch for %s, aborting.' % name)
  545. message("\rDownloaded: %s [checksum OK]\n" % name)
  546. return loc
  547. def download_tarball(url, sha1, dir, name):
  548. loc = download_file(url, sha1, dir)
  549. tar = tarfile.open(loc)
  550. sub = tar.getnames()[0]
  551. if '/' in sub:
  552. sub = sub[:sub.index('/')]
  553. src = os.path.join(dir, sub)
  554. tgt = os.path.join(dir, name)
  555. rmdir(src)
  556. tar.extractall(dir)
  557. rmdir(tgt)
  558. os.rename(src, tgt)
  559. return tgt
  560. def _is_compiled(dst, loc):
  561. present = True
  562. for name in loc['result']:
  563. present = present and exists(os.path.join(dst, name))
  564. return present
  565. def build_deplibs(config, basedir):
  566. mkdir_p(os.path.join(basedir, config))
  567. dstdir = os.path.join(basedir, config, 'deplibs')
  568. vars = {'destdir': dstdir, 'mingw-w64': MINGW_W64_PREFIX.get(rchop(config, '-dbg'), '')}
  569. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  570. cfg = None
  571. for key in DEPENDENT_LIBS[lib]['build']:
  572. if fnmatch.fnmatch(config, key):
  573. cfg = key
  574. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  575. continue
  576. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  577. message('========== building: %s\n' % lib)
  578. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  579. basedir, os.path.join(config, lib))
  580. for location, source, target in build_cfg.get('replace', []):
  581. data = open(os.path.join(srcdir, location), 'r').read()
  582. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  583. os.chdir(srcdir)
  584. for command in build_cfg['commands']:
  585. shell(command % vars)
  586. if not type(build_cfg['result']) is list:
  587. for target in build_cfg['result']:
  588. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  589. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  590. os.chdir(dstdir)
  591. if not _is_compiled(dstdir, build_cfg):
  592. error("Unable to compile %s for your system, aborting." % lib)
  593. rmdir(srcdir)
  594. def check_running_on_debian():
  595. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  596. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  597. if os.geteuid() != 0:
  598. error('This script must be run as root.')
  599. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  600. ARCH.insert(0, 'amd64')
  601. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  602. def install_packages(*names):
  603. lines = get_output('dpkg-query', '--list').split('\n')
  604. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  605. inst = [name for name in names if name in avail]
  606. if len(inst) != len(names):
  607. shell('apt-get update')
  608. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  609. # --------------------------------------------------------------- Linux chroot
  610. ARCH = ['i386']
  611. def check_setup_schroot(config):
  612. check_running_on_debian()
  613. login = os.environ.get('SUDO_USER') or get_output('logname')
  614. if not login or login == 'root':
  615. error('Unable to determine the login for which schroot access is to be given.')
  616. def build_setup_schroot(config, basedir):
  617. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  618. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  619. login = os.environ.get('SUDO_USER') or get_output('logname')
  620. chroot = config[1+config.rindex('-'):]
  621. for arch in ARCH:
  622. message('******************* %s-%s\n' % (chroot, arch))
  623. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  624. root_dir = os.path.join(base_dir, 'wkhtmltopdf-%s-%s' % (chroot, arch))
  625. rmdir(root_dir)
  626. mkdir_p(root_dir)
  627. for command in CHROOT_SETUP[chroot]:
  628. # handle architecture-specific commands
  629. name = command[0]
  630. if ':' in name:
  631. if name[1+name.rindex(':'):] != arch:
  632. continue
  633. else:
  634. name = name[:name.rindex(':')]
  635. # handle commands
  636. if name == 'debootstrap':
  637. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  638. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  639. elif name == 'rinse':
  640. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  641. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  642. elif name == 'shell':
  643. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  644. shell('%s %s %s' % (cmd, root_dir, command[1]))
  645. elif name == 'write_file':
  646. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  647. elif name == 'append_file':
  648. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  649. elif name == 'download_file':
  650. name = command[1].split('/')[-1]
  651. loc = os.path.join(root_dir, command[2], name)
  652. if exists(loc): os.remove(loc)
  653. def hook(cnt, bs, total):
  654. pct = int(cnt*bs*100/total)
  655. message("\rDownloading: %s [%d%%]" % (name, pct))
  656. urllib.urlretrieve(command[1], loc, reporthook=hook)
  657. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  658. elif name == 'fpm_setup':
  659. args, cfg = fpm_setup(chroot)
  660. cmd = '#!/bin/sh\nXZ_OPT=-9 fpm --force %s --package ../%s-$1_linux-%s-$2.%s .\n'
  661. loc = os.path.join(root_dir, command[1])
  662. open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
  663. shell('chmod a+x %s' % loc)
  664. elif name == 'schroot_conf':
  665. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
  666. cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))
  667. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  668. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  669. cfg.write('users=%s\nroot-users=root\n' % login)
  670. if arch == 'i386' and 'amd64' in ARCH:
  671. cfg.write('personality=linux32\n')
  672. cfg.close()
  673. def check_update_schroot(config):
  674. check_running_on_debian()
  675. if not get_output('schroot', '--list'):
  676. error('Unable to determine the list of available schroots.')
  677. def build_update_schroot(config, basedir):
  678. for name in get_output('schroot', '--list').split('\n'):
  679. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  680. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  681. def check_setup_mingw64(config):
  682. check_running_on_debian()
  683. def build_setup_mingw64(config, basedir):
  684. install_packages('build-essential', 'mingw-w64', 'nsis')
  685. def check_source_tarball(config):
  686. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  687. error("This can only be run inside a git checkout.")
  688. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  689. error("Please initialize and download the Qt submodule before running this.")
  690. def _filter_tar(info):
  691. name = info.name[1+info.name.index('/'):]
  692. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  693. return None
  694. info.uid = info.gid = 1000
  695. info.uname = info.gname = 'wkhtmltopdf'
  696. return info
  697. def build_source_tarball(config, basedir):
  698. version, simple_version = get_version(basedir)
  699. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  700. os.chdir(os.path.join(root_dir, 'qt'))
  701. shell('git clean -fdx')
  702. shell('git reset --hard HEAD')
  703. os.chdir(root_dir)
  704. shell('git clean -fdx')
  705. shell('git reset --hard HEAD')
  706. shell('git submodule update')
  707. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  708. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  709. # --------------------------------------------------------------- MSVC (2008-2013)
  710. MSVC_LOCATION = {
  711. 'msvc2008': 'VS90COMNTOOLS',
  712. 'msvc2010': 'VS100COMNTOOLS',
  713. 'msvc2012': 'VS110COMNTOOLS',
  714. 'msvc2013': 'VS120COMNTOOLS'
  715. }
  716. def check_msvc(config):
  717. version, arch = rchop(config, '-dbg').split('-')
  718. env_var = MSVC_LOCATION[version]
  719. if not env_var in os.environ:
  720. error("%s does not seem to be installed." % version)
  721. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  722. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  723. error("%s: unable to find vcvarsall.bat" % version)
  724. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  725. error("%s: unable to find the x86 compiler" % version)
  726. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  727. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  728. error("%s: unable to find the amd64 compiler" % version)
  729. def build_msvc(config, basedir):
  730. msvc, arch = rchop(config, '-dbg').split('-')
  731. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  732. vcarg = 'x86'
  733. if arch == 'win64':
  734. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  735. vcarg = 'amd64'
  736. else:
  737. vcarg = 'x86_amd64'
  738. python = sys.executable
  739. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  740. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  741. stdout, _ = process.communicate()
  742. exitcode = process.wait()
  743. if exitcode != 0:
  744. error("%s: unable to initialize the environment" % msvc)
  745. os.environ.update(eval(stdout.strip()))
  746. build_msvc_common(config, basedir)
  747. # --------------------------------------------------------------- MSVC via Windows SDK 7.1
  748. def check_msvc_winsdk71(config):
  749. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  750. if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
  751. return
  752. error("Unable to detect the location of Windows SDK 7.1")
  753. def build_msvc_winsdk71(config, basedir):
  754. arch = config[config.rindex('-'):]
  755. setenv = None
  756. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  757. if not pfile in os.environ:
  758. continue
  759. setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
  760. mode = debug and '/Debug' or '/Release'
  761. if arch == 'win64':
  762. args = '/2008 /x64 %s' % mode
  763. else:
  764. args = '/2008 /x86 %s' % mode
  765. python = sys.executable
  766. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  767. setenv, args, python), stdout=subprocess.PIPE, shell=True)
  768. stdout, _ = process.communicate()
  769. exitcode = process.wait()
  770. if exitcode != 0:
  771. error("unable to initialize the environment for Windows SDK 7.1")
  772. os.environ.update(eval(stdout.strip()))
  773. build_msvc_common(config, basedir)
  774. def build_msvc_common(config, basedir):
  775. version, simple_version = get_version(basedir)
  776. build_deplibs(config, basedir)
  777. libdir = os.path.join(basedir, config, 'deplibs')
  778. qtdir = os.path.join(basedir, config, 'qt')
  779. mkdir_p(qtdir)
  780. configure_args = qt_config('msvc',
  781. '-I %s\\include' % libdir,
  782. '-L %s\\lib' % libdir,
  783. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  784. os.chdir(qtdir)
  785. if not exists('is_configured'):
  786. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  787. open('is_configured', 'w').write('')
  788. shell('nmake')
  789. appdir = os.path.join(basedir, config, 'app')
  790. mkdir_p(appdir)
  791. os.chdir(appdir)
  792. rmdir('bin')
  793. mkdir_p('bin')
  794. os.environ['WKHTMLTOX_VERSION'] = version
  795. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  796. shell('nmake')
  797. found = False
  798. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  799. if not pfile in os.environ or not exists(os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')):
  800. continue
  801. found = True
  802. makensis = os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')
  803. os.chdir(os.path.join(basedir, '..'))
  804. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s wkhtmltox.nsi' % \
  805. (makensis, version, simple_version, config))
  806. if not found:
  807. message("\n\nCould not build installer as NSIS was not found.\n")
  808. # ------------------------------------------------ MinGW-W64 Cross Environment
  809. MINGW_W64_PREFIX = {
  810. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  811. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  812. }
  813. def check_mingw64_cross(config):
  814. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  815. def build_mingw64_cross(config, basedir):
  816. version, simple_version = get_version(basedir)
  817. build_deplibs(config, basedir)
  818. libdir = os.path.join(basedir, config, 'deplibs')
  819. qtdir = os.path.join(basedir, config, 'qt')
  820. configure_args = qt_config('mingw-w64-cross',
  821. '--prefix=%s' % qtdir,
  822. '-I %s/include' % libdir,
  823. '-L %s/lib' % libdir,
  824. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  825. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  826. mkdir_p(qtdir)
  827. os.chdir(qtdir)
  828. if not exists('is_configured'):
  829. for var in ['CFLAGS', 'CXXFLAGS']:
  830. os.environ[var] = '-w'
  831. shell('%s/../qt/configure %s' % (basedir, configure_args))
  832. shell('touch is_configured')
  833. shell('make -j%d' % CPU_COUNT)
  834. appdir = os.path.join(basedir, config, 'app')
  835. mkdir_p(appdir)
  836. os.chdir(appdir)
  837. shell('rm -f bin/*')
  838. # set up cross compiling prefix correctly
  839. os.environ['WKHTMLTOX_VERSION'] = version
  840. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  841. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  842. shell('make')
  843. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  844. os.chdir(os.path.join(basedir, '..'))
  845. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s wkhtmltox.nsi' % \
  846. (version, simple_version, config))
  847. # -------------------------------------------------- Linux schroot environment
  848. def check_linux_schroot(config):
  849. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  850. def build_linux_schroot(config, basedir):
  851. version, simple_version = get_version(basedir)
  852. dir = os.path.join(basedir, config)
  853. script = os.path.join(dir, 'build.sh')
  854. dist = os.path.join(dir, 'dist')
  855. mkdir_p(dir)
  856. rmdir(dist)
  857. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  858. lines = ['#!/bin/bash']
  859. lines.append('# start of autogenerated build script')
  860. lines.append('mkdir -p app qt')
  861. lines.append('cd qt')
  862. if config == 'centos5-i386':
  863. lines.append('export CFLAGS="-march=i486 -w"')
  864. lines.append('export CXXFLAGS="-march=i486 -w"')
  865. else:
  866. for var in ['CFLAGS', 'CXXFLAGS']:
  867. lines.append('export %s="-w"' % var)
  868. lines.append('if [ ! -f is_configured ]; then')
  869. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  870. lines.append(' touch is_configured')
  871. lines.append('fi')
  872. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  873. lines.append('cd ../app')
  874. lines.append('rm -f bin/*')
  875. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  876. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  877. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  878. lines.append('cd ..')
  879. lines.append('/fpm_package.sh %s %s' % (version, config[1+config.index('-'):]))
  880. lines.append('# end of build script')
  881. open(script, 'w').write('\n'.join(lines))
  882. os.chdir(dir)
  883. shell('chmod +x build.sh')
  884. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  885. # -------------------------------------------------- POSIX local environment
  886. def check_posix_local(config):
  887. pass
  888. def build_posix_local(config, basedir):
  889. version, simple_version = get_version(basedir)
  890. app = os.path.join(basedir, config, 'app')
  891. qtdir = os.path.join(basedir, config, 'qt')
  892. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  893. make = get_output('which gmake') and 'gmake' or 'make'
  894. mkdir_p(qt)
  895. mkdir_p(app)
  896. rmdir(dist)
  897. mkdir_p(os.path.join(dist, 'bin'))
  898. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  899. mkdir_p(os.path.join(dist, 'lib'))
  900. os.chdir(qt)
  901. if not exists('is_configured'):
  902. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qtdir))
  903. shell('touch is_configured')
  904. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  905. shell('%s -j%d' % (make, CPU_COUNT))
  906. os.chdir(app)
  907. shell('rm -f bin/*')
  908. os.environ['WKHTMLTOX_VERSION'] = version
  909. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  910. shell('%s -j%d' % (make, CPU_COUNT))
  911. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  912. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  913. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  914. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  915. os.chdir(basedir)
  916. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  917. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  918. # --------------------------------------------------------------- OS X
  919. def check_osx(config):
  920. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  921. error('This can only be run on a OS X system!')
  922. if not get_output('xcode-select', '--print-path'):
  923. error('Xcode is not installed, aborting.')
  924. def build_osx(config, basedir):
  925. version, simple_version = get_version(basedir)
  926. build_deplibs(config, basedir)
  927. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  928. framework = config.split('-')[1]
  929. if osxver == '10.6':
  930. osxcfg = '-%s -platform macx-g++42' % framework
  931. else:
  932. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  933. flags = ''
  934. if framework == 'carbon' and osxver != '10.6':
  935. for item in ['CFLAGS', 'CXXFLAGS']:
  936. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  937. qt = os.path.join(basedir, config, 'qt')
  938. libs = os.path.join(basedir, config, 'deplibs')
  939. app = os.path.join(basedir, config, 'app')
  940. dist = os.path.join(basedir, config, 'dist')
  941. configure_args = qt_config('osx', osxcfg,
  942. '--prefix=%s' % qt,
  943. '-I %s/include' % libs,
  944. '-L %s/lib' % libs)
  945. mkdir_p(qt)
  946. mkdir_p(app)
  947. rmdir(dist)
  948. os.chdir(qt)
  949. if not exists('is_configured'):
  950. shell('../../../qt/configure %s' % configure_args)
  951. shell('touch is_configured')
  952. shell('make -j%d' % CPU_COUNT)
  953. os.chdir(app)
  954. shell('rm -f bin/*')
  955. os.environ['WKHTMLTOX_VERSION'] = version
  956. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  957. shell('make -j%d' % CPU_COUNT)
  958. if osxver not in ['10.6', '10.7']:
  959. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  960. shell(' '.join([
  961. 'install_name_tool', '-change',
  962. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  963. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  964. 'bin/'+item]))
  965. shell('make install INSTALL_ROOT=%s' % dist)
  966. os.chdir(dist)
  967. shell('tar -c -v -f ../../wkhtmltox-%s_%s.tar .' % (version, config))
  968. shell('xz --compress --force --verbose -9 ../../wkhtmltox-%s_%s.tar' % (version, config))
  969. # --------------------------------------------------------------- command line
  970. def usage(exit_code=2):
  971. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  972. opts = list(BUILDERS.keys())
  973. opts.sort()
  974. for opt in opts:
  975. message('* %s\n' % opt)
  976. sys.exit(exit_code)
  977. def main():
  978. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  979. basedir = os.path.join(rootdir, 'static-build')
  980. if len(sys.argv) == 1:
  981. usage(0)
  982. config = sys.argv[1]
  983. if config not in BUILDERS:
  984. usage()
  985. for arg in sys.argv[2:]:
  986. if not arg in ['-clean', '-debug']:
  987. usage()
  988. final_config = config
  989. if '-debug' in sys.argv[2:]:
  990. final_config += '-dbg'
  991. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  992. if '-clean' in sys.argv[2:]:
  993. rmdir(os.path.join(basedir, config))
  994. os.chdir(rootdir)
  995. globals()['check_%s' % BUILDERS[config]](final_config)
  996. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  997. if __name__ == '__main__':
  998. main()