build.py 47 KB

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