build.py 47 KB

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