build.py 49 KB

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