build.py 50 KB

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