build.py 50 KB

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