build.py 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042
  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. QT_CONFIG = {
  21. 'common' : [
  22. '-opensource',
  23. '-confirm-license',
  24. '-fast',
  25. '-release',
  26. '-static',
  27. '-graphicssystem raster',
  28. '-webkit',
  29. '-exceptions', # required by XmlPatterns
  30. '-xmlpatterns', # required for TOC support
  31. '-system-zlib',
  32. '-system-libpng',
  33. '-system-libjpeg',
  34. '-no-libmng',
  35. '-no-libtiff',
  36. '-no-accessibility',
  37. '-no-stl',
  38. '-no-qt3support',
  39. '-no-phonon',
  40. '-no-phonon-backend',
  41. '-no-opengl',
  42. '-no-declarative',
  43. '-no-script',
  44. '-no-scripttools',
  45. '-no-sql-ibase',
  46. '-no-sql-mysql',
  47. '-no-sql-odbc',
  48. '-no-sql-psql',
  49. '-no-sql-sqlite',
  50. '-no-sql-sqlite2',
  51. '-no-mmx',
  52. '-no-3dnow',
  53. '-no-sse',
  54. '-no-sse2',
  55. '-no-multimedia',
  56. '-nomake demos',
  57. '-nomake docs',
  58. '-nomake examples',
  59. '-nomake tools',
  60. '-nomake tests',
  61. '-nomake translations'
  62. ],
  63. 'msvc': [
  64. '-mp',
  65. '-qt-style-windows',
  66. '-qt-style-cleanlooks',
  67. '-no-style-windowsxp',
  68. '-no-style-windowsvista',
  69. '-no-style-plastique',
  70. '-no-style-motif',
  71. '-no-style-cde',
  72. '-openssl-linked' # static linkage for OpenSSL
  73. ],
  74. 'posix': [
  75. '-silent', # perform a silent build
  76. '-xrender', # xrender support is required
  77. '-largefile',
  78. '-no-rpath',
  79. '-openssl', # load OpenSSL binaries at runtime
  80. '-no-dbus',
  81. '-no-nis',
  82. '-no-cups',
  83. '-no-iconv',
  84. '-no-pch',
  85. '-no-gtkstyle',
  86. '-no-nas-sound',
  87. '-no-sm',
  88. '-no-xshape',
  89. '-no-xinerama',
  90. '-no-xcursor',
  91. '-no-xfixes',
  92. '-no-xrandr',
  93. '-no-mitshm',
  94. '-no-xinput',
  95. '-no-xkb',
  96. '-no-glib',
  97. '-no-gstreamer',
  98. '-D ENABLE_VIDEO=0', # required as otherwise gstreamer gets linked in
  99. '-no-openvg',
  100. '-no-xsync',
  101. '-no-audio-backend',
  102. '-no-sse3',
  103. '-no-ssse3',
  104. '-no-sse4.1',
  105. '-no-sse4.2',
  106. '-no-avx',
  107. '-no-neon'
  108. ],
  109. 'mingw-w64-cross' : [
  110. '-silent', # perform a silent build
  111. '-openssl-linked', # static linkage for OpenSSL
  112. '-no-reduce-exports',
  113. '-no-rpath',
  114. '-xplatform win32-g++-4.6'
  115. ],
  116. 'osx': [
  117. '-no-framework',
  118. '-no-dwarf2',
  119. '-xrender', # xrender support is required
  120. '-openssl', # load OpenSSL binaries at runtime
  121. '-largefile',
  122. '-no-rpath',
  123. 'remove:-system-libpng',
  124. 'remove:-system-libjpeg',
  125. '-qt-libpng',
  126. '-qt-libjpeg'
  127. ]
  128. }
  129. BUILDERS = {
  130. 'source-tarball': 'source_tarball',
  131. 'msvc2008-win32': 'msvc',
  132. 'msvc2008-win64': 'msvc',
  133. 'msvc2010-win32': 'msvc',
  134. 'msvc2010-win64': 'msvc',
  135. 'msvc2012-win32': 'msvc',
  136. 'msvc2012-win64': 'msvc',
  137. 'msvc2013-win32': 'msvc',
  138. 'msvc2013-win64': 'msvc',
  139. 'msvc-winsdk71-win32': 'msvc_winsdk71',
  140. 'msvc-winsdk71-win64': 'msvc_winsdk71',
  141. 'setup-mingw-w64': 'setup_mingw64',
  142. 'setup-schroot-centos5': 'setup_schroot',
  143. 'setup-schroot-centos6': 'setup_schroot',
  144. 'setup-schroot-wheezy': 'setup_schroot',
  145. 'setup-schroot-trusty': 'setup_schroot',
  146. 'setup-schroot-precise': 'setup_schroot',
  147. 'update-all-schroots': 'update_schroot',
  148. 'centos5-i386': 'linux_schroot',
  149. 'centos5-amd64': 'linux_schroot',
  150. 'centos6-i386': 'linux_schroot',
  151. 'centos6-amd64': 'linux_schroot',
  152. 'wheezy-i386': 'linux_schroot',
  153. 'wheezy-amd64': 'linux_schroot',
  154. 'trusty-i386': 'linux_schroot',
  155. 'trusty-amd64': 'linux_schroot',
  156. 'precise-i386': 'linux_schroot',
  157. 'precise-amd64': 'linux_schroot',
  158. 'mingw-w64-cross-win32': 'mingw64_cross',
  159. 'mingw-w64-cross-win64': 'mingw64_cross',
  160. 'posix-local': 'posix_local',
  161. 'osx-cocoa-x86-64': 'osx',
  162. 'osx-carbon-i386': 'osx'
  163. }
  164. CHROOT_SETUP = {
  165. 'wheezy': [
  166. ('debootstrap', 'wheezy', 'http://ftp.us.debian.org/debian/'),
  167. ('write_file', 'etc/apt/sources.list', """
  168. deb http://ftp.debian.org/debian/ wheezy main contrib non-free
  169. deb http://ftp.debian.org/debian/ wheezy-updates main contrib non-free
  170. deb http://security.debian.org/ wheezy/updates main contrib non-free"""),
  171. ('shell', 'apt-get update'),
  172. ('shell', 'apt-get dist-upgrade --assume-yes'),
  173. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  174. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  175. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  176. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  177. ('schroot_conf', 'Debian Wheezy')
  178. ],
  179. 'trusty': [
  180. ('debootstrap', 'trusty', 'http://archive.ubuntu.com/ubuntu/'),
  181. ('write_file', 'etc/apt/sources.list', """
  182. deb http://archive.ubuntu.com/ubuntu/ trusty main restricted universe multiverse
  183. deb http://archive.ubuntu.com/ubuntu/ trusty-updates main restricted universe multiverse
  184. deb http://archive.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse"""),
  185. ('shell', 'apt-get update'),
  186. ('shell', 'apt-get dist-upgrade --assume-yes'),
  187. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg-turbo8-dev zlib1g-dev ruby-dev'),
  188. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  189. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  190. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  191. ('schroot_conf', 'Ubuntu Trusty')
  192. ],
  193. 'precise': [
  194. ('debootstrap', 'precise', 'http://archive.ubuntu.com/ubuntu/'),
  195. ('write_file', 'etc/apt/sources.list', """
  196. deb http://archive.ubuntu.com/ubuntu/ precise main restricted universe multiverse
  197. deb http://archive.ubuntu.com/ubuntu/ precise-updates main restricted universe multiverse
  198. deb http://archive.ubuntu.com/ubuntu/ precise-security main restricted universe multiverse"""),
  199. ('shell', 'apt-get update'),
  200. ('shell', 'apt-get dist-upgrade --assume-yes'),
  201. ('shell', 'apt-get install --assume-yes xz-utils libssl-dev libpng-dev libjpeg8-dev zlib1g-dev rubygems'),
  202. ('shell', 'apt-get install --assume-yes libfontconfig1-dev libfreetype6-dev libx11-dev libxext-dev libxrender-dev'),
  203. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  204. ('write_file', 'update.sh', 'apt-get update\napt-get dist-upgrade --assume-yes\n'),
  205. ('schroot_conf', 'Ubuntu Precise')
  206. ],
  207. 'centos5': [
  208. ('rinse', 'centos-5'),
  209. ('download_file', 'http://centos.karan.org/el5/ruby187/kbs-el5-ruby187.repo', 'etc/yum.repos.d'),
  210. ('download_file', 'http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm', 'tmp'),
  211. ('shell', 'rpm -i /tmp/epel-release-5-4.noarch.rpm'),
  212. ('shell', 'yum update -y'),
  213. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  214. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl xz ruby-devel rubygems rpm-build libffi-devel'),
  215. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  216. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  217. ('write_file', 'update.sh', 'yum update -y\n'),
  218. ('schroot_conf', 'CentOS 5')
  219. ],
  220. 'centos6': [
  221. ('rinse', 'centos-6'),
  222. ('shell', 'yum update -y'),
  223. ('append_file:amd64', 'etc/yum.conf', 'exclude = *.i?86\n'),
  224. ('shell', 'yum install -y gcc gcc-c++ make diffutils perl tar xz ruby-devel rubygems rpm-build libffi-devel'),
  225. ('shell', 'yum install -y openssl-devel libX11-devel libXrender-devel libXext-devel fontconfig-devel freetype-devel libjpeg-devel libpng-devel zlib-devel'),
  226. ('shell', 'gem install fpm ronn --no-ri --no-rdoc'),
  227. ('write_file', 'update.sh', 'yum update -y\n'),
  228. ('schroot_conf', 'CentOS 6')
  229. ]
  230. }
  231. DEPENDENT_LIBS = {
  232. 'openssl': {
  233. 'order' : 1,
  234. 'url' : 'http://www.openssl.org/source/openssl-1.0.1h.tar.gz',
  235. 'sha1' : 'b2239599c8bf8f7fc48590a55205c26abe560bf8',
  236. 'build' : {
  237. 'msvc*-win32*': {
  238. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  239. 'commands': [
  240. 'perl Configure --openssldir=%(destdir)s VC-WIN32 no-asm',
  241. 'ms\\do_ms.bat',
  242. 'nmake /f ms\\nt.mak install'],
  243. },
  244. 'msvc*-win64*': {
  245. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  246. 'commands': [
  247. 'perl Configure --openssldir=%(destdir)s VC-WIN64A',
  248. 'ms\\do_win64a.bat',
  249. 'nmake /f ms\\nt.mak install']
  250. },
  251. 'mingw-w64-cross-win*': {
  252. 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
  253. 'commands': [
  254. 'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw-w64)s- no-shared no-asm mingw64',
  255. 'make',
  256. 'make install_sw']
  257. }
  258. }
  259. },
  260. 'zlib': {
  261. 'order' : 2,
  262. 'url' : 'http://downloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz',
  263. 'sha1' : 'a4d316c404ff54ca545ea71a27af7dbc29817088',
  264. 'build' : {
  265. 'msvc*': {
  266. 'result': {
  267. 'include/zlib.h' : 'zlib.h',
  268. 'include/zconf.h': 'zconf.h',
  269. 'lib/zdll.lib' : 'zlib.lib'
  270. },
  271. 'replace': [('win32/Makefile.msc', '-MD', '-MT')],
  272. 'commands': ['nmake /f win32/Makefile.msc zlib.lib']
  273. },
  274. 'mingw-w64-cross-win*': {
  275. 'result': {
  276. 'include/zlib.h' : 'zlib.h',
  277. 'include/zconf.h': 'zconf.h',
  278. 'lib/libz.a' : 'libz.a'
  279. },
  280. 'replace': [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw-w64)s-')],
  281. 'commands': ['make -f win32/Makefile.gcc']
  282. }
  283. }
  284. },
  285. 'libpng': {
  286. 'order' : 3,
  287. 'url' : 'http://downloads.sourceforge.net/libpng/libpng-1.5.18.tar.gz',
  288. 'sha1': '7ddf6865aa70d2d79faf65ebc611919a0b573654',
  289. 'build' : {
  290. 'msvc*': {
  291. 'result': {
  292. 'include/png.h' : 'png.h',
  293. 'include/pngconf.h' : 'pngconf.h',
  294. 'include/pnglibconf.h': 'pnglibconf.h',
  295. 'lib/libpng.lib' : 'libpng.lib'
  296. },
  297. 'replace': [
  298. ('scripts/makefile.vcwin32', '-MD', '-MT'),
  299. ('scripts/makefile.vcwin32', '-I..\\zlib', '-I..\\deplibs\\include'),
  300. ('scripts/makefile.vcwin32', '..\\zlib\\zlib.lib', '..\\deplibs\\lib\\zdll.lib')],
  301. 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
  302. },
  303. 'mingw-w64-cross-win*': {
  304. 'result': {
  305. 'include/png.h' : 'png.h',
  306. 'include/pngconf.h' : 'pngconf.h',
  307. 'include/pnglibconf.h': 'pnglibconf.h',
  308. 'lib/libpng.a' : 'libpng.a'
  309. },
  310. 'replace': [
  311. ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
  312. ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
  313. ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw-w64)s-gcc'),
  314. ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw-w64)s-ar'),
  315. ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw-w64)s-ranlib')],
  316. 'commands': ['make -f scripts/makefile.gcc libpng.a']
  317. }
  318. }
  319. },
  320. 'libjpeg': {
  321. 'order' : 4,
  322. 'url' : 'http://ijg.org/files/jpegsrc.v9a.tar.gz',
  323. 'sha1': 'd65ed6f88d318f7380a3a5f75d578744e732daca',
  324. 'build' : {
  325. 'msvc*': {
  326. 'result': {
  327. 'include/jpeglib.h' : 'jpeglib.h',
  328. 'include/jmorecfg.h': 'jmorecfg.h',
  329. 'include/jerror.h' : 'jerror.h',
  330. 'include/jconfig.h' : 'jconfig.h',
  331. 'lib/libjpeg.lib' : 'libjpeg.lib'
  332. },
  333. 'replace': [('makefile.vc', '!include <win32.mak>', ''),
  334. ('makefile.vc', '$(cc)', 'cl'),
  335. ('makefile.vc', '$(cflags) $(cdebug) $(cvars)', '-c -nologo -D_CRT_SECURE_NO_DEPRECATE -MT -O2 -W3')],
  336. 'commands': [
  337. 'copy /y jconfig.vc jconfig.h',
  338. 'nmake /f makefile.vc libjpeg.lib']
  339. },
  340. 'mingw-w64-cross-win*': {
  341. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  342. 'commands': [
  343. './configure --host=%(mingw-w64)s --disable-shared --prefix=%(destdir)s',
  344. 'make install']
  345. }
  346. }
  347. }
  348. }
  349. EXCLUDE_SRC_TARBALL = [
  350. 'qt/config.profiles*',
  351. 'qt/demos*',
  352. 'qt/dist*',
  353. 'qt/doc*',
  354. 'qt/examples*',
  355. 'qt/imports*',
  356. 'qt/templates*',
  357. 'qt/tests*',
  358. 'qt/translations*',
  359. 'qt/util*',
  360. 'qt/lib/fonts*',
  361. 'qt/src/3rdparty/*ChangeLog*',
  362. 'qt/src/3rdparty/ce-compat*',
  363. 'qt/src/3rdparty/clucene*',
  364. 'qt/src/3rdparty/fonts*',
  365. 'qt/src/3rdparty/freetype*',
  366. 'qt/src/3rdparty/javascriptcore*',
  367. 'qt/src/3rdparty/libgq*',
  368. 'qt/src/3rdparty/libmng*',
  369. 'qt/src/3rdparty/libtiff*',
  370. 'qt/src/3rdparty/patches*',
  371. 'qt/src/3rdparty/phonon*',
  372. 'qt/src/3rdparty/pixman*',
  373. 'qt/src/3rdparty/powervr*',
  374. 'qt/src/3rdparty/ptmalloc*',
  375. 'qt/src/3rdparty/s60*',
  376. 'qt/src/3rdparty/wayland*'
  377. ]
  378. # --------------------------------------------------------------- HELPERS
  379. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  380. from os.path import exists
  381. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  382. def rchop(s, e):
  383. if s.endswith(e):
  384. return s[:-len(e)]
  385. return s
  386. def message(msg):
  387. sys.stdout.write(msg)
  388. sys.stdout.flush()
  389. def error(msg):
  390. message(msg+'\n')
  391. sys.exit(1)
  392. def shell(cmd):
  393. ret = os.system(cmd)
  394. if ret != 0:
  395. error("command failed: exit code %d" % ret)
  396. def get_output(*cmd):
  397. try:
  398. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  399. except:
  400. return None
  401. def rmdir(path):
  402. if exists(path):
  403. if platform.system() == 'Windows':
  404. shell('attrib -R %s\* /S' % path)
  405. shutil.rmtree(path)
  406. def mkdir_p(path):
  407. if not exists(path):
  408. os.makedirs(path)
  409. def get_version(basedir):
  410. mkdir_p(basedir)
  411. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  412. if '-' not in text:
  413. return (text, text)
  414. version = text[:text.index('-')]
  415. os.chdir(os.path.join(basedir, '..'))
  416. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  417. if not hash:
  418. return (text, version)
  419. return ('%s-%s' % (version, hash), version)
  420. def qt_config(key, *opts):
  421. input, output = [], []
  422. input.extend(QT_CONFIG['common'])
  423. input.extend(QT_CONFIG[key])
  424. input.extend(opts)
  425. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  426. if cfg:
  427. input.extend(cfg.split())
  428. for arg in input:
  429. if not arg.startswith('remove:-'):
  430. output.append(arg)
  431. elif arg[1+arg.index(':'):] in output:
  432. output.remove(arg[1+arg.index(':'):])
  433. return ' '.join(output)
  434. def download_file(url, sha1, dir):
  435. name = url.split('/')[-1]
  436. loc = os.path.join(dir, name)
  437. if os.path.exists(loc):
  438. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  439. if hash == sha1:
  440. return loc
  441. os.remove(loc)
  442. message('Checksum mismatch for %s, re-downloading.\n' % name)
  443. def hook(cnt, bs, total):
  444. pct = int(cnt*bs*100/total)
  445. message("\rDownloading: %s [%d%%]" % (name, pct))
  446. urllib.urlretrieve(url, loc, reporthook=hook)
  447. message("\r")
  448. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  449. if hash != sha1:
  450. os.remove(loc)
  451. error('Checksum mismatch for %s, aborting.' % name)
  452. message("\rDownloaded: %s [checksum OK]\n" % name)
  453. return loc
  454. def download_tarball(url, sha1, dir, name):
  455. loc = download_file(url, sha1, dir)
  456. tar = tarfile.open(loc)
  457. sub = tar.getnames()[0]
  458. if '/' in sub:
  459. sub = sub[:sub.index('/')]
  460. src = os.path.join(dir, sub)
  461. tgt = os.path.join(dir, name)
  462. rmdir(src)
  463. tar.extractall(dir)
  464. rmdir(tgt)
  465. os.rename(src, tgt)
  466. return tgt
  467. def _is_compiled(dst, loc):
  468. present = True
  469. for name in loc['result']:
  470. present = present and exists(os.path.join(dst, name))
  471. return present
  472. def build_deplibs(config, basedir):
  473. mkdir_p(os.path.join(basedir, config))
  474. dstdir = os.path.join(basedir, config, 'deplibs')
  475. vars = {'destdir': dstdir, 'mingw-w64': MINGW_W64_PREFIX.get(rchop(config, '-dbg'), '')}
  476. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  477. cfg = None
  478. for key in DEPENDENT_LIBS[lib]['build']:
  479. if fnmatch.fnmatch(config, key):
  480. cfg = key
  481. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  482. continue
  483. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  484. message('========== building: %s\n' % lib)
  485. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  486. basedir, os.path.join(config, lib))
  487. for location, source, target in build_cfg.get('replace', []):
  488. data = open(os.path.join(srcdir, location), 'r').read()
  489. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  490. os.chdir(srcdir)
  491. for command in build_cfg['commands']:
  492. shell(command % vars)
  493. if not type(build_cfg['result']) is list:
  494. for target in build_cfg['result']:
  495. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  496. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  497. os.chdir(dstdir)
  498. if not _is_compiled(dstdir, build_cfg):
  499. error("Unable to compile %s for your system, aborting." % lib)
  500. rmdir(srcdir)
  501. def check_running_on_debian():
  502. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  503. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  504. if os.geteuid() != 0:
  505. error('This script must be run as root.')
  506. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  507. ARCH.insert(0, 'amd64')
  508. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  509. def install_packages(*names):
  510. lines = get_output('dpkg-query', '--list').split('\n')
  511. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  512. inst = [name for name in names if name in avail]
  513. if len(inst) != len(names):
  514. shell('apt-get update')
  515. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  516. # --------------------------------------------------------------- Linux chroot
  517. ARCH = ['i386']
  518. def check_setup_schroot(config):
  519. check_running_on_debian()
  520. login = os.environ.get('SUDO_USER') or get_output('logname')
  521. if not login or login == 'root':
  522. error('Unable to determine the login for which schroot access is to be given.')
  523. def build_setup_schroot(config, basedir):
  524. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  525. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  526. login = os.environ.get('SUDO_USER') or get_output('logname')
  527. chroot = config[1+config.rindex('-'):]
  528. for arch in ARCH:
  529. message('******************* %s-%s\n' % (chroot, arch))
  530. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  531. root_dir = os.path.join(base_dir, 'wkhtmltopdf-%s-%s' % (chroot, arch))
  532. rmdir(root_dir)
  533. mkdir_p(root_dir)
  534. for command in CHROOT_SETUP[chroot]:
  535. # handle architecture-specific commands
  536. name = command[0]
  537. if ':' in name:
  538. if name[1+name.rindex(':'):] != arch:
  539. continue
  540. else:
  541. name = name[:name.rindex(':')]
  542. # handle commands
  543. if name == 'debootstrap':
  544. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  545. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  546. elif name == 'rinse':
  547. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  548. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  549. elif name == 'shell':
  550. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  551. shell('%s %s %s' % (cmd, root_dir, command[1]))
  552. elif name == 'write_file':
  553. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  554. elif name == 'append_file':
  555. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  556. elif name == 'download_file':
  557. name = command[1].split('/')[-1]
  558. loc = os.path.join(root_dir, command[2], name)
  559. if exists(loc): os.remove(loc)
  560. def hook(cnt, bs, total):
  561. pct = int(cnt*bs*100/total)
  562. message("\rDownloading: %s [%d%%]" % (name, pct))
  563. urllib.urlretrieve(command[1], loc, reporthook=hook)
  564. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  565. elif name == 'schroot_conf':
  566. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
  567. cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))
  568. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  569. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  570. cfg.write('users=%s\nroot-users=root\n' % login)
  571. if arch == 'i386' and 'amd64' in ARCH:
  572. cfg.write('personality=linux32\n')
  573. cfg.close()
  574. def check_update_schroot(config):
  575. check_running_on_debian()
  576. if not get_output('schroot', '--list'):
  577. error('Unable to determine the list of available schroots.')
  578. def build_update_schroot(config, basedir):
  579. for name in get_output('schroot', '--list').split('\n'):
  580. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  581. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  582. def check_setup_mingw64(config):
  583. check_running_on_debian()
  584. def build_setup_mingw64(config, basedir):
  585. install_packages('build-essential', 'mingw-w64', 'nsis')
  586. def check_source_tarball(config):
  587. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  588. error("This can only be run inside a git checkout.")
  589. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  590. error("Please initialize and download the Qt submodule before running this.")
  591. def _filter_tar(info):
  592. name = info.name[1+info.name.index('/'):]
  593. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  594. return None
  595. info.uid = info.gid = 1000
  596. info.uname = info.gname = 'wkhtmltopdf'
  597. return info
  598. def build_source_tarball(config, basedir):
  599. version, simple_version = get_version(basedir)
  600. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  601. os.chdir(os.path.join(root_dir, 'qt'))
  602. shell('git clean -fdx')
  603. shell('git reset --hard HEAD')
  604. os.chdir(root_dir)
  605. shell('git clean -fdx')
  606. shell('git reset --hard HEAD')
  607. shell('git submodule update')
  608. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  609. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  610. # --------------------------------------------------------------- MSVC (2008-2013)
  611. MSVC_LOCATION = {
  612. 'msvc2008': 'VS90COMNTOOLS',
  613. 'msvc2010': 'VS100COMNTOOLS',
  614. 'msvc2012': 'VS110COMNTOOLS',
  615. 'msvc2013': 'VS120COMNTOOLS'
  616. }
  617. def check_msvc(config):
  618. version, arch = rchop(config, '-dbg').split('-')
  619. env_var = MSVC_LOCATION[version]
  620. if not env_var in os.environ:
  621. error("%s does not seem to be installed." % version)
  622. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  623. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  624. error("%s: unable to find vcvarsall.bat" % version)
  625. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  626. error("%s: unable to find the x86 compiler" % version)
  627. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  628. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  629. error("%s: unable to find the amd64 compiler" % version)
  630. def build_msvc(config, basedir):
  631. msvc, arch = rchop(config, '-dbg').split('-')
  632. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  633. vcarg = 'x86'
  634. if arch == 'win64':
  635. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  636. vcarg = 'amd64'
  637. else:
  638. vcarg = 'x86_amd64'
  639. python = sys.executable
  640. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  641. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  642. stdout, _ = process.communicate()
  643. exitcode = process.wait()
  644. if exitcode != 0:
  645. error("%s: unable to initialize the environment" % msvc)
  646. os.environ.update(eval(stdout.strip()))
  647. build_msvc_common(config, basedir)
  648. # --------------------------------------------------------------- MSVC via Windows SDK 7.1
  649. def check_msvc_winsdk71(config):
  650. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  651. if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
  652. return
  653. error("Unable to detect the location of Windows SDK 7.1")
  654. def build_msvc_winsdk71(config, basedir):
  655. arch = config[config.rindex('-'):]
  656. setenv = None
  657. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  658. if not pfile in os.environ:
  659. continue
  660. setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
  661. mode = debug and '/Debug' or '/Release'
  662. if arch == 'win64':
  663. args = '/2008 /x64 %s' % mode
  664. else:
  665. args = '/2008 /x86 %s' % mode
  666. python = sys.executable
  667. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  668. setenv, args, python), stdout=subprocess.PIPE, shell=True)
  669. stdout, _ = process.communicate()
  670. exitcode = process.wait()
  671. if exitcode != 0:
  672. error("unable to initialize the environment for Windows SDK 7.1")
  673. os.environ.update(eval(stdout.strip()))
  674. build_msvc_common(config, basedir)
  675. def build_msvc_common(config, basedir):
  676. version, simple_version = get_version(basedir)
  677. build_deplibs(config, basedir)
  678. libdir = os.path.join(basedir, config, 'deplibs')
  679. qtdir = os.path.join(basedir, config, 'qt')
  680. mkdir_p(qtdir)
  681. configure_args = qt_config('msvc',
  682. '-I %s\\include' % libdir,
  683. '-L %s\\lib' % libdir,
  684. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  685. os.chdir(qtdir)
  686. if not exists('is_configured'):
  687. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  688. open('is_configured', 'w').write('')
  689. shell('nmake')
  690. appdir = os.path.join(basedir, config, 'app')
  691. mkdir_p(appdir)
  692. os.chdir(appdir)
  693. rmdir('bin')
  694. mkdir_p('bin')
  695. os.environ['WKHTMLTOX_VERSION'] = version
  696. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  697. shell('nmake')
  698. found = False
  699. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  700. if not pfile in os.environ or not exists(os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')):
  701. continue
  702. found = True
  703. makensis = os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')
  704. os.chdir(os.path.join(basedir, '..'))
  705. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s wkhtmltox.nsi' % \
  706. (makensis, version, simple_version, config))
  707. if not found:
  708. message("\n\nCould not build installer as NSIS was not found.\n")
  709. # ------------------------------------------------ MinGW-W64 Cross Environment
  710. MINGW_W64_PREFIX = {
  711. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  712. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  713. }
  714. def check_mingw64_cross(config):
  715. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  716. def build_mingw64_cross(config, basedir):
  717. version, simple_version = get_version(basedir)
  718. build_deplibs(config, basedir)
  719. libdir = os.path.join(basedir, config, 'deplibs')
  720. qtdir = os.path.join(basedir, config, 'qt')
  721. configure_args = qt_config('mingw-w64-cross',
  722. '--prefix=%s' % qtdir,
  723. '-I %s/include' % libdir,
  724. '-L %s/lib' % libdir,
  725. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  726. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  727. mkdir_p(qtdir)
  728. os.chdir(qtdir)
  729. if not exists('is_configured'):
  730. for var in ['CFLAGS', 'CXXFLAGS']:
  731. os.environ[var] = '-w'
  732. shell('%s/../qt/configure %s' % (basedir, configure_args))
  733. shell('touch is_configured')
  734. shell('make -j%d' % CPU_COUNT)
  735. appdir = os.path.join(basedir, config, 'app')
  736. mkdir_p(appdir)
  737. os.chdir(appdir)
  738. shell('rm -f bin/*')
  739. # set up cross compiling prefix correctly
  740. os.environ['WKHTMLTOX_VERSION'] = version
  741. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  742. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  743. shell('make')
  744. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  745. os.chdir(os.path.join(basedir, '..'))
  746. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s wkhtmltox.nsi' % \
  747. (version, simple_version, config))
  748. # -------------------------------------------------- Linux schroot environment
  749. def check_linux_schroot(config):
  750. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  751. def build_linux_schroot(config, basedir):
  752. version, simple_version = get_version(basedir)
  753. dir = os.path.join(basedir, config)
  754. script = os.path.join(dir, 'build.sh')
  755. dist = os.path.join(dir, 'wkhtmltox-%s' % version)
  756. mkdir_p(dir)
  757. rmdir(dist)
  758. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  759. lines = ['#!/bin/bash']
  760. lines.append('# start of autogenerated build script')
  761. lines.append('mkdir -p app qt')
  762. lines.append('cd qt')
  763. if config == 'centos5-i386':
  764. lines.append('export CFLAGS="-march=i486 -w"')
  765. lines.append('export CXXFLAGS="-march=i486 -w"')
  766. else:
  767. for var in ['CFLAGS', 'CXXFLAGS']:
  768. lines.append('export %s="-w"' % var)
  769. lines.append('if [ ! -f is_configured ]; then')
  770. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  771. lines.append(' touch is_configured')
  772. lines.append('fi')
  773. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  774. lines.append('cd ../app')
  775. lines.append('rm -f bin/*')
  776. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  777. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  778. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  779. lines.append('cd ..')
  780. lines.append('tar -c -v -f ../wkhtmltox-%s_linux-%s.tar wkhtmltox-%s/' % (version, config, version))
  781. lines.append('xz --compress --force --verbose -9 ../wkhtmltox-%s_linux-%s.tar' % (version, config))
  782. lines.append('# end of build script')
  783. open(script, 'w').write('\n'.join(lines))
  784. os.chdir(dir)
  785. shell('chmod +x build.sh')
  786. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  787. # -------------------------------------------------- POSIX local environment
  788. def check_posix_local(config):
  789. pass
  790. def build_posix_local(config, basedir):
  791. version, simple_version = get_version(basedir)
  792. app = os.path.join(basedir, config, 'app')
  793. qtdir = os.path.join(basedir, config, 'qt')
  794. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  795. make = get_output('which gmake') and 'gmake' or 'make'
  796. mkdir_p(qt)
  797. mkdir_p(app)
  798. rmdir(dist)
  799. mkdir_p(os.path.join(dist, 'bin'))
  800. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  801. mkdir_p(os.path.join(dist, 'lib'))
  802. os.chdir(qt)
  803. if not exists('is_configured'):
  804. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qtdir))
  805. shell('touch is_configured')
  806. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  807. shell('%s -j%d' % (make, CPU_COUNT))
  808. os.chdir(app)
  809. shell('rm -f bin/*')
  810. os.environ['WKHTMLTOX_VERSION'] = version
  811. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  812. shell('%s -j%d' % (make, CPU_COUNT))
  813. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  814. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  815. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  816. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  817. os.chdir(basedir)
  818. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  819. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  820. # --------------------------------------------------------------- OS X
  821. def check_osx(config):
  822. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  823. error('This can only be run on a OS X system!')
  824. if not get_output('xcode-select', '--print-path'):
  825. error('Xcode is not installed, aborting.')
  826. def build_osx(config, basedir):
  827. version, simple_version = get_version(basedir)
  828. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  829. framework = config.split('-')[1]
  830. if osxver == '10.6':
  831. osxcfg = '-%s -platform macx-g++42' % framework
  832. else:
  833. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  834. flags = ''
  835. if framework == 'carbon' and osxver != '10.6':
  836. for item in ['CFLAGS', 'CXXFLAGS']:
  837. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  838. qt = os.path.join(basedir, config, 'qt')
  839. app = os.path.join(basedir, config, 'app')
  840. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  841. mkdir_p(qt)
  842. mkdir_p(app)
  843. rmdir(dist)
  844. mkdir_p(os.path.join(dist, 'bin'))
  845. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  846. mkdir_p(os.path.join(dist, 'lib'))
  847. os.chdir(qt)
  848. if not exists('is_configured'):
  849. shell('../../../qt/configure %s' % qt_config('osx', '--prefix=%s' % qt, osxcfg))
  850. shell('touch is_configured')
  851. shell('make -j%d' % CPU_COUNT)
  852. os.chdir(app)
  853. shell('rm -f bin/*')
  854. os.environ['WKHTMLTOX_VERSION'] = version
  855. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  856. shell('make -j%d' % CPU_COUNT)
  857. if osxver not in ['10.6', '10.7']:
  858. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  859. shell(' '.join([
  860. 'install_name_tool', '-change',
  861. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  862. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  863. 'bin/'+item]))
  864. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  865. shell('cp -P bin/libwkhtmltox*.dylib* ../wkhtmltox-%s/lib' % version)
  866. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  867. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  868. os.chdir(os.path.join(basedir, config))
  869. shell('tar -c -v -f ../wkhtmltox-%s_%s.tar wkhtmltox-%s/' % (version, config, version))
  870. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_%s.tar' % (version, config))
  871. # --------------------------------------------------------------- command line
  872. def usage(exit_code=2):
  873. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  874. opts = list(BUILDERS.keys())
  875. opts.sort()
  876. for opt in opts:
  877. message('* %s\n' % opt)
  878. sys.exit(exit_code)
  879. def main():
  880. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  881. basedir = os.path.join(rootdir, 'static-build')
  882. if len(sys.argv) == 1:
  883. usage(0)
  884. config = sys.argv[1]
  885. if config not in BUILDERS:
  886. usage()
  887. for arg in sys.argv[2:]:
  888. if not arg in ['-clean', '-debug']:
  889. usage()
  890. final_config = config
  891. if '-debug' in sys.argv[2:]:
  892. final_config += '-dbg'
  893. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  894. if '-clean' in sys.argv[2:]:
  895. rmdir(os.path.join(basedir, config))
  896. os.chdir(rootdir)
  897. globals()['check_%s' % BUILDERS[config]](final_config)
  898. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  899. if __name__ == '__main__':
  900. main()