build.py 47 KB

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