build.py 42 KB

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