build.py 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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 -- ',
  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 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.2h.tar.gz',
  265. 'sha1' : '577585f5f5d299c44dd3c993d3c0ac7a219e4949',
  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.2.56.tar.gz',
  320. 'sha1': '9619a20e1bfc34edfbc4931a632a2d6a2c8a9fbc',
  321. 'build' : {
  322. 'msvc*': {
  323. 'result': {
  324. 'include/png.h' : 'png.h',
  325. 'include/pngconf.h' : 'pngconf.h',
  326. 'lib/libpng.lib' : 'libpng.lib'
  327. },
  328. 'replace': [
  329. ('scripts/makefile.vcwin32', '-I..\\zlib', '-I..\\deplibs\\include'),
  330. ('scripts/makefile.vcwin32', '..\\zlib\\zlib.lib', '..\\deplibs\\lib\\zdll.lib'),
  331. ('scripts/makefile.vcwin32', '-MD', '%(cflags)s')],
  332. 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
  333. },
  334. 'mingw-w64-cross-win*': {
  335. 'result': {
  336. 'include/png.h' : 'png.h',
  337. 'include/pngconf.h' : 'pngconf.h',
  338. 'lib/libpng.a' : 'libpng.a'
  339. },
  340. 'replace': [
  341. ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
  342. ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
  343. ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw_w64)s-gcc'),
  344. ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw_w64)s-ar'),
  345. ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw_w64)s-ranlib')],
  346. 'commands': ['make -f scripts/makefile.gcc libpng.a']
  347. },
  348. 'osx-carbon-i386': {
  349. 'result': ['include/png.h', 'include/pngconf.h', 'lib/libpng.a'],
  350. 'commands': [
  351. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  352. 'make install']
  353. },
  354. 'osx-cocoa-x86-64': {
  355. 'result': ['include/png.h', 'include/pngconf.h', 'lib/libpng.a'],
  356. 'commands': [
  357. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  358. 'make install']
  359. },
  360. 'linux-generic-*': {
  361. 'result': ['include/png.h', 'include/pngconf.h', 'lib/libpng.a'],
  362. 'commands': [
  363. 'CFLAGS="-fPIC" ./configure --disable-shared --enable-static --prefix=%(destdir)s',
  364. 'make install']
  365. }
  366. }
  367. },
  368. 'libjpeg': {
  369. 'order' : 4,
  370. 'url' : 'http://ijg.org/files/jpegsrc.v9b.tar.gz',
  371. 'sha1': '15dd867617a88abd07573e06a86ace9bdb998ac2',
  372. 'build' : {
  373. 'msvc*': {
  374. 'result': {
  375. 'include/jpeglib.h' : 'jpeglib.h',
  376. 'include/jmorecfg.h': 'jmorecfg.h',
  377. 'include/jerror.h' : 'jerror.h',
  378. 'include/jconfig.h' : 'jconfig.h',
  379. 'lib/libjpeg.lib' : 'libjpeg.lib'
  380. },
  381. 'replace': [('makefile.vc', '!include <win32.mak>', ''),
  382. ('makefile.vc', '$(cc)', 'cl'),
  383. ('makefile.vc', '$(cflags) $(cdebug) $(cvars)', '-c -nologo -D_CRT_SECURE_NO_DEPRECATE %(cflags)s -O2 -W3')],
  384. 'commands': [
  385. 'copy /y jconfig.vc jconfig.h',
  386. 'nmake /f makefile.vc libjpeg.lib']
  387. },
  388. 'mingw-w64-cross-win*': {
  389. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  390. 'commands': [
  391. './configure --host=%(mingw_w64)s --disable-shared --prefix=%(destdir)s',
  392. 'make install']
  393. },
  394. 'osx-carbon-i386': {
  395. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  396. 'commands': [
  397. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  398. 'make install']
  399. },
  400. 'osx-cocoa-x86-64': {
  401. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  402. 'commands': [
  403. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  404. 'make install']
  405. },
  406. 'linux-generic-*': {
  407. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  408. 'commands': [
  409. 'CFLAGS="-fPIC" ./configure --disable-shared --enable-static --prefix=%(destdir)s',
  410. 'make install']
  411. }
  412. }
  413. },
  414. 'xz': {
  415. 'order' : 5,
  416. 'url' : 'http://tukaani.org/xz/xz-5.2.2.tar.gz',
  417. 'sha1': '14663612422ab61386673be78fbb2556f50a1f08',
  418. 'build' : {
  419. 'osx*': {
  420. 'result': ['bin/xz'],
  421. 'commands': [
  422. 'CFLAGS="-arch i386 -mmacosx-version-min=10.6" ./configure --disable-nls --enable-small --disable-shared --disable-threads --prefix=%(destdir)s',
  423. 'make -C src/liblzma', 'make -C src/xz', 'make install-strip']
  424. }
  425. }
  426. }
  427. }
  428. EXCLUDE_SRC_TARBALL = [
  429. 'qt/config.profiles*',
  430. 'qt/demos*',
  431. 'qt/dist*',
  432. 'qt/doc*',
  433. 'qt/examples*',
  434. 'qt/imports*',
  435. 'qt/templates*',
  436. 'qt/tests*',
  437. 'qt/translations*',
  438. 'qt/util*',
  439. 'qt/lib/fonts*',
  440. 'qt/src/3rdparty/*ChangeLog*',
  441. 'qt/src/3rdparty/ce-compat*',
  442. 'qt/src/3rdparty/clucene*',
  443. 'qt/src/3rdparty/fonts*',
  444. 'qt/src/3rdparty/freetype*',
  445. 'qt/src/3rdparty/javascriptcore*',
  446. 'qt/src/3rdparty/libgq*',
  447. 'qt/src/3rdparty/libmng*',
  448. 'qt/src/3rdparty/libtiff*',
  449. 'qt/src/3rdparty/patches*',
  450. 'qt/src/3rdparty/phonon*',
  451. 'qt/src/3rdparty/pixman*',
  452. 'qt/src/3rdparty/powervr*',
  453. 'qt/src/3rdparty/ptmalloc*',
  454. 'qt/src/3rdparty/s60*',
  455. 'qt/src/3rdparty/wayland*'
  456. ]
  457. # --------------------------------------------------------------- HELPERS
  458. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  459. from os.path import exists
  460. if platform.system() == 'Windows':
  461. try:
  462. import winreg
  463. except ImportError:
  464. import _winreg as winreg
  465. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  466. else:
  467. CPU_COUNT = max(2, multiprocessing.cpu_count())
  468. def rchop(s, e):
  469. if s.endswith(e):
  470. return s[:-len(e)]
  471. return s
  472. def message(msg):
  473. sys.stdout.write(msg)
  474. sys.stdout.flush()
  475. def error(msg):
  476. message(msg+'\n')
  477. sys.exit(1)
  478. def shell(cmd):
  479. ret = os.system(cmd)
  480. if ret != 0:
  481. error("%s\ncommand failed: exit code %d" % (cmd, ret))
  482. def chroot_shell(name, cmd):
  483. distro = get_chroot_list().get(name)
  484. wrapper = LINUX_SCHROOT_SETUP.get(distro, {}).get('wrapper_command', '')
  485. ret = os.system('schroot -c wkhtmltox-%s -- %s%s ' % (name, wrapper, cmd))
  486. if ret != 0:
  487. error("command inside chroot failed: exit code %d" % ret)
  488. def get_output(*cmd):
  489. try:
  490. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  491. except:
  492. return None
  493. def rmdir(path):
  494. if exists(path):
  495. if platform.system() == 'Windows':
  496. shell('attrib -R %s\* /S' % path)
  497. shutil.rmtree(path)
  498. def mkdir_p(path):
  499. if not exists(path):
  500. os.makedirs(path)
  501. def get_registry_value(key, value=None):
  502. for mask in [0, winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY]:
  503. try:
  504. reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key, 0, winreg.KEY_READ | mask)
  505. return winreg.QueryValueEx(reg_key, value)[0]
  506. except WindowsError:
  507. pass
  508. return None
  509. def get_version(basedir):
  510. mkdir_p(basedir)
  511. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  512. if '-' not in text:
  513. return (text, text)
  514. version = text[:text.index('-')]
  515. os.chdir(os.path.join(basedir, '..'))
  516. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  517. if not hash:
  518. return (text, version)
  519. return ('%s-%s' % (text, hash), version)
  520. def nsis_version(ver):
  521. while ver.count('.') < 3:
  522. ver += '.0'
  523. return ver
  524. def qt_config(key, *opts):
  525. input, output = [], []
  526. input.extend(QT_CONFIG['common'])
  527. input.extend(QT_CONFIG[key])
  528. input.extend(opts)
  529. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  530. if cfg:
  531. input.extend(cfg.split())
  532. for arg in input:
  533. if not arg.startswith('remove:-'):
  534. output.append(arg)
  535. elif arg[1+arg.index(':'):] in output:
  536. output.remove(arg[1+arg.index(':'):])
  537. return ' '.join(output)
  538. def fpm_params(cfg, ver):
  539. setup = LINUX_SCHROOT_SETUP[cfg[:cfg.index('-')]]
  540. output = '--force --prefix /usr/local --category utils -s dir -C dist'
  541. for key in PROJECT_SETUP:
  542. output += ' --%s "%s"' % (key, PROJECT_SETUP[key])
  543. output += ' --version "%s"' % ver
  544. output += ' --package ../%s-%s_linux-%s' % (PROJECT_SETUP['name'], ver, cfg)
  545. if setup['packaging_tool'] == 'apt':
  546. output += '.deb -t deb --deb-compression %s' % setup['compression']
  547. output += ' --provides wkhtmltopdf --conflicts wkhtmltopdf --replaces wkhtmltopdf'
  548. elif setup['packaging_tool'] == 'yum':
  549. output += '.rpm -t rpm --rpm-compression %s --epoch 1' % setup['compression']
  550. for depend in setup['runtime_packages'].split():
  551. output += ' --depends %s' % depend
  552. output += ' .'
  553. return output
  554. def download_file(url, sha1, dir):
  555. name = url.split('/')[-1]
  556. loc = os.path.join(dir, name)
  557. if os.path.exists(loc):
  558. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  559. if hash == sha1:
  560. return loc
  561. os.remove(loc)
  562. message('Checksum mismatch for %s, re-downloading.\n' % name)
  563. def hook(cnt, bs, total):
  564. pct = int(cnt*bs*100/total)
  565. message("\rDownloading: %s [%d%%]" % (name, pct))
  566. urllib.urlretrieve(url, loc, reporthook=hook)
  567. message("\r")
  568. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  569. if hash != sha1:
  570. os.remove(loc)
  571. error('Checksum mismatch for %s, aborting.' % name)
  572. message("\rDownloaded: %s [checksum OK]\n" % name)
  573. return loc
  574. def download_tarball(url, sha1, dir, name):
  575. loc = download_file(url, sha1, dir)
  576. tar = tarfile.open(loc)
  577. sub = tar.getnames()[0]
  578. if '/' in sub:
  579. sub = sub[:sub.index('/')]
  580. src = os.path.join(dir, sub)
  581. tgt = os.path.join(dir, name)
  582. rmdir(src)
  583. tar.extractall(dir)
  584. rmdir(tgt)
  585. os.rename(src, tgt)
  586. return tgt
  587. def _is_compiled(dst, loc):
  588. present = True
  589. for name in loc['result']:
  590. if isinstance(name, tuple):
  591. present = present and bool([n for n in name if exists(os.path.join(dst, n))])
  592. else:
  593. present = present and exists(os.path.join(dst, name))
  594. return present
  595. def build_deplibs(config, basedir, **kwargs):
  596. mkdir_p(os.path.join(basedir, config))
  597. dstdir = os.path.join(basedir, config, 'deplibs')
  598. vars = {'destdir': dstdir }
  599. vars.update(kwargs)
  600. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  601. cfg = None
  602. for key in DEPENDENT_LIBS[lib]['build']:
  603. if fnmatch.fnmatch(config, key):
  604. cfg = key
  605. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  606. continue
  607. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  608. message('========== building: %s\n' % lib)
  609. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  610. basedir, os.path.join(config, lib))
  611. for location, source, target in build_cfg.get('replace', []):
  612. data = open(os.path.join(srcdir, location), 'r').read()
  613. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  614. os.chdir(srcdir)
  615. for command in build_cfg['commands']:
  616. shell(command % vars)
  617. if not type(build_cfg['result']) is list:
  618. for target in build_cfg['result']:
  619. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  620. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  621. os.chdir(dstdir)
  622. if not _is_compiled(dstdir, build_cfg):
  623. error("Unable to compile %s for your system, aborting." % lib)
  624. rmdir(srcdir)
  625. def build_qt(qtdir, make_cmd, configure_cmd):
  626. configured = ''
  627. if exists(os.path.join(qtdir, 'configured')):
  628. configured = open(os.path.join(qtdir, 'configured'), 'r').read()
  629. if not 'qt' in configured or not exists(qtdir):
  630. mkdir_p(qtdir)
  631. os.chdir(qtdir)
  632. shell(configure_cmd)
  633. open(os.path.join(qtdir, 'configured'), 'a').write('qt\n')
  634. os.chdir(qtdir)
  635. shell(make_cmd)
  636. def check_running_on_debian():
  637. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list') or platform.architecture()[0] != '64bit':
  638. error('This can only be run on a 64-bit Debian/Ubuntu distribution, aborting.')
  639. if os.geteuid() != 0:
  640. error('This script must be run as root.')
  641. def install_packages(*names):
  642. inst = get_output('dpkg-query', '--show', '--showformat', '${Package}\n').split('\n')
  643. miss = [name for name in names if name not in inst]
  644. if miss:
  645. shell('apt-get update')
  646. shell('apt-get install --assume-yes %s' % (' '.join(miss)))
  647. def get_chroot_list():
  648. prefix = 'chroot:wkhtmltox-'
  649. result = {}
  650. for line in get_output('schroot', '--list').split('\n'):
  651. if not line.startswith(prefix):
  652. continue
  653. name = line[len(prefix):]
  654. for distro in LINUX_SCHROOT_SETUP:
  655. if 'chroot_alias' in LINUX_SCHROOT_SETUP[distro]:
  656. if name == LINUX_SCHROOT_SETUP[distro]['chroot_alias']:
  657. result[name] = distro
  658. continue
  659. for arch in LINUX_SCHROOT_SETUP[distro]['build_arch']:
  660. if name == '%s-%s' % (distro, arch):
  661. result[name] = distro
  662. return result
  663. # --------------------------------------------------------------- Linux chroot
  664. def check_setup_schroot(config):
  665. check_running_on_debian()
  666. login = os.environ.get('SUDO_USER') or get_output('logname')
  667. if not login or login == 'root':
  668. error('Unable to determine the login for which schroot access is to be given.')
  669. def build_setup_schroot(config, basedir):
  670. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring',
  671. 'build-essential', 'ruby', 'ruby-dev', 'libffi-dev', 'tar', 'xz-utils')
  672. if not get_output('which', 'fpm'):
  673. shell('gem install fpm --no-ri --no-rdoc')
  674. login = os.environ.get('SUDO_USER') or get_output('logname')
  675. target = config.split('-', 2)[2]
  676. distro = LINUX_SCHROOT_SETUP.get(target)
  677. allenv = get_chroot_list()
  678. for arch in distro['build_arch']:
  679. alias = distro.get('chroot_alias', '%s-%s' % (target, arch))
  680. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  681. root_dir = os.path.join(base_dir, 'wkhtmltox-%s' % alias)
  682. pkg_list = '%s %s' % (distro['build_packages'], distro.get('runtime_packages', ''))
  683. chroot = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  684. if alias in allenv:
  685. message('******************* %s (skipped)\n' % alias)
  686. continue
  687. message('******************* %s\n' % alias)
  688. os.system('umount %s/proc 2>/dev/null' % root_dir)
  689. os.system('umount %s/sys 2>/dev/null' % root_dir)
  690. rmdir(root_dir)
  691. mkdir_p(root_dir)
  692. def do_setup(*cmds):
  693. shell('mount -t proc proc %s/proc' % root_dir)
  694. shell('mount -t sysfs sysfs %s/sys' % root_dir)
  695. for cmd in cmds:
  696. shell('%s %s %s' % (chroot, root_dir, cmd))
  697. shell('umount %s/proc' % root_dir)
  698. shell('umount %s/sys' % root_dir)
  699. if distro['packaging_tool'] == 'apt':
  700. cfg = distro['debootstrap']
  701. shell('debootstrap --arch=%s --variant=buildd %s %s %s' % (arch, cfg[0], root_dir, cfg[1]))
  702. open(os.path.join(root_dir, 'etc/apt/sources.list'), 'w').write(cfg[2])
  703. open(os.path.join(root_dir, 'usr/sbin/policy-rc.d'), 'w').write("#!/bin/bash\nexit 101\n")
  704. do_setup('chmod a+x /usr/sbin/policy-rc.d', # hack for Ubuntu Precise
  705. 'apt-get update',
  706. 'apt-get dist-upgrade --assume-yes',
  707. 'apt-get install --assume-yes %s' % pkg_list)
  708. elif distro['packaging_tool'] == 'yum':
  709. rinse = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  710. rinse_distro, extra_repos = distro['rinse']
  711. shell('%s --arch %s --distribution %s --directory %s' % (rinse, arch, rinse_distro, root_dir))
  712. if arch == 'amd64':
  713. open(os.path.join(root_dir, 'etc/yum.conf'), 'a').write('exclude = *.i?86\n')
  714. if extra_repos:
  715. open(os.path.join(root_dir, 'etc/yum.repos.d/wkhtmltopdf.repo'), 'w').write(extra_repos)
  716. do_setup('yum clean all', 'yum update -y', 'yum install -y %s' % pkg_list)
  717. open('/etc/schroot/chroot.d/wkhtmltox', 'a').write("""
  718. [wkhtmltox-%(alias)s]
  719. type=directory
  720. directory=%(dir)s
  721. description=%(title)s for wkhtmltox
  722. users=%(login)s
  723. root-users=root
  724. %(personality)s""" % { 'alias': alias, 'dir': root_dir, 'title': distro['title'], 'login': login,
  725. 'personality': (arch == 'i386' and 'personality=linux32\n' or '\n') })
  726. def check_update_schroot(config):
  727. check_running_on_debian()
  728. if not get_chroot_list():
  729. error('Unable to determine the list of available schroots.')
  730. def build_update_schroot(config, basedir):
  731. for name, distro in get_chroot_list().iteritems():
  732. message('******************* %s\n' % name)
  733. tool = LINUX_SCHROOT_SETUP[distro]['packaging_tool']
  734. if tool == 'apt':
  735. chroot_shell(name, 'apt-get update')
  736. chroot_shell(name, 'apt-get dist-upgrade --assume-yes')
  737. elif tool == 'yum':
  738. chroot_shell(name, 'yum update -y')
  739. def check_setup_mingw_w64(config):
  740. check_running_on_debian()
  741. def build_setup_mingw_w64(config, basedir):
  742. install_packages('build-essential', 'mingw-w64', 'nsis', 'perl', 'git', 'ruby', 'gperf', 'bison', 'flex')
  743. def check_source_tarball(config):
  744. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  745. error("This can only be run inside a git checkout.")
  746. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  747. error("Please initialize and download the Qt submodule before running this.")
  748. def _filter_tar(info):
  749. name = info.name[1+info.name.index('/'):]
  750. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  751. return None
  752. info.uid = info.gid = 1000
  753. info.uname = info.gname = 'wkhtmltopdf'
  754. return info
  755. def build_source_tarball(config, basedir):
  756. version, simple_version = get_version(basedir)
  757. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  758. os.chdir(os.path.join(root_dir, 'qt'))
  759. shell('git clean -fdx')
  760. shell('git reset --hard HEAD')
  761. os.chdir(root_dir)
  762. shell('git clean -fdx')
  763. shell('git reset --hard HEAD')
  764. shell('git submodule update')
  765. open('VERSION', 'w').write(version)
  766. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  767. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  768. shell('git reset --hard HEAD')
  769. # --------------------------------------------------------------- MSVC (2013 only)
  770. MSVC_LOCATION = {
  771. 'msvc2013': ('VS120COMNTOOLS', '12.0'),
  772. 'msvc2015': ('VS140COMNTOOLS', '14.0')
  773. }
  774. MSVC_RUNTIME = {
  775. 'msvc2013-win32': ('df7f0a73bfa077e483e51bfb97f5e2eceedfb6a3', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe'),
  776. 'msvc2013-win64': ('8bf41ba9eef02d30635a10433817dbb6886da5a2', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe'),
  777. 'msvc2015-win32': ('bfb74e498c44d3a103ca3aa2831763fb417134d1', 'https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe'),
  778. 'msvc2015-win64': ('3155cb0f146b927fcc30647c1a904cd162548c8c', 'https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe')
  779. }
  780. def check_msvc(config):
  781. version, arch = rchop(config, '-dbg').split('-')
  782. env_var, _ = MSVC_LOCATION[version]
  783. if not env_var in os.environ:
  784. error("%s does not seem to be installed." % version)
  785. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  786. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  787. error("%s: unable to find vcvarsall.bat" % version)
  788. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  789. error("%s: unable to find the x86 compiler" % version)
  790. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  791. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  792. error("%s: unable to find the amd64 compiler" % version)
  793. perl = get_output('perl', '-V')
  794. if not perl or 'perl5' not in perl:
  795. error("perl does not seem to be installed.")
  796. nsis = get_registry_value(r'SOFTWARE\NSIS')
  797. if not nsis or not exists(os.path.join(nsis, 'makensis.exe')):
  798. error("NSIS does not seem to be installed.")
  799. def build_msvc(config, basedir):
  800. msvc, arch = rchop(config, '-dbg').split('-')
  801. env_var, reg_ver = MSVC_LOCATION[msvc]
  802. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  803. vcarg = 'x86'
  804. if arch == 'win64':
  805. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  806. vcarg = 'amd64'
  807. else:
  808. vcarg = 'x86_amd64'
  809. python = sys.executable
  810. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  811. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  812. stdout, _ = process.communicate()
  813. exitcode = process.wait()
  814. if exitcode != 0:
  815. error("%s: unable to initialize the environment" % msvc)
  816. os.environ.update(eval(stdout.strip()))
  817. version, simple_version = get_version(basedir)
  818. cflags = config.endswith('-dbg') and '/MDd /Zi' or '/MD'
  819. build_deplibs(config, basedir, cflags=cflags)
  820. sha1, url = MSVC_RUNTIME[rchop(config, '-dbg')]
  821. shutil.copy(download_file(url, sha1, basedir), os.path.join(basedir, config, 'vcredist.exe'))
  822. libdir = os.path.join(basedir, config, 'deplibs')
  823. qtdir = os.path.join(basedir, config, 'qt')
  824. mkdir_p(qtdir)
  825. configure_args = qt_config('msvc',
  826. '-I %s\\include' % libdir,
  827. '-L %s\\lib' % libdir,
  828. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  829. build_qt(qtdir, 'nmake', '%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  830. appdir = os.path.join(basedir, config, 'app')
  831. mkdir_p(appdir)
  832. os.chdir(appdir)
  833. rmdir('bin')
  834. mkdir_p('bin')
  835. os.environ['WKHTMLTOX_VERSION'] = version
  836. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  837. shell('nmake')
  838. if config.endswith('-dbg'):
  839. return
  840. makensis = os.path.join(get_registry_value(r'SOFTWARE\NSIS'), 'makensis.exe')
  841. os.chdir(os.path.join(basedir, '..'))
  842. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s /DMSVC=%s /DARCH=%s wkhtmltox.nsi' % \
  843. (makensis, version, nsis_version(simple_version), config, reg_ver, arch))
  844. # ------------------------------------------------ MinGW-W64 Cross Environment
  845. MINGW_W64_PREFIX = {
  846. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  847. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  848. }
  849. def check_mingw64_cross(config):
  850. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  851. def build_mingw64_cross(config, basedir):
  852. version, simple_version = get_version(basedir)
  853. build_deplibs(config, basedir, mingw_w64=MINGW_W64_PREFIX.get(rchop(config, '-dbg')))
  854. libdir = os.path.join(basedir, config, 'deplibs')
  855. qtdir = os.path.join(basedir, config, 'qt')
  856. configure_args = qt_config('mingw-w64-cross',
  857. '--prefix=%s' % qtdir,
  858. '-I%s/include' % libdir,
  859. '-L%s/lib' % libdir,
  860. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  861. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L%s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  862. mkdir_p(qtdir)
  863. os.chdir(qtdir)
  864. build_qt(qtdir, 'make -j%d' % CPU_COUNT,
  865. '%s/../qt/configure %s' % (basedir, configure_args))
  866. appdir = os.path.join(basedir, config, 'app')
  867. mkdir_p(appdir)
  868. os.chdir(appdir)
  869. shell('rm -f bin/*')
  870. # set up cross compiling prefix correctly
  871. os.environ['WKHTMLTOX_VERSION'] = version
  872. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  873. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  874. shell('make')
  875. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  876. shell('rm -f bin/lib*.dll')
  877. for dll in ['libgcc_s_sjlj-1.dll', 'libgcc_s_seh-1.dll', 'libstdc++-6.dll']:
  878. dll_path = get_output('dpkg', '-S', dll)
  879. if dll_path:
  880. for line in dll_path.split('\n'):
  881. loc = line[1+line.index(':'):].strip()
  882. if exists(loc) and MINGW_W64_PREFIX[rchop(config, '-dbg')] in loc and '-posix' not in loc:
  883. shell('cp %s bin/' % loc)
  884. if config.endswith('-dbg'):
  885. return
  886. os.chdir(os.path.join(basedir, '..'))
  887. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s -DMINGW -DARCH=%s wkhtmltox.nsi' % \
  888. (version, nsis_version(simple_version), config, rchop(config, '-dbg').split('-')[-1]))
  889. # -------------------------------------------------- Linux schroot environment
  890. def check_linux_schroot(config):
  891. chroot_shell(rchop(config, '-dbg'), 'gcc --version')
  892. def build_linux_schroot(config, basedir):
  893. os.chdir(os.path.realpath(os.path.join(basedir, '..')))
  894. chroot_shell(rchop(config, '-dbg'), 'python scripts/build.py %s -chroot-build' % ' '.join(sys.argv[1:]))
  895. version, simple_version = get_version(basedir)
  896. os.chdir(os.path.join(basedir, config))
  897. shell('fpm %s' % fpm_params(config, version))
  898. def chroot_build_linux_schroot(config, basedir):
  899. version, simple_version = get_version(basedir)
  900. qtdir = os.path.join(basedir, config, 'qt')
  901. mkdir_p(qtdir)
  902. build_qt(qtdir, 'make -j%d' % CPU_COUNT,
  903. '%s/../qt/configure %s' % (basedir, qt_config('posix', '--prefix=%s' % qtdir)))
  904. app = os.path.join(basedir, config, 'app')
  905. dist = os.path.join(basedir, config, 'dist')
  906. mkdir_p(app)
  907. mkdir_p(dist)
  908. os.chdir(app)
  909. shell('rm -f bin/*')
  910. os.environ['WKHTMLTOX_VERSION'] = version
  911. os.environ['XZ_OPT'] = '-9'
  912. shell('%s/bin/qmake %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  913. shell('make install INSTALL_ROOT=%s' % dist)
  914. def check_linux_generic(config):
  915. chroot_env = ('amd64' in config) and 'generic-amd64' or 'generic-i386'
  916. chroot_shell(chroot_env, 'gcc --version')
  917. def build_linux_generic(config, basedir):
  918. chroot_env = ('amd64' in config) and 'generic-amd64' or 'generic-i386'
  919. os.chdir(os.path.realpath(os.path.join(basedir, '..')))
  920. chroot_shell(chroot_env, 'python scripts/build.py %s -chroot-build' % ' '.join(sys.argv[1:]))
  921. if config.endswith('-dbg'):
  922. return
  923. version, simple_version = get_version(basedir)
  924. os.chdir(os.path.join(basedir, config))
  925. shell('XZ_OPT=-9 tar Jcf ../%s-%s_%s.tar.xz wkhtmltox/' % (PROJECT_SETUP['name'], version, config))
  926. def chroot_build_linux_generic(config, basedir):
  927. version, simple_version = get_version(basedir)
  928. build_deplibs(config, basedir)
  929. libdir = os.path.join(basedir, config, 'deplibs')
  930. qtdir = os.path.join(basedir, config, 'qt')
  931. mkdir_p(qtdir)
  932. configure_args = qt_config('posix',
  933. '--prefix=%s' % qtdir,
  934. '-I%s/include' % libdir,
  935. '-L%s/lib' % libdir,
  936. '-DOPENSSL_NO_SSL2')
  937. build_qt(qtdir, 'make -j%d' % CPU_COUNT, '%s/../qt/configure %s' % (basedir, configure_args))
  938. app = os.path.join(basedir, config, 'app')
  939. dist = os.path.join(basedir, config, 'wkhtmltox')
  940. mkdir_p(app)
  941. rmdir(dist)
  942. mkdir_p(dist)
  943. os.chdir(app)
  944. shell('rm -f bin/*')
  945. os.environ['WKHTMLTOX_VERSION'] = version
  946. shell('%s/bin/qmake %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  947. shell('make install INSTALL_ROOT=%s' % dist)
  948. # -------------------------------------------------- POSIX local environment
  949. def check_posix_local(config):
  950. pass
  951. def build_posix_local(config, basedir):
  952. version, simple_version = get_version(basedir)
  953. app = os.path.join(basedir, config, 'app')
  954. qt = os.path.join(basedir, config, 'qt')
  955. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  956. make = get_output('which', 'gmake') and 'gmake' or 'make'
  957. mkdir_p(qt)
  958. mkdir_p(app)
  959. rmdir(dist)
  960. mkdir_p(os.path.join(dist, 'bin'))
  961. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  962. mkdir_p(os.path.join(dist, 'lib'))
  963. build_qt(qt, '%s -j%d' % (make, CPU_COUNT),
  964. '%s/../qt/configure %s' % (basedir, qt_config('posix', '--prefix=%s' % qt)))
  965. os.chdir(app)
  966. shell('rm -f bin/*')
  967. os.environ['WKHTMLTOX_VERSION'] = version
  968. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  969. shell('%s -j%d' % (make, CPU_COUNT))
  970. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  971. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  972. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  973. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  974. if config.endswith('-dbg'):
  975. return
  976. os.chdir(os.path.join(basedir, config))
  977. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  978. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  979. # --------------------------------------------------------------- OS X
  980. OSXPKG_IDENTIFIER = 'org.wkhtmltopdf'
  981. OSXPKG_PREFIX = '/usr/local/share/wkhtmltox-installer'
  982. def check_osx(config):
  983. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  984. error('This can only be run on a OS X system!')
  985. if not get_output('xcode-select', '--print-path'):
  986. error('Xcode is not installed, aborting.')
  987. if not get_output('which', 'fpm'):
  988. error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
  989. def build_osx(config, basedir):
  990. version, simple_version = get_version(basedir)
  991. build_deplibs(config, basedir)
  992. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  993. framework = config.split('-')[1]
  994. if osxver == '10.6':
  995. osxcfg = '-%s -platform macx-g++42' % framework
  996. else:
  997. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  998. flags = ''
  999. if framework == 'carbon' and osxver != '10.6':
  1000. for item in ['CFLAGS', 'CXXFLAGS']:
  1001. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  1002. def get_dir(name):
  1003. return os.path.join(basedir, config, name)
  1004. configure_args = qt_config('osx', osxcfg,
  1005. '--prefix=%s' % get_dir('qt'),
  1006. '-I %s/include' % get_dir('deplibs'),
  1007. '-L %s/lib' % get_dir('deplibs'))
  1008. rmdir(get_dir('dist'))
  1009. rmdir(get_dir('pkg'))
  1010. mkdir_p(get_dir('qt'))
  1011. mkdir_p(get_dir('app'))
  1012. mkdir_p(get_dir('pkg'))
  1013. build_qt(get_dir('qt'), 'make -j%d' % CPU_COUNT, '../../../qt/configure %s' % configure_args)
  1014. os.chdir(get_dir('app'))
  1015. shell('rm -f bin/*')
  1016. os.environ['WKHTMLTOX_VERSION'] = version
  1017. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  1018. shell('make -j%d' % CPU_COUNT)
  1019. if osxver not in ['10.6', '10.7']:
  1020. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  1021. shell(' '.join([
  1022. 'install_name_tool', '-change',
  1023. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  1024. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  1025. 'bin/'+item]))
  1026. shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
  1027. if config.endswith('-dbg'):
  1028. return
  1029. def _osx_tar(info):
  1030. info.uid = info.gid = 0
  1031. info.uname = 'root'
  1032. info.gname = 'wheel'
  1033. return info
  1034. # create tarball for application and copy xz
  1035. os.chdir(get_dir('dist'))
  1036. with tarfile.open('../pkg/app.tar', 'w') as tar:
  1037. tar.add('.', './', filter=_osx_tar)
  1038. xz = os.path.join(get_dir('deplibs'), 'bin', 'xz')
  1039. shell('%s --compress --force --verbose -9 ../pkg/app.tar' % xz)
  1040. shutil.copy(xz, '../pkg/')
  1041. with open('../pkg/uninstall-wkhtmltox', 'w') as f:
  1042. os.chmod('../pkg/uninstall-wkhtmltox', 0o755)
  1043. f.write("""#!/bin/bash
  1044. if [ "$(id -u)" != "0" ]; then
  1045. echo "This script must be run as sudo uninstall-wkhtmltox" 1>&2
  1046. exit 1
  1047. fi
  1048. cd /usr/local
  1049. if which pkgutil >/dev/null; then
  1050. pkgutil --forget %s.%s
  1051. fi
  1052. """ % (OSXPKG_IDENTIFIER, PROJECT_SETUP['name']))
  1053. for root, dirs, files in os.walk(get_dir('dist')):
  1054. for file in files:
  1055. f.write('echo REMOVE /usr/local/%(name)s && rm -f %(name)s\n' % { 'name': os.path.relpath(os.path.join(root, file)) })
  1056. f.write('echo REMOVE /usr/local/include/wkhtmltox && rm -df /usr/local/include/wkhtmltox\n')
  1057. f.write('echo REMOVE /usr/local/bin/uninstall-wkhtmltox && rm -f /usr/local/bin/uninstall-wkhtmltox')
  1058. open('../extract.sh', 'w').write("""#!/bin/bash
  1059. TGTDIR=/usr/local
  1060. BASEDIR=%s
  1061. cd $BASEDIR
  1062. ./xz --decompress app.tar.xz
  1063. cd $TGTDIR
  1064. tar oxf $BASEDIR/app.tar
  1065. mv $BASEDIR/uninstall-wkhtmltox $TGTDIR/bin
  1066. rm -fr $BASEDIR
  1067. """ % OSXPKG_PREFIX)
  1068. os.chdir(os.path.join(basedir, config))
  1069. fpm_args = '--force --prefix %s --category utils -s dir -C pkg' % OSXPKG_PREFIX
  1070. for key in PROJECT_SETUP:
  1071. fpm_args += ' --%s "%s"' % (key, PROJECT_SETUP[key])
  1072. fpm_args += ' --osxpkg-identifier-prefix "%s" --version "%s"' % (OSXPKG_IDENTIFIER, version)
  1073. fpm_args += ' -t osxpkg --package ../%s-%s_%s.pkg' % (PROJECT_SETUP['name'], version, config)
  1074. fpm_args += ' --after-install extract.sh .'
  1075. shell('fpm %s' % fpm_args)
  1076. # --------------------------------------------------------------- command line
  1077. def usage(exit_code=2):
  1078. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  1079. opts = list(BUILDERS.keys())
  1080. opts.sort()
  1081. for opt in opts:
  1082. message('* %s\n' % opt)
  1083. sys.exit(exit_code)
  1084. def main():
  1085. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  1086. basedir = os.path.join(rootdir, 'static-build')
  1087. if not exists(os.path.join(rootdir, 'qt', 'configure')):
  1088. error('error: source code for Qt not available, cannot proceed.')
  1089. if len(sys.argv) == 1:
  1090. usage(0)
  1091. config = sys.argv[1]
  1092. if config not in BUILDERS:
  1093. usage()
  1094. for arg in sys.argv[2:]:
  1095. if not arg in ['-clean', '-debug', '-chroot-build']:
  1096. usage()
  1097. final_config = config
  1098. if '-debug' in sys.argv[2:]:
  1099. final_config += '-dbg'
  1100. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  1101. if '-clean' in sys.argv[2:]:
  1102. rmdir(os.path.join(basedir, final_config))
  1103. os.chdir(rootdir)
  1104. if '-chroot-build' in sys.argv[2:]:
  1105. globals()['chroot_build_%s' % BUILDERS[config]](final_config, basedir)
  1106. return
  1107. globals()['check_%s' % BUILDERS[config]](final_config)
  1108. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  1109. if __name__ == '__main__':
  1110. main()