build.py 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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.1m.tar.gz',
  357. 'sha1' : '4ccaf6e505529652f9fdafa01d1d8300bd9f3179',
  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. else:
  547. CPU_COUNT = max(2, multiprocessing.cpu_count())
  548. def rchop(s, e):
  549. if s.endswith(e):
  550. return s[:-len(e)]
  551. return s
  552. def message(msg):
  553. sys.stdout.write(msg)
  554. sys.stdout.flush()
  555. def error(msg):
  556. message(msg+'\n')
  557. sys.exit(1)
  558. def shell(cmd):
  559. ret = os.system(cmd)
  560. if ret != 0:
  561. error("%s\ncommand failed: exit code %d" % (cmd, ret))
  562. def chroot_shell(name, cmd):
  563. ret = os.system('schroot -c wkhtmltopdf-%s -- %s ' % (name, cmd))
  564. if ret != 0:
  565. error("command inside chroot failed: exit code %d" % ret)
  566. def get_output(*cmd):
  567. try:
  568. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  569. except:
  570. return None
  571. def rmdir(path):
  572. if exists(path):
  573. if platform.system() == 'Windows':
  574. shell('attrib -R %s\* /S' % path)
  575. shutil.rmtree(path)
  576. def mkdir_p(path):
  577. if not exists(path):
  578. os.makedirs(path)
  579. def get_registry_value(key, value=None):
  580. for mask in [0, winreg.KEY_WOW64_64KEY, winreg.KEY_WOW64_32KEY]:
  581. try:
  582. reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key, 0, winreg.KEY_READ | mask)
  583. return winreg.QueryValueEx(reg_key, value)[0]
  584. except WindowsError:
  585. pass
  586. return None
  587. def get_version(basedir):
  588. mkdir_p(basedir)
  589. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  590. if '-' not in text:
  591. return (text, text)
  592. version = text[:text.index('-')]
  593. os.chdir(os.path.join(basedir, '..'))
  594. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  595. if not hash:
  596. return (text, version)
  597. return ('%s-%s' % (text, hash), version)
  598. def qt_config(key, *opts):
  599. input, output = [], []
  600. input.extend(QT_CONFIG['common'])
  601. input.extend(QT_CONFIG[key])
  602. input.extend(opts)
  603. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  604. if cfg:
  605. input.extend(cfg.split())
  606. for arg in input:
  607. if not arg.startswith('remove:-'):
  608. output.append(arg)
  609. elif arg[1+arg.index(':'):] in output:
  610. output.remove(arg[1+arg.index(':'):])
  611. return ' '.join(output)
  612. def fpm_setup(cfg):
  613. input, output = {}, ''
  614. input.update(FPM_SETUP['common'])
  615. input.update(FPM_SETUP[cfg])
  616. for key in input:
  617. if type(input[key]) is list:
  618. for val in input[key]:
  619. output += ' %s "%s"' % (key, val)
  620. else:
  621. output += ' %s "%s"' % (key, input[key])
  622. return output, input
  623. def download_file(url, sha1, dir):
  624. name = url.split('/')[-1]
  625. loc = os.path.join(dir, name)
  626. if os.path.exists(loc):
  627. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  628. if hash == sha1:
  629. return loc
  630. os.remove(loc)
  631. message('Checksum mismatch for %s, re-downloading.\n' % name)
  632. def hook(cnt, bs, total):
  633. pct = int(cnt*bs*100/total)
  634. message("\rDownloading: %s [%d%%]" % (name, pct))
  635. urllib.urlretrieve(url, loc, reporthook=hook)
  636. message("\r")
  637. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  638. if hash != sha1:
  639. os.remove(loc)
  640. error('Checksum mismatch for %s, aborting.' % name)
  641. message("\rDownloaded: %s [checksum OK]\n" % name)
  642. return loc
  643. def download_tarball(url, sha1, dir, name):
  644. loc = download_file(url, sha1, dir)
  645. tar = tarfile.open(loc)
  646. sub = tar.getnames()[0]
  647. if '/' in sub:
  648. sub = sub[:sub.index('/')]
  649. src = os.path.join(dir, sub)
  650. tgt = os.path.join(dir, name)
  651. rmdir(src)
  652. tar.extractall(dir)
  653. rmdir(tgt)
  654. os.rename(src, tgt)
  655. return tgt
  656. def _is_compiled(dst, loc):
  657. present = True
  658. for name in loc['result']:
  659. present = present and exists(os.path.join(dst, name))
  660. return present
  661. def build_deplibs(config, basedir, **kwargs):
  662. mkdir_p(os.path.join(basedir, config))
  663. dstdir = os.path.join(basedir, config, 'deplibs')
  664. vars = {'destdir': dstdir }
  665. vars.update(kwargs)
  666. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  667. cfg = None
  668. for key in DEPENDENT_LIBS[lib]['build']:
  669. if fnmatch.fnmatch(config, key):
  670. cfg = key
  671. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  672. continue
  673. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  674. message('========== building: %s\n' % lib)
  675. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  676. basedir, os.path.join(config, lib))
  677. for location, source, target in build_cfg.get('replace', []):
  678. data = open(os.path.join(srcdir, location), 'r').read()
  679. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  680. os.chdir(srcdir)
  681. for command in build_cfg['commands']:
  682. shell(command % vars)
  683. if not type(build_cfg['result']) is list:
  684. for target in build_cfg['result']:
  685. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  686. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  687. os.chdir(dstdir)
  688. if not _is_compiled(dstdir, build_cfg):
  689. error("Unable to compile %s for your system, aborting." % lib)
  690. rmdir(srcdir)
  691. def check_running_on_debian():
  692. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  693. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  694. if os.geteuid() != 0:
  695. error('This script must be run as root.')
  696. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  697. ARCH.insert(0, 'amd64')
  698. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  699. def install_packages(*names):
  700. lines = get_output('dpkg-query', '--list').split('\n')
  701. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  702. inst = [name for name in names if name in avail]
  703. if len(inst) != len(names):
  704. shell('apt-get update')
  705. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  706. # --------------------------------------------------------------- Linux chroot
  707. ARCH = ['i386']
  708. def check_setup_schroot(config):
  709. check_running_on_debian()
  710. login = os.environ.get('SUDO_USER') or get_output('logname')
  711. if not login or login == 'root':
  712. error('Unable to determine the login for which schroot access is to be given.')
  713. def build_setup_schroot(config, basedir):
  714. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  715. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  716. login = os.environ.get('SUDO_USER') or get_output('logname')
  717. chroot = config[1+config.rindex('-'):]
  718. command_list = CHROOT_SETUP.get(chroot)
  719. if not command_list and ('%s:amd64' % chroot) in CHROOT_SETUP:
  720. command_list = CHROOT_SETUP['%s:amd64' % chroot]
  721. if 'i386' in ARCH:
  722. del ARCH[ARCH.index('i386')]
  723. for arch in ARCH:
  724. alias = '%s-%s' % (chroot, arch)
  725. if command_list[0][0] == 'set_alias':
  726. alias = command_list[0][1]
  727. del command_list[0]
  728. message('******************* %s\n' % alias)
  729. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  730. root_dir = os.path.join(base_dir, alias)
  731. os.system('umount %s/proc' % root_dir)
  732. os.system('umount %s/sys' % root_dir)
  733. rmdir(root_dir)
  734. mkdir_p(root_dir)
  735. for command in command_list:
  736. # handle architecture-specific commands
  737. name = command[0]
  738. if ':' in name:
  739. if name[1+name.rindex(':'):] != arch:
  740. continue
  741. else:
  742. name = name[:name.rindex(':')]
  743. # handle commands
  744. if name == 'debootstrap':
  745. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  746. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  747. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  748. shell('%s %s mount -t proc proc /proc' % (cmd, root_dir))
  749. shell('%s %s mount -t sysfs sysfs /sys' % (cmd, root_dir))
  750. elif name == 'rinse':
  751. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  752. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  753. shell('%s %s mount -t proc proc /proc' % (cmd, root_dir))
  754. shell('%s %s mount -t sysfs sysfs /sys' % (cmd, root_dir))
  755. elif name == 'shell':
  756. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  757. shell('%s %s %s' % (cmd, root_dir, command[1]))
  758. elif name == 'write_file':
  759. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  760. elif name == 'append_file':
  761. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  762. elif name == 'download_file':
  763. name = command[1].split('/')[-1]
  764. loc = os.path.join(root_dir, command[2], name)
  765. if exists(loc): os.remove(loc)
  766. def hook(cnt, bs, total):
  767. pct = int(cnt*bs*100/total)
  768. message("\rDownloading: %s [%d%%]" % (name, pct))
  769. urllib.urlretrieve(command[1], loc, reporthook=hook)
  770. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  771. elif name == 'fpm_setup':
  772. args, cfg = fpm_setup(chroot)
  773. cmd = '#!/bin/sh\nXZ_OPT=-9 fpm --force %s --package ../%s-$1_linux-%s-$2.%s .\n'
  774. loc = os.path.join(root_dir, command[1])
  775. open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
  776. shell('chmod a+x %s' % loc)
  777. elif name == 'schroot_conf':
  778. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s' % alias, 'w')
  779. cfg.write('[wkhtmltopdf-%s]\n' % alias)
  780. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  781. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  782. cfg.write('users=%s\nroot-users=root\n' % login)
  783. if arch == 'i386' and 'amd64' in ARCH:
  784. cfg.write('personality=linux32\n')
  785. cfg.close()
  786. os.system('umount %s/proc' % root_dir)
  787. os.system('umount %s/sys' % root_dir)
  788. def check_update_schroot(config):
  789. check_running_on_debian()
  790. if not get_output('schroot', '--list'):
  791. error('Unable to determine the list of available schroots.')
  792. def build_update_schroot(config, basedir):
  793. for name in get_output('schroot', '--list').split('\n'):
  794. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  795. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  796. def check_source_tarball(config):
  797. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  798. error("This can only be run inside a git checkout.")
  799. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  800. error("Please initialize and download the Qt submodule before running this.")
  801. def _filter_tar(info):
  802. name = info.name[1+info.name.index('/'):]
  803. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  804. return None
  805. info.uid = info.gid = 1000
  806. info.uname = info.gname = 'wkhtmltopdf'
  807. return info
  808. def build_source_tarball(config, basedir):
  809. version, simple_version = get_version(basedir)
  810. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  811. os.chdir(os.path.join(root_dir, 'qt'))
  812. shell('git clean -fdx')
  813. shell('git reset --hard HEAD')
  814. os.chdir(root_dir)
  815. shell('git clean -fdx')
  816. shell('git reset --hard HEAD')
  817. shell('git submodule update')
  818. open('VERSION', 'w').write(version)
  819. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  820. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  821. shell('git reset --hard HEAD')
  822. # --------------------------------------------------------------- MSVC (2013 only)
  823. MSVC_LOCATION = {
  824. 'msvc2013': 'VS120COMNTOOLS'
  825. }
  826. MSVC_RUNTIME = {
  827. 'msvc2013-win32': ('df7f0a73bfa077e483e51bfb97f5e2eceedfb6a3', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe'),
  828. 'msvc2013-win64': ('8bf41ba9eef02d30635a10433817dbb6886da5a2', 'http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe')
  829. }
  830. def check_msvc(config):
  831. version, arch = rchop(config, '-dbg').split('-')
  832. env_var = MSVC_LOCATION[version]
  833. if not env_var in os.environ:
  834. error("%s does not seem to be installed." % version)
  835. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  836. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  837. error("%s: unable to find vcvarsall.bat" % version)
  838. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  839. error("%s: unable to find the x86 compiler" % version)
  840. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  841. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  842. error("%s: unable to find the amd64 compiler" % version)
  843. perl = get_output('perl', '-V')
  844. if not perl or 'perl5' not in perl:
  845. error("perl does not seem to be installed.")
  846. nsis = get_registry_value(r'SOFTWARE\NSIS')
  847. if not nsis or not exists(os.path.join(nsis, 'makensis.exe')):
  848. error("NSIS does not seem to be installed.")
  849. def build_msvc(config, basedir):
  850. msvc, arch = rchop(config, '-dbg').split('-')
  851. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  852. vcarg = 'x86'
  853. if arch == 'win64':
  854. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  855. vcarg = 'amd64'
  856. else:
  857. vcarg = 'x86_amd64'
  858. python = sys.executable
  859. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  860. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  861. stdout, _ = process.communicate()
  862. exitcode = process.wait()
  863. if exitcode != 0:
  864. error("%s: unable to initialize the environment" % msvc)
  865. os.environ.update(eval(stdout.strip()))
  866. version, simple_version = get_version(basedir)
  867. build_deplibs(config, basedir)
  868. sha1, url = MSVC_RUNTIME[rchop(config, '-dbg')]
  869. shutil.copy(download_file(url, sha1, basedir), os.path.join(basedir, config, 'vcredist.exe'))
  870. libdir = os.path.join(basedir, config, 'deplibs')
  871. qtdir = os.path.join(basedir, config, 'qt')
  872. mkdir_p(qtdir)
  873. configure_args = qt_config('msvc',
  874. '-I %s\\include' % libdir,
  875. '-L %s\\lib' % libdir,
  876. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  877. os.chdir(qtdir)
  878. if not exists('is_configured'):
  879. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  880. open('is_configured', 'w').write('')
  881. shell('nmake')
  882. appdir = os.path.join(basedir, config, 'app')
  883. mkdir_p(appdir)
  884. os.chdir(appdir)
  885. rmdir('bin')
  886. mkdir_p('bin')
  887. os.environ['WKHTMLTOX_VERSION'] = version
  888. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  889. shell('nmake')
  890. makensis = os.path.join(get_registry_value(r'SOFTWARE\NSIS'), 'makensis.exe')
  891. os.chdir(os.path.join(basedir, '..'))
  892. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s /DMSVC /DARCH=%s wkhtmltox.nsi' % \
  893. (makensis, version, simple_version, config, arch))
  894. # ------------------------------------------------ MinGW-W64 Cross Environment
  895. MINGW_W64_PREFIX = {
  896. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  897. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  898. }
  899. def check_mingw64_cross(config):
  900. chroot_shell('mingw-w64', '%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  901. def build_mingw64_cross(config, basedir):
  902. os.chdir(os.path.realpath(os.path.join(basedir, '..')))
  903. chroot_shell('mingw-w64', 'python scripts/build.py %s -chroot-build' % ' '.join(sys.argv[1:]))
  904. def chroot_build_mingw64_cross(config, basedir):
  905. version, simple_version = get_version(basedir)
  906. build_deplibs(config, basedir, mingw_w64=MINGW_W64_PREFIX.get(rchop(config, '-dbg')))
  907. libdir = os.path.join(basedir, config, 'deplibs')
  908. qtdir = os.path.join(basedir, config, 'qt')
  909. configure_args = qt_config('mingw-w64-cross',
  910. '--prefix=%s' % qtdir,
  911. '-I%s/include' % libdir,
  912. '-L%s/lib' % libdir,
  913. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  914. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L%s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  915. mkdir_p(qtdir)
  916. os.chdir(qtdir)
  917. if not exists('is_configured'):
  918. for var in ['CFLAGS', 'CXXFLAGS']:
  919. os.environ[var] = '-w'
  920. shell('%s/../qt/configure %s' % (basedir, configure_args))
  921. shell('touch is_configured')
  922. shell('make -j%d' % CPU_COUNT)
  923. appdir = os.path.join(basedir, config, 'app')
  924. mkdir_p(appdir)
  925. os.chdir(appdir)
  926. shell('rm -f bin/*')
  927. # set up cross compiling prefix correctly
  928. os.environ['WKHTMLTOX_VERSION'] = version
  929. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  930. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  931. shell('make')
  932. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  933. shell('rm -f bin/lib*.dll')
  934. for dll in ['libgcc_s_sjlj-1.dll', 'libstdc++-6.dll', 'libwinpthread-1.dll']:
  935. dll_path = get_output('dpkg', '-S', dll)
  936. if dll_path:
  937. for line in dll_path.split('\n'):
  938. loc = line[1+line.index(':'):].strip()
  939. if exists(loc) and MINGW_W64_PREFIX[rchop(config, '-dbg')] in loc:
  940. shell('cp %s bin/' % loc)
  941. os.chdir(os.path.join(basedir, '..'))
  942. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s -DMINGW -DARCH=%s wkhtmltox.nsi' % \
  943. (version, simple_version, config, rchop(config, '-dbg').split('-')[-1]))
  944. # -------------------------------------------------- Linux schroot environment
  945. def check_linux_schroot(config):
  946. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  947. def build_linux_schroot(config, basedir):
  948. version, simple_version = get_version(basedir)
  949. dir = os.path.join(basedir, config)
  950. script = os.path.join(dir, 'build.sh')
  951. dist = os.path.join(dir, 'dist')
  952. mkdir_p(dir)
  953. rmdir(dist)
  954. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  955. lines = ['#!/bin/bash']
  956. lines.append('# start of autogenerated build script')
  957. lines.append('mkdir -p app qt')
  958. lines.append('cd qt')
  959. if config == 'centos5-i386':
  960. lines.append('export CFLAGS="-march=i486 -w"')
  961. lines.append('export CXXFLAGS="-march=i486 -w"')
  962. else:
  963. for var in ['CFLAGS', 'CXXFLAGS']:
  964. lines.append('export %s="-w"' % var)
  965. lines.append('if [ ! -f is_configured ]; then')
  966. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  967. lines.append(' touch is_configured')
  968. lines.append('fi')
  969. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  970. lines.append('cd ../app')
  971. lines.append('rm -f bin/*')
  972. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  973. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  974. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  975. lines.append('cd ..')
  976. lines.append('/fpm_package.sh %s %s' % (version, config[1+config.index('-'):]))
  977. lines.append('# end of build script')
  978. open(script, 'w').write('\n'.join(lines))
  979. os.chdir(dir)
  980. shell('chmod +x build.sh')
  981. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  982. # -------------------------------------------------- POSIX local environment
  983. def check_posix_local(config):
  984. pass
  985. def build_posix_local(config, basedir):
  986. version, simple_version = get_version(basedir)
  987. app = os.path.join(basedir, config, 'app')
  988. qt = os.path.join(basedir, config, 'qt')
  989. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  990. make = get_output('which gmake') and 'gmake' or 'make'
  991. mkdir_p(qt)
  992. mkdir_p(app)
  993. rmdir(dist)
  994. mkdir_p(os.path.join(dist, 'bin'))
  995. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  996. mkdir_p(os.path.join(dist, 'lib'))
  997. os.chdir(qt)
  998. if not exists('is_configured'):
  999. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qt))
  1000. shell('touch is_configured')
  1001. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  1002. shell('%s -j%d' % (make, CPU_COUNT))
  1003. os.chdir(app)
  1004. shell('rm -f bin/*')
  1005. os.environ['WKHTMLTOX_VERSION'] = version
  1006. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  1007. shell('%s -j%d' % (make, CPU_COUNT))
  1008. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  1009. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  1010. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  1011. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  1012. os.chdir(os.path.join(basedir, config))
  1013. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  1014. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  1015. # --------------------------------------------------------------- OS X
  1016. def check_osx(config):
  1017. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  1018. error('This can only be run on a OS X system!')
  1019. if not get_output('xcode-select', '--print-path'):
  1020. error('Xcode is not installed, aborting.')
  1021. if not get_output('which', 'fpm'):
  1022. error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
  1023. def build_osx(config, basedir):
  1024. version, simple_version = get_version(basedir)
  1025. build_deplibs(config, basedir)
  1026. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  1027. framework = config.split('-')[1]
  1028. if osxver == '10.6':
  1029. osxcfg = '-%s -platform macx-g++42' % framework
  1030. else:
  1031. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  1032. flags = ''
  1033. if framework == 'carbon' and osxver != '10.6':
  1034. for item in ['CFLAGS', 'CXXFLAGS']:
  1035. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  1036. def get_dir(name):
  1037. return os.path.join(basedir, config, name)
  1038. configure_args = qt_config('osx', osxcfg,
  1039. '--prefix=%s' % get_dir('qt'),
  1040. '-I %s/include' % get_dir('deplibs'),
  1041. '-L %s/lib' % get_dir('deplibs'))
  1042. rmdir(get_dir('dist'))
  1043. rmdir(get_dir('pkg'))
  1044. mkdir_p(get_dir('qt'))
  1045. mkdir_p(get_dir('app'))
  1046. mkdir_p(get_dir('pkg'))
  1047. os.chdir(get_dir('qt'))
  1048. if not exists('is_configured'):
  1049. shell('../../../qt/configure %s' % configure_args)
  1050. shell('touch is_configured')
  1051. shell('make -j%d' % CPU_COUNT)
  1052. os.chdir(get_dir('app'))
  1053. shell('rm -f bin/*')
  1054. os.environ['WKHTMLTOX_VERSION'] = version
  1055. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  1056. shell('make -j%d' % CPU_COUNT)
  1057. if osxver not in ['10.6', '10.7']:
  1058. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  1059. shell(' '.join([
  1060. 'install_name_tool', '-change',
  1061. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  1062. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  1063. 'bin/'+item]))
  1064. shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
  1065. def _osx_tar(info):
  1066. info.uid = info.gid = 0
  1067. info.uname = 'root'
  1068. info.gname = 'wheel'
  1069. return info
  1070. # create tarball for application and copy xz
  1071. os.chdir(get_dir('dist'))
  1072. with tarfile.open('../pkg/app.tar', 'w') as tar:
  1073. tar.add('.', './', filter=_osx_tar)
  1074. xz = os.path.join(get_dir('deplibs'), 'bin', 'xz')
  1075. shell('%s --compress --force --verbose -9 ../pkg/app.tar' % xz)
  1076. shutil.copy(xz, '../pkg/')
  1077. args, cfg = fpm_setup('osx')
  1078. with open('../pkg/uninstall-wkhtmltox', 'w') as f:
  1079. os.chmod('../pkg/uninstall-wkhtmltox', 0o755)
  1080. f.write("""#!/bin/bash
  1081. if [ "$(id -u)" != "0" ]; then
  1082. echo "This script must be run as sudo uninstall-wkhtmltox" 1>&2
  1083. exit 1
  1084. fi
  1085. cd /usr/local
  1086. if which pkgutil >/dev/null; then
  1087. pkgutil --forget %s.%s
  1088. fi
  1089. """ % (cfg['--osxpkg-identifier-prefix'], cfg['--name']))
  1090. for root, dirs, files in os.walk(get_dir('dist')):
  1091. for file in files:
  1092. f.write('echo REMOVE /usr/local/%(name)s && rm -f %(name)s\n' % { 'name': os.path.relpath(os.path.join(root, file)) })
  1093. f.write('echo REMOVE /usr/local/include/wkhtmltox && rm -df /usr/local/include/wkhtmltox\n')
  1094. f.write('echo REMOVE /usr/local/bin/uninstall-wkhtmltox && rm -f /usr/local/bin/uninstall-wkhtmltox')
  1095. open('../extract.sh', 'w').write("""#!/bin/bash
  1096. TGTDIR=/usr/local
  1097. BASEDIR=%s
  1098. cd $BASEDIR
  1099. ./xz --decompress app.tar.xz
  1100. cd $TGTDIR
  1101. tar xf $BASEDIR/app.tar
  1102. mv $BASEDIR/uninstall-wkhtmltox $TGTDIR/bin
  1103. rm -fr $BASEDIR
  1104. """ % cfg['--prefix'])
  1105. os.chdir(os.path.join(basedir, config))
  1106. shell('fpm --force %s --package ../%s-%s_%s.pkg .' % (args.replace('$1', version), cfg['--name'], version, config))
  1107. # --------------------------------------------------------------- command line
  1108. def usage(exit_code=2):
  1109. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  1110. opts = list(BUILDERS.keys())
  1111. opts.sort()
  1112. for opt in opts:
  1113. message('* %s\n' % opt)
  1114. sys.exit(exit_code)
  1115. def main():
  1116. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  1117. basedir = os.path.join(rootdir, 'static-build')
  1118. if len(sys.argv) == 1:
  1119. usage(0)
  1120. config = sys.argv[1]
  1121. if config not in BUILDERS:
  1122. usage()
  1123. for arg in sys.argv[2:]:
  1124. if not arg in ['-clean', '-debug', '-chroot-build']:
  1125. usage()
  1126. final_config = config
  1127. if '-debug' in sys.argv[2:]:
  1128. final_config += '-dbg'
  1129. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  1130. if '-clean' in sys.argv[2:]:
  1131. rmdir(os.path.join(basedir, config))
  1132. os.chdir(rootdir)
  1133. if '-chroot-build' in sys.argv[2:]:
  1134. globals()['chroot_build_%s' % BUILDERS[config]](final_config, basedir)
  1135. return
  1136. globals()['check_%s' % BUILDERS[config]](final_config)
  1137. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  1138. if __name__ == '__main__':
  1139. main()