build.py 51 KB

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