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