build.py 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  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_mingw64',
  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. }
  340. DEPENDENT_LIBS = {
  341. 'openssl': {
  342. 'order' : 1,
  343. 'url' : 'https://www.openssl.org/source/openssl-1.0.1j.tar.gz',
  344. 'sha1' : 'cff86857507624f0ad42d922bb6f77c4f1c2b819',
  345. 'build' : {
  346. 'msvc*-win32*': {
  347. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  348. 'replace': [('util/pl/VC-32.pl', ' /MT', ' /MD')],
  349. 'commands': [
  350. 'perl Configure --openssldir=%(destdir)s VC-WIN32 no-asm',
  351. 'ms\\do_ms.bat',
  352. 'nmake /f ms\\nt.mak install'],
  353. },
  354. 'msvc*-win64*': {
  355. 'result': ['include/openssl/ssl.h', 'lib/ssleay32.lib', 'lib/libeay32.lib'],
  356. 'replace': [('util/pl/VC-32.pl', ' /MT', ' /MD')],
  357. 'commands': [
  358. 'perl Configure --openssldir=%(destdir)s VC-WIN64A',
  359. 'ms\\do_win64a.bat',
  360. 'nmake /f ms\\nt.mak install']
  361. },
  362. 'mingw-w64-cross-win*': {
  363. 'result': ['include/openssl/ssl.h', 'lib/libssl.a', 'lib/libcrypto.a'],
  364. 'commands': [
  365. 'perl Configure --openssldir=%(destdir)s --cross-compile-prefix=%(mingw_w64)s- no-shared no-asm mingw64',
  366. 'make',
  367. 'make install_sw']
  368. }
  369. }
  370. },
  371. 'zlib': {
  372. 'order' : 2,
  373. 'url' : 'http://downloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz',
  374. 'sha1' : 'a4d316c404ff54ca545ea71a27af7dbc29817088',
  375. 'build' : {
  376. 'msvc*': {
  377. 'result': {
  378. 'include/zlib.h' : 'zlib.h',
  379. 'include/zconf.h': 'zconf.h',
  380. 'lib/zdll.lib' : 'zlib.lib'
  381. },
  382. 'commands': ['nmake /f win32/Makefile.msc zlib.lib']
  383. },
  384. 'mingw-w64-cross-win*': {
  385. 'result': {
  386. 'include/zlib.h' : 'zlib.h',
  387. 'include/zconf.h': 'zconf.h',
  388. 'lib/libz.a' : 'libz.a'
  389. },
  390. 'replace': [('win32/Makefile.gcc', 'PREFIX =', 'PREFIX = %(mingw_w64)s-')],
  391. 'commands': ['make -f win32/Makefile.gcc']
  392. }
  393. }
  394. },
  395. 'libpng': {
  396. 'order' : 3,
  397. 'url' : 'http://downloads.sourceforge.net/libpng/libpng-1.5.19.tar.gz',
  398. 'sha1': 'c4cacb5512fab1f0b6e5673766b0d89669205756',
  399. 'build' : {
  400. 'msvc*': {
  401. 'result': {
  402. 'include/png.h' : 'png.h',
  403. 'include/pngconf.h' : 'pngconf.h',
  404. 'include/pnglibconf.h': 'pnglibconf.h',
  405. 'lib/libpng.lib' : 'libpng.lib'
  406. },
  407. 'replace': [
  408. ('scripts/makefile.vcwin32', '-I..\\zlib', '-I..\\deplibs\\include'),
  409. ('scripts/makefile.vcwin32', '..\\zlib\\zlib.lib', '..\\deplibs\\lib\\zdll.lib')],
  410. 'commands': ['nmake /f scripts/makefile.vcwin32 libpng.lib']
  411. },
  412. 'mingw-w64-cross-win*': {
  413. 'result': {
  414. 'include/png.h' : 'png.h',
  415. 'include/pngconf.h' : 'pngconf.h',
  416. 'include/pnglibconf.h': 'pnglibconf.h',
  417. 'lib/libpng.a' : 'libpng.a'
  418. },
  419. 'replace': [
  420. ('scripts/makefile.gcc', 'ZLIBINC = ../zlib', 'ZLIBINC = %(destdir)s/include'),
  421. ('scripts/makefile.gcc', 'ZLIBLIB = ../zlib', 'ZLIBLIB = %(destdir)s/lib'),
  422. ('scripts/makefile.gcc', 'CC = gcc', 'CC = %(mingw_w64)s-gcc'),
  423. ('scripts/makefile.gcc', 'AR_RC = ar', 'AR_RC = %(mingw_w64)s-ar'),
  424. ('scripts/makefile.gcc', 'RANLIB = ranlib', 'RANLIB = %(mingw_w64)s-ranlib')],
  425. 'commands': ['make -f scripts/makefile.gcc libpng.a']
  426. },
  427. 'osx-carbon-i386': {
  428. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  429. 'commands': [
  430. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  431. 'make install']
  432. },
  433. 'osx-cocoa-x86-64': {
  434. 'result': ['include/png.h', 'include/pngconf.h', 'include/pnglibconf.h', 'lib/libpng.a'],
  435. 'commands': [
  436. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  437. 'make install']
  438. }
  439. }
  440. },
  441. 'libjpeg': {
  442. 'order' : 4,
  443. 'url' : 'http://ijg.org/files/jpegsrc.v9a.tar.gz',
  444. 'sha1': 'd65ed6f88d318f7380a3a5f75d578744e732daca',
  445. 'build' : {
  446. 'msvc*': {
  447. 'result': {
  448. 'include/jpeglib.h' : 'jpeglib.h',
  449. 'include/jmorecfg.h': 'jmorecfg.h',
  450. 'include/jerror.h' : 'jerror.h',
  451. 'include/jconfig.h' : 'jconfig.h',
  452. 'lib/libjpeg.lib' : 'libjpeg.lib'
  453. },
  454. 'replace': [('makefile.vc', '!include <win32.mak>', ''),
  455. ('makefile.vc', '$(cc)', 'cl'),
  456. ('makefile.vc', '$(cflags) $(cdebug) $(cvars)', '-c -nologo -D_CRT_SECURE_NO_DEPRECATE -MD -O2 -W3')],
  457. 'commands': [
  458. 'copy /y jconfig.vc jconfig.h',
  459. 'nmake /f makefile.vc libjpeg.lib']
  460. },
  461. 'mingw-w64-cross-win*': {
  462. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  463. 'commands': [
  464. './configure --host=%(mingw_w64)s --disable-shared --prefix=%(destdir)s',
  465. 'make install']
  466. },
  467. 'osx-carbon-i386': {
  468. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  469. 'commands': [
  470. 'CFLAGS="-arch i386" ./configure --disable-shared --prefix=%(destdir)s',
  471. 'make install']
  472. },
  473. 'osx-cocoa-x86-64': {
  474. 'result': ['include/jpeglib.h', 'include/jmorecfg.h', 'include/jerror.h', 'include/jconfig.h', 'lib/libjpeg.a'],
  475. 'commands': [
  476. 'CFLAGS="-arch x86_64" ./configure --disable-shared --prefix=%(destdir)s',
  477. 'make install']
  478. }
  479. }
  480. },
  481. 'xz': {
  482. 'order' : 5,
  483. 'url' : 'http://tukaani.org/xz/xz-5.0.5.tar.gz',
  484. 'sha1': '26fec2c1e409f736e77a85e4ab314dc74987def0',
  485. 'build' : {
  486. 'osx*': {
  487. 'result': ['bin/xz'],
  488. 'commands': [
  489. 'CFLAGS="-arch i386 -mmacosx-version-min=10.6" ./configure --disable-nls --enable-small --disable-shared --disable-threads --prefix=%(destdir)s',
  490. 'make -C src/liblzma', 'make -C src/xz', 'make install-strip']
  491. }
  492. }
  493. }
  494. }
  495. EXCLUDE_SRC_TARBALL = [
  496. 'qt/config.profiles*',
  497. 'qt/demos*',
  498. 'qt/dist*',
  499. 'qt/doc*',
  500. 'qt/examples*',
  501. 'qt/imports*',
  502. 'qt/templates*',
  503. 'qt/tests*',
  504. 'qt/translations*',
  505. 'qt/util*',
  506. 'qt/lib/fonts*',
  507. 'qt/src/3rdparty/*ChangeLog*',
  508. 'qt/src/3rdparty/ce-compat*',
  509. 'qt/src/3rdparty/clucene*',
  510. 'qt/src/3rdparty/fonts*',
  511. 'qt/src/3rdparty/freetype*',
  512. 'qt/src/3rdparty/javascriptcore*',
  513. 'qt/src/3rdparty/libgq*',
  514. 'qt/src/3rdparty/libmng*',
  515. 'qt/src/3rdparty/libtiff*',
  516. 'qt/src/3rdparty/patches*',
  517. 'qt/src/3rdparty/phonon*',
  518. 'qt/src/3rdparty/pixman*',
  519. 'qt/src/3rdparty/powervr*',
  520. 'qt/src/3rdparty/ptmalloc*',
  521. 'qt/src/3rdparty/s60*',
  522. 'qt/src/3rdparty/wayland*'
  523. ]
  524. # --------------------------------------------------------------- HELPERS
  525. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  526. from os.path import exists
  527. if platform.system() == 'Windows':
  528. try:
  529. import winreg
  530. except ImportError:
  531. import _winreg as winreg
  532. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  533. def rchop(s, e):
  534. if s.endswith(e):
  535. return s[:-len(e)]
  536. return s
  537. def message(msg):
  538. sys.stdout.write(msg)
  539. sys.stdout.flush()
  540. def error(msg):
  541. message(msg+'\n')
  542. sys.exit(1)
  543. def shell(cmd):
  544. ret = os.system(cmd)
  545. if ret != 0:
  546. error("%s\ncommand failed: exit code %d" % (cmd, ret))
  547. def chroot_shell(name, cmd):
  548. ret = os.system('schroot -c wkhtmltopdf-%s -- %s ' % (name, cmd))
  549. if ret != 0:
  550. error("command inside chroot failed: exit code %d" % ret)
  551. def get_output(*cmd):
  552. try:
  553. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  554. except:
  555. return None
  556. def rmdir(path):
  557. if exists(path):
  558. if platform.system() == 'Windows':
  559. shell('attrib -R %s\* /S' % path)
  560. shutil.rmtree(path)
  561. def mkdir_p(path):
  562. if not exists(path):
  563. os.makedirs(path)
  564. def get_registry_value(key, value=None):
  565. for mask in [0, winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY]:
  566. try:
  567. reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key, 0, winreg.KEY_READ | mask)
  568. return winreg.QueryValueEx(reg_key, value)[0]
  569. except WindowsError:
  570. pass
  571. return None
  572. def get_version(basedir):
  573. mkdir_p(basedir)
  574. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  575. if '-' not in text:
  576. return (text, text)
  577. version = text[:text.index('-')]
  578. os.chdir(os.path.join(basedir, '..'))
  579. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  580. if not hash:
  581. return (text, version)
  582. return ('%s-%s' % (text, hash), version)
  583. def qt_config(key, *opts):
  584. input, output = [], []
  585. input.extend(QT_CONFIG['common'])
  586. input.extend(QT_CONFIG[key])
  587. input.extend(opts)
  588. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  589. if cfg:
  590. input.extend(cfg.split())
  591. for arg in input:
  592. if not arg.startswith('remove:-'):
  593. output.append(arg)
  594. elif arg[1+arg.index(':'):] in output:
  595. output.remove(arg[1+arg.index(':'):])
  596. return ' '.join(output)
  597. def fpm_setup(cfg):
  598. input, output = {}, ''
  599. input.update(FPM_SETUP['common'])
  600. input.update(FPM_SETUP[cfg])
  601. for key in input:
  602. if type(input[key]) is list:
  603. for val in input[key]:
  604. output += ' %s "%s"' % (key, val)
  605. else:
  606. output += ' %s "%s"' % (key, input[key])
  607. return output, input
  608. def download_file(url, sha1, dir):
  609. name = url.split('/')[-1]
  610. loc = os.path.join(dir, name)
  611. if os.path.exists(loc):
  612. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  613. if hash == sha1:
  614. return loc
  615. os.remove(loc)
  616. message('Checksum mismatch for %s, re-downloading.\n' % name)
  617. def hook(cnt, bs, total):
  618. pct = int(cnt*bs*100/total)
  619. message("\rDownloading: %s [%d%%]" % (name, pct))
  620. urllib.urlretrieve(url, loc, reporthook=hook)
  621. message("\r")
  622. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  623. if hash != sha1:
  624. os.remove(loc)
  625. error('Checksum mismatch for %s, aborting.' % name)
  626. message("\rDownloaded: %s [checksum OK]\n" % name)
  627. return loc
  628. def download_tarball(url, sha1, dir, name):
  629. loc = download_file(url, sha1, dir)
  630. tar = tarfile.open(loc)
  631. sub = tar.getnames()[0]
  632. if '/' in sub:
  633. sub = sub[:sub.index('/')]
  634. src = os.path.join(dir, sub)
  635. tgt = os.path.join(dir, name)
  636. rmdir(src)
  637. tar.extractall(dir)
  638. rmdir(tgt)
  639. os.rename(src, tgt)
  640. return tgt
  641. def _is_compiled(dst, loc):
  642. present = True
  643. for name in loc['result']:
  644. present = present and exists(os.path.join(dst, name))
  645. return present
  646. def build_deplibs(config, basedir, **kwargs):
  647. mkdir_p(os.path.join(basedir, config))
  648. dstdir = os.path.join(basedir, config, 'deplibs')
  649. vars = {'destdir': dstdir }
  650. vars.update(kwargs)
  651. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  652. cfg = None
  653. for key in DEPENDENT_LIBS[lib]['build']:
  654. if fnmatch.fnmatch(config, key):
  655. cfg = key
  656. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  657. continue
  658. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  659. message('========== building: %s\n' % lib)
  660. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  661. basedir, os.path.join(config, lib))
  662. for location, source, target in build_cfg.get('replace', []):
  663. data = open(os.path.join(srcdir, location), 'r').read()
  664. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  665. os.chdir(srcdir)
  666. for command in build_cfg['commands']:
  667. shell(command % vars)
  668. if not type(build_cfg['result']) is list:
  669. for target in build_cfg['result']:
  670. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  671. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  672. os.chdir(dstdir)
  673. if not _is_compiled(dstdir, build_cfg):
  674. error("Unable to compile %s for your system, aborting." % lib)
  675. rmdir(srcdir)
  676. def check_running_on_debian():
  677. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  678. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  679. if os.geteuid() != 0:
  680. error('This script must be run as root.')
  681. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  682. ARCH.insert(0, 'amd64')
  683. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  684. def install_packages(*names):
  685. lines = get_output('dpkg-query', '--list').split('\n')
  686. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  687. inst = [name for name in names if name in avail]
  688. if len(inst) != len(names):
  689. shell('apt-get update')
  690. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  691. # --------------------------------------------------------------- Linux chroot
  692. ARCH = ['i386']
  693. def check_setup_schroot(config):
  694. check_running_on_debian()
  695. login = os.environ.get('SUDO_USER') or get_output('logname')
  696. if not login or login == 'root':
  697. error('Unable to determine the login for which schroot access is to be given.')
  698. def build_setup_schroot(config, basedir):
  699. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  700. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  701. login = os.environ.get('SUDO_USER') or get_output('logname')
  702. chroot = config[1+config.rindex('-'):]
  703. command_list = CHROOT_SETUP.get(chroot)
  704. if not command_list and ('%s:amd64' % chroot) in CHROOT_SETUP:
  705. command_list = CHROOT_SETUP['%s:amd64' % chroot]
  706. if 'i386' in ARCH:
  707. del ARCH[ARCH.index('i386')]
  708. for arch in ARCH:
  709. alias = '%s-%s' % (chroot, arch)
  710. if command_list[0][0] == 'set_alias':
  711. alias = command_list[0][1]
  712. del command_list[0]
  713. message('******************* %s\n' % alias)
  714. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  715. root_dir = os.path.join(base_dir, alias)
  716. os.system('umount %s/proc' % root_dir)
  717. os.system('umount %s/sys' % root_dir)
  718. rmdir(root_dir)
  719. mkdir_p(root_dir)
  720. for command in command_list:
  721. # handle architecture-specific commands
  722. name = command[0]
  723. if ':' in name:
  724. if name[1+name.rindex(':'):] != arch:
  725. continue
  726. else:
  727. name = name[:name.rindex(':')]
  728. # handle commands
  729. if name == 'debootstrap':
  730. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  731. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  732. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  733. shell('%s %s mount -t proc proc /proc' % (cmd, root_dir))
  734. shell('%s %s mount -t sysfs sysfs /sys' % (cmd, root_dir))
  735. elif name == 'rinse':
  736. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  737. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  738. shell('%s %s mount -t proc proc /proc' % (cmd, root_dir))
  739. shell('%s %s mount -t sysfs sysfs /sys' % (cmd, root_dir))
  740. elif name == 'shell':
  741. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  742. shell('%s %s %s' % (cmd, root_dir, command[1]))
  743. elif name == 'write_file':
  744. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  745. elif name == 'append_file':
  746. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  747. elif name == 'download_file':
  748. name = command[1].split('/')[-1]
  749. loc = os.path.join(root_dir, command[2], name)
  750. if exists(loc): os.remove(loc)
  751. def hook(cnt, bs, total):
  752. pct = int(cnt*bs*100/total)
  753. message("\rDownloading: %s [%d%%]" % (name, pct))
  754. urllib.urlretrieve(command[1], loc, reporthook=hook)
  755. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  756. elif name == 'fpm_setup':
  757. args, cfg = fpm_setup(chroot)
  758. cmd = '#!/bin/sh\nXZ_OPT=-9 fpm --force %s --package ../%s-$1_linux-%s-$2.%s .\n'
  759. loc = os.path.join(root_dir, command[1])
  760. open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
  761. shell('chmod a+x %s' % loc)
  762. elif name == 'schroot_conf':
  763. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s' % alias, 'w')
  764. cfg.write('[wkhtmltopdf-%s]\n' % alias)
  765. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  766. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  767. cfg.write('users=%s\nroot-users=root\n' % login)
  768. if arch == 'i386' and 'amd64' in ARCH:
  769. cfg.write('personality=linux32\n')
  770. cfg.close()
  771. os.system('umount %s/proc' % root_dir)
  772. os.system('umount %s/sys' % root_dir)
  773. def check_update_schroot(config):
  774. check_running_on_debian()
  775. if not get_output('schroot', '--list'):
  776. error('Unable to determine the list of available schroots.')
  777. def build_update_schroot(config, basedir):
  778. for name in get_output('schroot', '--list').split('\n'):
  779. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  780. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  781. def check_setup_mingw64(config):
  782. check_running_on_debian()
  783. def build_setup_mingw64(config, basedir):
  784. install_packages('build-essential', 'mingw-w64', 'nsis')
  785. def check_source_tarball(config):
  786. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  787. error("This can only be run inside a git checkout.")
  788. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  789. error("Please initialize and download the Qt submodule before running this.")
  790. def _filter_tar(info):
  791. name = info.name[1+info.name.index('/'):]
  792. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  793. return None
  794. info.uid = info.gid = 1000
  795. info.uname = info.gname = 'wkhtmltopdf'
  796. return info
  797. def build_source_tarball(config, basedir):
  798. version, simple_version = get_version(basedir)
  799. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  800. os.chdir(os.path.join(root_dir, 'qt'))
  801. shell('git clean -fdx')
  802. shell('git reset --hard HEAD')
  803. os.chdir(root_dir)
  804. shell('git clean -fdx')
  805. shell('git reset --hard HEAD')
  806. shell('git submodule update')
  807. open('VERSION', 'w').write(version)
  808. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  809. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  810. shell('git reset --hard HEAD')
  811. # --------------------------------------------------------------- MSVC (2013 only)
  812. MSVC_LOCATION = {
  813. 'msvc2013': 'VS120COMNTOOLS'
  814. }
  815. MSVC_RUNTIME = {
  816. 'msvc2013-win32': ('df7f0a73bfa077e483e51bfb97f5e2eceedfb6a3', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe'),
  817. 'msvc2013-win64': ('8bf41ba9eef02d30635a10433817dbb6886da5a2', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe')
  818. }
  819. def check_msvc(config):
  820. version, arch = rchop(config, '-dbg').split('-')
  821. env_var = MSVC_LOCATION[version]
  822. if not env_var in os.environ:
  823. error("%s does not seem to be installed." % version)
  824. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  825. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  826. error("%s: unable to find vcvarsall.bat" % version)
  827. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  828. error("%s: unable to find the x86 compiler" % version)
  829. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  830. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  831. error("%s: unable to find the amd64 compiler" % version)
  832. perl = get_output('perl', '-V')
  833. if not perl or 'perl5' not in perl:
  834. error("perl does not seem to be installed.")
  835. nsis = get_registry_value(r'SOFTWARE\NSIS')
  836. if not nsis or not exists(os.path.join(nsis, 'makensis.exe')):
  837. error("NSIS does not seem to be installed.")
  838. def build_msvc(config, basedir):
  839. msvc, arch = rchop(config, '-dbg').split('-')
  840. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  841. vcarg = 'x86'
  842. if arch == 'win64':
  843. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  844. vcarg = 'amd64'
  845. else:
  846. vcarg = 'x86_amd64'
  847. python = sys.executable
  848. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  849. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  850. stdout, _ = process.communicate()
  851. exitcode = process.wait()
  852. if exitcode != 0:
  853. error("%s: unable to initialize the environment" % msvc)
  854. os.environ.update(eval(stdout.strip()))
  855. version, simple_version = get_version(basedir)
  856. build_deplibs(config, basedir)
  857. sha1, url = MSVC_RUNTIME[rchop(config, '-dbg')]
  858. shutil.copy(download_file(url, sha1, basedir), os.path.join(basedir, config, 'vcredist.exe'))
  859. libdir = os.path.join(basedir, config, 'deplibs')
  860. qtdir = os.path.join(basedir, config, 'qt')
  861. mkdir_p(qtdir)
  862. configure_args = qt_config('msvc',
  863. '-I %s\\include' % libdir,
  864. '-L %s\\lib' % libdir,
  865. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  866. os.chdir(qtdir)
  867. if not exists('is_configured'):
  868. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  869. open('is_configured', 'w').write('')
  870. shell('nmake')
  871. appdir = os.path.join(basedir, config, 'app')
  872. mkdir_p(appdir)
  873. os.chdir(appdir)
  874. rmdir('bin')
  875. mkdir_p('bin')
  876. os.environ['WKHTMLTOX_VERSION'] = version
  877. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  878. shell('nmake')
  879. makensis = os.path.join(get_registry_value(r'SOFTWARE\NSIS'), 'makensis.exe')
  880. os.chdir(os.path.join(basedir, '..'))
  881. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s /DMSVC /DARCH=%s wkhtmltox.nsi' % \
  882. (makensis, version, simple_version, config, arch))
  883. # ------------------------------------------------ MinGW-W64 Cross Environment
  884. MINGW_W64_PREFIX = {
  885. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  886. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  887. }
  888. def check_mingw64_cross(config):
  889. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  890. def build_mingw64_cross(config, basedir):
  891. version, simple_version = get_version(basedir)
  892. build_deplibs(config, basedir, mingw_w64=MINGW_W64_PREFIX.get(rchop(config, '-dbg')))
  893. libdir = os.path.join(basedir, config, 'deplibs')
  894. qtdir = os.path.join(basedir, config, 'qt')
  895. configure_args = qt_config('mingw-w64-cross',
  896. '--prefix=%s' % qtdir,
  897. '-I %s/include' % libdir,
  898. '-L %s/lib' % libdir,
  899. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  900. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  901. mkdir_p(qtdir)
  902. os.chdir(qtdir)
  903. if not exists('is_configured'):
  904. for var in ['CFLAGS', 'CXXFLAGS']:
  905. os.environ[var] = '-w'
  906. shell('%s/../qt/configure %s' % (basedir, configure_args))
  907. shell('touch is_configured')
  908. shell('make -j%d' % CPU_COUNT)
  909. appdir = os.path.join(basedir, config, 'app')
  910. mkdir_p(appdir)
  911. os.chdir(appdir)
  912. shell('rm -f bin/*')
  913. # set up cross compiling prefix correctly
  914. os.environ['WKHTMLTOX_VERSION'] = version
  915. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  916. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  917. shell('make')
  918. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  919. shell('rm -f bin/lib*.dll')
  920. for dll in ['libgcc_s_sjlj-1.dll', 'libgcc_s_seh-1.dll', 'libstdc++-6.dll']:
  921. dll_path = get_output('dpkg', '-S', dll)
  922. if dll_path:
  923. for line in dll_path.split('\n'):
  924. loc = line[1+line.index(':'):].strip()
  925. if exists(loc) and MINGW_W64_PREFIX[rchop(config, '-dbg')] in loc and '-posix' not in loc:
  926. shell('cp %s bin/' % loc)
  927. os.chdir(os.path.join(basedir, '..'))
  928. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s -DMINGW -DARCH=%s wkhtmltox.nsi' % \
  929. (version, simple_version, config, rchop(config, '-dbg').split('-')[-1]))
  930. # -------------------------------------------------- Linux schroot environment
  931. def check_linux_schroot(config):
  932. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  933. def build_linux_schroot(config, basedir):
  934. version, simple_version = get_version(basedir)
  935. dir = os.path.join(basedir, config)
  936. script = os.path.join(dir, 'build.sh')
  937. dist = os.path.join(dir, 'dist')
  938. mkdir_p(dir)
  939. rmdir(dist)
  940. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  941. lines = ['#!/bin/bash']
  942. lines.append('# start of autogenerated build script')
  943. lines.append('mkdir -p app qt')
  944. lines.append('cd qt')
  945. if config == 'centos5-i386':
  946. lines.append('export CFLAGS="-march=i486 -w"')
  947. lines.append('export CXXFLAGS="-march=i486 -w"')
  948. else:
  949. for var in ['CFLAGS', 'CXXFLAGS']:
  950. lines.append('export %s="-w"' % var)
  951. lines.append('if [ ! -f is_configured ]; then')
  952. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  953. lines.append(' touch is_configured')
  954. lines.append('fi')
  955. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  956. lines.append('cd ../app')
  957. lines.append('rm -f bin/*')
  958. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  959. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  960. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  961. lines.append('cd ..')
  962. lines.append('/fpm_package.sh %s %s' % (version, config[1+config.index('-'):]))
  963. lines.append('# end of build script')
  964. open(script, 'w').write('\n'.join(lines))
  965. os.chdir(dir)
  966. shell('chmod +x build.sh')
  967. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  968. # -------------------------------------------------- POSIX local environment
  969. def check_posix_local(config):
  970. pass
  971. def build_posix_local(config, basedir):
  972. version, simple_version = get_version(basedir)
  973. app = os.path.join(basedir, config, 'app')
  974. qt = os.path.join(basedir, config, 'qt')
  975. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  976. make = get_output('which gmake') and 'gmake' or 'make'
  977. mkdir_p(qt)
  978. mkdir_p(app)
  979. rmdir(dist)
  980. mkdir_p(os.path.join(dist, 'bin'))
  981. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  982. mkdir_p(os.path.join(dist, 'lib'))
  983. os.chdir(qt)
  984. if not exists('is_configured'):
  985. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qt))
  986. shell('touch is_configured')
  987. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  988. shell('%s -j%d' % (make, CPU_COUNT))
  989. os.chdir(app)
  990. shell('rm -f bin/*')
  991. os.environ['WKHTMLTOX_VERSION'] = version
  992. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  993. shell('%s -j%d' % (make, CPU_COUNT))
  994. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  995. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  996. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  997. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  998. os.chdir(os.path.join(basedir, config))
  999. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  1000. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  1001. # --------------------------------------------------------------- OS X
  1002. def check_osx(config):
  1003. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  1004. error('This can only be run on a OS X system!')
  1005. if not get_output('xcode-select', '--print-path'):
  1006. error('Xcode is not installed, aborting.')
  1007. if not get_output('which', 'fpm'):
  1008. error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
  1009. def build_osx(config, basedir):
  1010. version, simple_version = get_version(basedir)
  1011. build_deplibs(config, basedir)
  1012. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  1013. framework = config.split('-')[1]
  1014. if osxver == '10.6':
  1015. osxcfg = '-%s -platform macx-g++42' % framework
  1016. else:
  1017. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  1018. flags = ''
  1019. if framework == 'carbon' and osxver != '10.6':
  1020. for item in ['CFLAGS', 'CXXFLAGS']:
  1021. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  1022. def get_dir(name):
  1023. return os.path.join(basedir, config, name)
  1024. configure_args = qt_config('osx', osxcfg,
  1025. '--prefix=%s' % get_dir('qt'),
  1026. '-I %s/include' % get_dir('deplibs'),
  1027. '-L %s/lib' % get_dir('deplibs'))
  1028. rmdir(get_dir('dist'))
  1029. rmdir(get_dir('pkg'))
  1030. mkdir_p(get_dir('qt'))
  1031. mkdir_p(get_dir('app'))
  1032. mkdir_p(get_dir('pkg'))
  1033. os.chdir(get_dir('qt'))
  1034. if not exists('is_configured'):
  1035. shell('../../../qt/configure %s' % configure_args)
  1036. shell('touch is_configured')
  1037. shell('make -j%d' % CPU_COUNT)
  1038. os.chdir(get_dir('app'))
  1039. shell('rm -f bin/*')
  1040. os.environ['WKHTMLTOX_VERSION'] = version
  1041. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  1042. shell('make -j%d' % CPU_COUNT)
  1043. if osxver not in ['10.6', '10.7']:
  1044. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  1045. shell(' '.join([
  1046. 'install_name_tool', '-change',
  1047. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  1048. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  1049. 'bin/'+item]))
  1050. shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
  1051. def _osx_tar(info):
  1052. info.uid = info.gid = 0
  1053. info.uname = 'root'
  1054. info.gname = 'wheel'
  1055. return info
  1056. # create tarball for application and copy xz
  1057. os.chdir(get_dir('dist'))
  1058. with tarfile.open('../pkg/app.tar', 'w') as tar:
  1059. tar.add('.', './', filter=_osx_tar)
  1060. xz = os.path.join(get_dir('deplibs'), 'bin', 'xz')
  1061. shell('%s --compress --force --verbose -9 ../pkg/app.tar' % xz)
  1062. shutil.copy(xz, '../pkg/')
  1063. args, cfg = fpm_setup('osx')
  1064. with open('../pkg/uninstall-wkhtmltox', 'w') as f:
  1065. os.chmod('../pkg/uninstall-wkhtmltox', 0o755)
  1066. f.write("""#!/bin/bash
  1067. if [ "$(id -u)" != "0" ]; then
  1068. echo "This script must be run as sudo uninstall-wkhtmltox" 1>&2
  1069. exit 1
  1070. fi
  1071. cd /usr/local
  1072. if which pkgutil >/dev/null; then
  1073. pkgutil --forget %s.%s
  1074. fi
  1075. """ % (cfg['--osxpkg-identifier-prefix'], cfg['--name']))
  1076. for root, dirs, files in os.walk(get_dir('dist')):
  1077. for file in files:
  1078. f.write('echo REMOVE /usr/local/%(name)s && rm -f %(name)s\n' % { 'name': os.path.relpath(os.path.join(root, file)) })
  1079. f.write('echo REMOVE /usr/local/include/wkhtmltox && rm -df /usr/local/include/wkhtmltox\n')
  1080. f.write('echo REMOVE /usr/local/bin/uninstall-wkhtmltox && rm -f /usr/local/bin/uninstall-wkhtmltox')
  1081. open('../extract.sh', 'w').write("""#!/bin/bash
  1082. TGTDIR=/usr/local
  1083. BASEDIR=%s
  1084. cd $BASEDIR
  1085. ./xz --decompress app.tar.xz
  1086. cd $TGTDIR
  1087. tar xf $BASEDIR/app.tar
  1088. mv $BASEDIR/uninstall-wkhtmltox $TGTDIR/bin
  1089. rm -fr $BASEDIR
  1090. """ % cfg['--prefix'])
  1091. os.chdir(os.path.join(basedir, config))
  1092. shell('fpm --force %s --package ../%s-%s_%s.pkg .' % (args.replace('$1', version), cfg['--name'], version, config))
  1093. # --------------------------------------------------------------- command line
  1094. def usage(exit_code=2):
  1095. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  1096. opts = list(BUILDERS.keys())
  1097. opts.sort()
  1098. for opt in opts:
  1099. message('* %s\n' % opt)
  1100. sys.exit(exit_code)
  1101. def main():
  1102. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  1103. basedir = os.path.join(rootdir, 'static-build')
  1104. if len(sys.argv) == 1:
  1105. usage(0)
  1106. config = sys.argv[1]
  1107. if config not in BUILDERS:
  1108. usage()
  1109. for arg in sys.argv[2:]:
  1110. if not arg in ['-clean', '-debug', '-chroot-build']:
  1111. usage()
  1112. final_config = config
  1113. if '-debug' in sys.argv[2:]:
  1114. final_config += '-dbg'
  1115. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  1116. if '-clean' in sys.argv[2:]:
  1117. rmdir(os.path.join(basedir, config))
  1118. os.chdir(rootdir)
  1119. if '-chroot-build' in sys.argv[2:]:
  1120. globals()['chroot_build_%s' % BUILDERS[config]](final_config, basedir)
  1121. return
  1122. globals()['check_%s' % BUILDERS[config]](final_config)
  1123. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  1124. if __name__ == '__main__':
  1125. main()