build.py 49 KB

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