build.py 49 KB

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