build.py 46 KB

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