build.py 49 KB

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