build.py 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185
  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/installer/wkhtmltox',
  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 ronn --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 ronn --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 ronn --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 ronn --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 ronn --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' : 'http://www.openssl.org/source/openssl-1.0.1h.tar.gz',
  300. 'sha1' : 'b2239599c8bf8f7fc48590a55205c26abe560bf8',
  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.18.tar.gz',
  353. 'sha1': '7ddf6865aa70d2d79faf65ebc611919a0b573654',
  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. }
  438. EXCLUDE_SRC_TARBALL = [
  439. 'qt/config.profiles*',
  440. 'qt/demos*',
  441. 'qt/dist*',
  442. 'qt/doc*',
  443. 'qt/examples*',
  444. 'qt/imports*',
  445. 'qt/templates*',
  446. 'qt/tests*',
  447. 'qt/translations*',
  448. 'qt/util*',
  449. 'qt/lib/fonts*',
  450. 'qt/src/3rdparty/*ChangeLog*',
  451. 'qt/src/3rdparty/ce-compat*',
  452. 'qt/src/3rdparty/clucene*',
  453. 'qt/src/3rdparty/fonts*',
  454. 'qt/src/3rdparty/freetype*',
  455. 'qt/src/3rdparty/javascriptcore*',
  456. 'qt/src/3rdparty/libgq*',
  457. 'qt/src/3rdparty/libmng*',
  458. 'qt/src/3rdparty/libtiff*',
  459. 'qt/src/3rdparty/patches*',
  460. 'qt/src/3rdparty/phonon*',
  461. 'qt/src/3rdparty/pixman*',
  462. 'qt/src/3rdparty/powervr*',
  463. 'qt/src/3rdparty/ptmalloc*',
  464. 'qt/src/3rdparty/s60*',
  465. 'qt/src/3rdparty/wayland*'
  466. ]
  467. # --------------------------------------------------------------- HELPERS
  468. import os, sys, platform, subprocess, shutil, re, fnmatch, multiprocessing, urllib, hashlib, tarfile
  469. from os.path import exists
  470. CPU_COUNT = max(2, multiprocessing.cpu_count()-1) # leave one CPU free
  471. def rchop(s, e):
  472. if s.endswith(e):
  473. return s[:-len(e)]
  474. return s
  475. def message(msg):
  476. sys.stdout.write(msg)
  477. sys.stdout.flush()
  478. def error(msg):
  479. message(msg+'\n')
  480. sys.exit(1)
  481. def shell(cmd):
  482. ret = os.system(cmd)
  483. if ret != 0:
  484. error("command failed: exit code %d" % ret)
  485. def get_output(*cmd):
  486. try:
  487. return subprocess.check_output(cmd, stderr=subprocess.STDOUT).strip()
  488. except:
  489. return None
  490. def rmdir(path):
  491. if exists(path):
  492. if platform.system() == 'Windows':
  493. shell('attrib -R %s\* /S' % path)
  494. shutil.rmtree(path)
  495. def mkdir_p(path):
  496. if not exists(path):
  497. os.makedirs(path)
  498. def get_version(basedir):
  499. mkdir_p(basedir)
  500. text = open(os.path.join(basedir, '..', 'VERSION'), 'r').read()
  501. if '-' not in text:
  502. return (text, text)
  503. version = text[:text.index('-')]
  504. os.chdir(os.path.join(basedir, '..'))
  505. hash = get_output('git', 'rev-parse', '--short', 'HEAD')
  506. if not hash:
  507. return (text, version)
  508. return ('%s-%s' % (version, hash), version)
  509. def qt_config(key, *opts):
  510. input, output = [], []
  511. input.extend(QT_CONFIG['common'])
  512. input.extend(QT_CONFIG[key])
  513. input.extend(opts)
  514. cfg = os.environ.get('WKHTMLTOX_QT_CONFIG')
  515. if cfg:
  516. input.extend(cfg.split())
  517. for arg in input:
  518. if not arg.startswith('remove:-'):
  519. output.append(arg)
  520. elif arg[1+arg.index(':'):] in output:
  521. output.remove(arg[1+arg.index(':'):])
  522. return ' '.join(output)
  523. def fpm_setup(cfg):
  524. input, output = {}, ''
  525. input.update(FPM_SETUP['common'])
  526. input.update(FPM_SETUP[cfg])
  527. for key in input:
  528. if type(input[key]) is list:
  529. for val in input[key]:
  530. output += ' %s "%s"' % (key, val)
  531. else:
  532. output += ' %s "%s"' % (key, input[key])
  533. return output, input
  534. def download_file(url, sha1, dir):
  535. name = url.split('/')[-1]
  536. loc = os.path.join(dir, name)
  537. if os.path.exists(loc):
  538. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  539. if hash == sha1:
  540. return loc
  541. os.remove(loc)
  542. message('Checksum mismatch for %s, re-downloading.\n' % name)
  543. def hook(cnt, bs, total):
  544. pct = int(cnt*bs*100/total)
  545. message("\rDownloading: %s [%d%%]" % (name, pct))
  546. urllib.urlretrieve(url, loc, reporthook=hook)
  547. message("\r")
  548. hash = hashlib.sha1(open(loc, 'rb').read()).hexdigest()
  549. if hash != sha1:
  550. os.remove(loc)
  551. error('Checksum mismatch for %s, aborting.' % name)
  552. message("\rDownloaded: %s [checksum OK]\n" % name)
  553. return loc
  554. def download_tarball(url, sha1, dir, name):
  555. loc = download_file(url, sha1, dir)
  556. tar = tarfile.open(loc)
  557. sub = tar.getnames()[0]
  558. if '/' in sub:
  559. sub = sub[:sub.index('/')]
  560. src = os.path.join(dir, sub)
  561. tgt = os.path.join(dir, name)
  562. rmdir(src)
  563. tar.extractall(dir)
  564. rmdir(tgt)
  565. os.rename(src, tgt)
  566. return tgt
  567. def _is_compiled(dst, loc):
  568. present = True
  569. for name in loc['result']:
  570. present = present and exists(os.path.join(dst, name))
  571. return present
  572. def build_deplibs(config, basedir):
  573. mkdir_p(os.path.join(basedir, config))
  574. dstdir = os.path.join(basedir, config, 'deplibs')
  575. vars = {'destdir': dstdir, 'mingw-w64': MINGW_W64_PREFIX.get(rchop(config, '-dbg'), '')}
  576. for lib in sorted(DEPENDENT_LIBS, key=lambda x: DEPENDENT_LIBS[x]['order']):
  577. cfg = None
  578. for key in DEPENDENT_LIBS[lib]['build']:
  579. if fnmatch.fnmatch(config, key):
  580. cfg = key
  581. if not cfg or _is_compiled(dstdir, DEPENDENT_LIBS[lib]['build'][cfg]):
  582. continue
  583. build_cfg = DEPENDENT_LIBS[lib]['build'][cfg]
  584. message('========== building: %s\n' % lib)
  585. srcdir = download_tarball(DEPENDENT_LIBS[lib]['url'], DEPENDENT_LIBS[lib]['sha1'],
  586. basedir, os.path.join(config, lib))
  587. for location, source, target in build_cfg.get('replace', []):
  588. data = open(os.path.join(srcdir, location), 'r').read()
  589. open(os.path.join(srcdir, location), 'w').write(data.replace(source, target % vars))
  590. os.chdir(srcdir)
  591. for command in build_cfg['commands']:
  592. shell(command % vars)
  593. if not type(build_cfg['result']) is list:
  594. for target in build_cfg['result']:
  595. mkdir_p(os.path.dirname(os.path.join(dstdir, target)))
  596. shutil.copy(build_cfg['result'][target], os.path.join(dstdir, target))
  597. os.chdir(dstdir)
  598. if not _is_compiled(dstdir, build_cfg):
  599. error("Unable to compile %s for your system, aborting." % lib)
  600. rmdir(srcdir)
  601. def check_running_on_debian():
  602. if not sys.platform.startswith('linux') or not exists('/etc/apt/sources.list'):
  603. error('This can only be run on a Debian/Ubuntu distribution, aborting.')
  604. if os.geteuid() != 0:
  605. error('This script must be run as root.')
  606. if platform.architecture()[0] == '64bit' and 'amd64' not in ARCH:
  607. ARCH.insert(0, 'amd64')
  608. PACKAGE_NAME = re.compile(r'ii\s+(.+?)\s+.*')
  609. def install_packages(*names):
  610. lines = get_output('dpkg-query', '--list').split('\n')
  611. avail = [PACKAGE_NAME.match(line).group(1) for line in lines if PACKAGE_NAME.match(line)]
  612. inst = [name for name in names if name in avail]
  613. if len(inst) != len(names):
  614. shell('apt-get update')
  615. shell('apt-get install --assume-yes %s' % (' '.join(names)))
  616. # --------------------------------------------------------------- Linux chroot
  617. ARCH = ['i386']
  618. def check_setup_schroot(config):
  619. check_running_on_debian()
  620. login = os.environ.get('SUDO_USER') or get_output('logname')
  621. if not login or login == 'root':
  622. error('Unable to determine the login for which schroot access is to be given.')
  623. def build_setup_schroot(config, basedir):
  624. install_packages('git', 'debootstrap', 'schroot', 'rinse', 'debian-archive-keyring')
  625. os.environ['HOME'] = '/tmp' # workaround bug in gem when home directory doesn't exist
  626. login = os.environ.get('SUDO_USER') or get_output('logname')
  627. chroot = config[1+config.rindex('-'):]
  628. for arch in ARCH:
  629. message('******************* %s-%s\n' % (chroot, arch))
  630. base_dir = os.environ.get('WKHTMLTOX_CHROOT') or '/var/chroot'
  631. root_dir = os.path.join(base_dir, 'wkhtmltopdf-%s-%s' % (chroot, arch))
  632. rmdir(root_dir)
  633. mkdir_p(root_dir)
  634. for command in CHROOT_SETUP[chroot]:
  635. # handle architecture-specific commands
  636. name = command[0]
  637. if ':' in name:
  638. if name[1+name.rindex(':'):] != arch:
  639. continue
  640. else:
  641. name = name[:name.rindex(':')]
  642. # handle commands
  643. if name == 'debootstrap':
  644. shell('debootstrap --arch=%(arch)s --variant=buildd %(distro)s %(dir)s %(url)s' % {
  645. 'arch': arch, 'dir': root_dir, 'distro': command[1], 'url': command[2] })
  646. elif name == 'rinse':
  647. cmd = (arch == 'i386' and 'linux32 rinse' or 'rinse')
  648. shell('%s --arch %s --distribution %s --directory %s' % (cmd, arch, command[1], root_dir))
  649. elif name == 'shell':
  650. cmd = (arch == 'i386' and 'linux32 chroot' or 'chroot')
  651. shell('%s %s %s' % (cmd, root_dir, command[1]))
  652. elif name == 'write_file':
  653. open(os.path.join(root_dir, command[1]), 'w').write(command[2].strip())
  654. elif name == 'append_file':
  655. open(os.path.join(root_dir, command[1]), 'a').write(command[2].strip())
  656. elif name == 'download_file':
  657. name = command[1].split('/')[-1]
  658. loc = os.path.join(root_dir, command[2], name)
  659. if exists(loc): os.remove(loc)
  660. def hook(cnt, bs, total):
  661. pct = int(cnt*bs*100/total)
  662. message("\rDownloading: %s [%d%%]" % (name, pct))
  663. urllib.urlretrieve(command[1], loc, reporthook=hook)
  664. message("\rDownloaded: %s%s\n" % (name, ' '*10))
  665. elif name == 'fpm_setup':
  666. args, cfg = fpm_setup(chroot)
  667. cmd = '#!/bin/sh\nXZ_OPT=-9 fpm --force %s --package ../%s-$1_linux-%s-$2.%s .\n'
  668. loc = os.path.join(root_dir, command[1])
  669. open(loc, 'w').write(cmd % (args, cfg['--name'], chroot, cfg['-t']))
  670. shell('chmod a+x %s' % loc)
  671. elif name == 'schroot_conf':
  672. cfg = open('/etc/schroot/chroot.d/wkhtmltopdf-%s-%s' % (chroot, arch), 'w')
  673. cfg.write('[wkhtmltopdf-%s-%s]\n' % (chroot, arch))
  674. cfg.write('type=directory\ndirectory=%s/\n' % root_dir)
  675. cfg.write('description=%s %s for wkhtmltopdf\n' % (command[1], arch))
  676. cfg.write('users=%s\nroot-users=root\n' % login)
  677. if arch == 'i386' and 'amd64' in ARCH:
  678. cfg.write('personality=linux32\n')
  679. cfg.close()
  680. def check_update_schroot(config):
  681. check_running_on_debian()
  682. if not get_output('schroot', '--list'):
  683. error('Unable to determine the list of available schroots.')
  684. def build_update_schroot(config, basedir):
  685. for name in get_output('schroot', '--list').split('\n'):
  686. message('******************* %s\n' % name[name.index('wkhtmltopdf-'):])
  687. shell('schroot -c %s -- /bin/bash /update.sh' % name[name.index('wkhtmltopdf-'):])
  688. def check_setup_mingw64(config):
  689. check_running_on_debian()
  690. def build_setup_mingw64(config, basedir):
  691. install_packages('build-essential', 'mingw-w64', 'nsis')
  692. def check_source_tarball(config):
  693. if not get_output('git', 'rev-parse', '--short', 'HEAD'):
  694. error("This can only be run inside a git checkout.")
  695. if not exists(os.path.join(os.getcwd(), 'qt', '.git')):
  696. error("Please initialize and download the Qt submodule before running this.")
  697. def _filter_tar(info):
  698. name = info.name[1+info.name.index('/'):]
  699. if name.endswith('.git') or [p for p in EXCLUDE_SRC_TARBALL if fnmatch.fnmatch(name, p)]:
  700. return None
  701. info.uid = info.gid = 1000
  702. info.uname = info.gname = 'wkhtmltopdf'
  703. return info
  704. def build_source_tarball(config, basedir):
  705. version, simple_version = get_version(basedir)
  706. root_dir = os.path.realpath(os.path.join(basedir, '..'))
  707. os.chdir(os.path.join(root_dir, 'qt'))
  708. shell('git clean -fdx')
  709. shell('git reset --hard HEAD')
  710. os.chdir(root_dir)
  711. shell('git clean -fdx')
  712. shell('git reset --hard HEAD')
  713. shell('git submodule update')
  714. with tarfile.open('wkhtmltox-%s.tar.bz2' % version, 'w:bz2') as tar:
  715. tar.add('.', 'wkhtmltox-%s/' % version, filter=_filter_tar)
  716. # --------------------------------------------------------------- MSVC (2008-2013)
  717. MSVC_LOCATION = {
  718. 'msvc2008': 'VS90COMNTOOLS',
  719. 'msvc2010': 'VS100COMNTOOLS',
  720. 'msvc2012': 'VS110COMNTOOLS',
  721. 'msvc2013': 'VS120COMNTOOLS'
  722. }
  723. def check_msvc(config):
  724. version, arch = rchop(config, '-dbg').split('-')
  725. env_var = MSVC_LOCATION[version]
  726. if not env_var in os.environ:
  727. error("%s does not seem to be installed." % version)
  728. vcdir = os.path.join(os.environ[env_var], '..', '..', 'VC')
  729. if not exists(os.path.join(vcdir, 'vcvarsall.bat')):
  730. error("%s: unable to find vcvarsall.bat" % version)
  731. if arch == 'win32' and not exists(os.path.join(vcdir, 'bin', 'cl.exe')):
  732. error("%s: unable to find the x86 compiler" % version)
  733. if arch == 'win64' and not exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')) \
  734. and not exists(os.path.join(vcdir, 'bin', 'x86_amd64', 'cl.exe')):
  735. error("%s: unable to find the amd64 compiler" % version)
  736. def build_msvc(config, basedir):
  737. msvc, arch = rchop(config, '-dbg').split('-')
  738. vcdir = os.path.join(os.environ[MSVC_LOCATION[msvc]], '..', '..', 'VC')
  739. vcarg = 'x86'
  740. if arch == 'win64':
  741. if exists(os.path.join(vcdir, 'bin', 'amd64', 'cl.exe')):
  742. vcarg = 'amd64'
  743. else:
  744. vcarg = 'x86_amd64'
  745. python = sys.executable
  746. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  747. os.path.join(vcdir, 'vcvarsall.bat'), vcarg, python), stdout=subprocess.PIPE, shell=True)
  748. stdout, _ = process.communicate()
  749. exitcode = process.wait()
  750. if exitcode != 0:
  751. error("%s: unable to initialize the environment" % msvc)
  752. os.environ.update(eval(stdout.strip()))
  753. build_msvc_common(config, basedir)
  754. # --------------------------------------------------------------- MSVC via Windows SDK 7.1
  755. def check_msvc_winsdk71(config):
  756. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  757. if pfile in os.environ and exists(os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')):
  758. return
  759. error("Unable to detect the location of Windows SDK 7.1")
  760. def build_msvc_winsdk71(config, basedir):
  761. arch = config[config.rindex('-'):]
  762. setenv = None
  763. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  764. if not pfile in os.environ:
  765. continue
  766. setenv = os.path.join(os.environ[pfile], 'Microsoft SDKs', 'Windows', 'v7.1', 'Bin', 'SetEnv.cmd')
  767. mode = debug and '/Debug' or '/Release'
  768. if arch == 'win64':
  769. args = '/2008 /x64 %s' % mode
  770. else:
  771. args = '/2008 /x86 %s' % mode
  772. python = sys.executable
  773. process = subprocess.Popen('("%s" %s>nul)&&"%s" -c "import os, sys; sys.stdout.write(repr(dict(os.environ)))"' % (
  774. setenv, args, python), stdout=subprocess.PIPE, shell=True)
  775. stdout, _ = process.communicate()
  776. exitcode = process.wait()
  777. if exitcode != 0:
  778. error("unable to initialize the environment for Windows SDK 7.1")
  779. os.environ.update(eval(stdout.strip()))
  780. build_msvc_common(config, basedir)
  781. def build_msvc_common(config, basedir):
  782. version, simple_version = get_version(basedir)
  783. build_deplibs(config, basedir)
  784. libdir = os.path.join(basedir, config, 'deplibs')
  785. qtdir = os.path.join(basedir, config, 'qt')
  786. mkdir_p(qtdir)
  787. configure_args = qt_config('msvc',
  788. '-I %s\\include' % libdir,
  789. '-L %s\\lib' % libdir,
  790. 'OPENSSL_LIBS="-L%s\\\\lib -lssleay32 -llibeay32 -lUser32 -lAdvapi32 -lGdi32 -lCrypt32"' % libdir.replace('\\', '\\\\'))
  791. os.chdir(qtdir)
  792. if not exists('is_configured'):
  793. shell('%s\\..\\qt\\configure.exe %s' % (basedir, configure_args))
  794. open('is_configured', 'w').write('')
  795. shell('nmake')
  796. appdir = os.path.join(basedir, config, 'app')
  797. mkdir_p(appdir)
  798. os.chdir(appdir)
  799. rmdir('bin')
  800. mkdir_p('bin')
  801. os.environ['WKHTMLTOX_VERSION'] = version
  802. shell('%s\\bin\\qmake %s\\..\\wkhtmltopdf.pro' % (qtdir, basedir))
  803. shell('nmake')
  804. found = False
  805. for pfile in ['ProgramFiles(x86)', 'ProgramFiles']:
  806. if not pfile in os.environ or not exists(os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')):
  807. continue
  808. found = True
  809. makensis = os.path.join(os.environ[pfile], 'NSIS', 'makensis.exe')
  810. os.chdir(os.path.join(basedir, '..'))
  811. shell('"%s" /DVERSION=%s /DSIMPLE_VERSION=%s /DTARGET=%s wkhtmltox.nsi' % \
  812. (makensis, version, simple_version, config))
  813. if not found:
  814. message("\n\nCould not build installer as NSIS was not found.\n")
  815. # ------------------------------------------------ MinGW-W64 Cross Environment
  816. MINGW_W64_PREFIX = {
  817. 'mingw-w64-cross-win32' : 'i686-w64-mingw32',
  818. 'mingw-w64-cross-win64' : 'x86_64-w64-mingw32',
  819. }
  820. def check_mingw64_cross(config):
  821. shell('%s-gcc --version' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  822. def build_mingw64_cross(config, basedir):
  823. version, simple_version = get_version(basedir)
  824. build_deplibs(config, basedir)
  825. libdir = os.path.join(basedir, config, 'deplibs')
  826. qtdir = os.path.join(basedir, config, 'qt')
  827. configure_args = qt_config('mingw-w64-cross',
  828. '--prefix=%s' % qtdir,
  829. '-I %s/include' % libdir,
  830. '-L %s/lib' % libdir,
  831. '-device-option CROSS_COMPILE=%s-' % MINGW_W64_PREFIX[rchop(config, '-dbg')])
  832. os.environ['OPENSSL_LIBS'] = '-lssl -lcrypto -L %s/lib -lws2_32 -lgdi32 -lcrypt32' % libdir
  833. mkdir_p(qtdir)
  834. os.chdir(qtdir)
  835. if not exists('is_configured'):
  836. for var in ['CFLAGS', 'CXXFLAGS']:
  837. os.environ[var] = '-w'
  838. shell('%s/../qt/configure %s' % (basedir, configure_args))
  839. shell('touch is_configured')
  840. shell('make -j%d' % CPU_COUNT)
  841. appdir = os.path.join(basedir, config, 'app')
  842. mkdir_p(appdir)
  843. os.chdir(appdir)
  844. shell('rm -f bin/*')
  845. # set up cross compiling prefix correctly
  846. os.environ['WKHTMLTOX_VERSION'] = version
  847. shell('%s/bin/qmake -set CROSS_COMPILE %s-' % (qtdir, MINGW_W64_PREFIX[rchop(config, '-dbg')]))
  848. shell('%s/bin/qmake -spec win32-g++-4.6 %s/../wkhtmltopdf.pro' % (qtdir, basedir))
  849. shell('make')
  850. shutil.copy('bin/libwkhtmltox0.a', 'bin/wkhtmltox.lib')
  851. os.chdir(os.path.join(basedir, '..'))
  852. shell('makensis -DVERSION=%s -DSIMPLE_VERSION=%s -DTARGET=%s wkhtmltox.nsi' % \
  853. (version, simple_version, config))
  854. # -------------------------------------------------- Linux schroot environment
  855. def check_linux_schroot(config):
  856. shell('schroot -c wkhtmltopdf-%s -- gcc --version' % rchop(config, '-dbg'))
  857. def build_linux_schroot(config, basedir):
  858. version, simple_version = get_version(basedir)
  859. dir = os.path.join(basedir, config)
  860. script = os.path.join(dir, 'build.sh')
  861. dist = os.path.join(dir, 'dist')
  862. mkdir_p(dir)
  863. rmdir(dist)
  864. configure_args = qt_config('posix', '--prefix=%s' % os.path.join(dir, 'qt'))
  865. lines = ['#!/bin/bash']
  866. lines.append('# start of autogenerated build script')
  867. lines.append('mkdir -p app qt')
  868. lines.append('cd qt')
  869. if config == 'centos5-i386':
  870. lines.append('export CFLAGS="-march=i486 -w"')
  871. lines.append('export CXXFLAGS="-march=i486 -w"')
  872. else:
  873. for var in ['CFLAGS', 'CXXFLAGS']:
  874. lines.append('export %s="-w"' % var)
  875. lines.append('if [ ! -f is_configured ]; then')
  876. lines.append(' ../../../qt/configure %s || exit 1' % configure_args)
  877. lines.append(' touch is_configured')
  878. lines.append('fi')
  879. lines.append('if ! make -j%d -q; then\n make -j%d || exit 1\nfi' % (CPU_COUNT, CPU_COUNT))
  880. lines.append('cd ../app')
  881. lines.append('rm -f bin/*')
  882. lines.append('export WKHTMLTOX_VERSION=%s' % version)
  883. lines.append('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  884. lines.append('make install INSTALL_ROOT=%s || exit 1' % dist)
  885. lines.append('cd ..')
  886. lines.append('/fpm_package.sh %s %s' % (version, config[1+config.index('-'):]))
  887. lines.append('# end of build script')
  888. open(script, 'w').write('\n'.join(lines))
  889. os.chdir(dir)
  890. shell('chmod +x build.sh')
  891. shell('schroot -c wkhtmltopdf-%s -- ./build.sh' % rchop(config, '-dbg'))
  892. # -------------------------------------------------- POSIX local environment
  893. def check_posix_local(config):
  894. pass
  895. def build_posix_local(config, basedir):
  896. version, simple_version = get_version(basedir)
  897. app = os.path.join(basedir, config, 'app')
  898. qtdir = os.path.join(basedir, config, 'qt')
  899. dist = os.path.join(basedir, config, 'wkhtmltox-%s' % version)
  900. make = get_output('which gmake') and 'gmake' or 'make'
  901. mkdir_p(qt)
  902. mkdir_p(app)
  903. rmdir(dist)
  904. mkdir_p(os.path.join(dist, 'bin'))
  905. mkdir_p(os.path.join(dist, 'include', 'wkhtmltox'))
  906. mkdir_p(os.path.join(dist, 'lib'))
  907. os.chdir(qt)
  908. if not exists('is_configured'):
  909. shell('../../../qt/configure %s' % qt_config('posix', '--prefix=%s' % qtdir))
  910. shell('touch is_configured')
  911. if subprocess.call([make, '-j%d' % CPU_COUNT]):
  912. shell('%s -j%d' % (make, CPU_COUNT))
  913. os.chdir(app)
  914. shell('rm -f bin/*')
  915. os.environ['WKHTMLTOX_VERSION'] = version
  916. shell('../qt/bin/qmake ../../../wkhtmltopdf.pro')
  917. shell('%s -j%d' % (make, CPU_COUNT))
  918. shell('cp bin/wkhtmlto* ../wkhtmltox-%s/bin' % version)
  919. shell('cp -P bin/libwkhtmltox*.so.* ../wkhtmltox-%s/lib' % version)
  920. shell('cp ../../../include/wkhtmltox/*.h ../wkhtmltox-%s/include/wkhtmltox' % version)
  921. shell('cp ../../../include/wkhtmltox/dll*.inc ../wkhtmltox-%s/include/wkhtmltox' % version)
  922. os.chdir(basedir)
  923. shell('tar -c -v -f ../wkhtmltox-%s_local-%s.tar wkhtmltox-%s/' % (version, platform.node(), version))
  924. shell('xz --compress --force --verbose -9 ../wkhtmltox-%s_local-%s.tar' % (version, platform.node()))
  925. # --------------------------------------------------------------- OS X
  926. def check_osx(config):
  927. if not platform.system() == 'Darwin' or not platform.mac_ver()[0]:
  928. error('This can only be run on a OS X system!')
  929. if not get_output('xcode-select', '--print-path'):
  930. error('Xcode is not installed, aborting.')
  931. if not get_output('which', 'fpm'):
  932. error('Please install fpm by running "sudo gem install fpm --no-ri --no-rdoc"')
  933. def build_osx(config, basedir):
  934. version, simple_version = get_version(basedir)
  935. build_deplibs(config, basedir)
  936. osxver = platform.mac_ver()[0][:platform.mac_ver()[0].rindex('.')]
  937. framework = config.split('-')[1]
  938. if osxver == '10.6':
  939. osxcfg = '-%s -platform macx-g++42' % framework
  940. else:
  941. osxcfg = '-%s -platform unsupported/macx-clang' % framework
  942. flags = ''
  943. if framework == 'carbon' and osxver != '10.6':
  944. for item in ['CFLAGS', 'CXXFLAGS']:
  945. flags += '"QMAKE_%s += %s" ' % (item, '-fvisibility=hidden -fvisibility-inlines-hidden')
  946. def get_dir(name):
  947. return os.path.join(basedir, config, name)
  948. configure_args = qt_config('osx', osxcfg,
  949. '--prefix=%s' % get_dir('qt'),
  950. '-I %s/include' % get_dir('deplibs'),
  951. '-L %s/lib' % get_dir('deplibs'))
  952. rmdir(get_dir('dist'))
  953. rmdir(get_dir('pkg'))
  954. mkdir_p(get_dir('qt'))
  955. mkdir_p(get_dir('app'))
  956. mkdir_p(get_dir('pkg'))
  957. os.chdir(get_dir('qt'))
  958. if not exists('is_configured'):
  959. shell('../../../qt/configure %s' % configure_args)
  960. shell('touch is_configured')
  961. shell('make -j%d' % CPU_COUNT)
  962. os.chdir(get_dir('app'))
  963. shell('rm -f bin/*')
  964. os.environ['WKHTMLTOX_VERSION'] = version
  965. shell('../qt/bin/qmake %s ../../../wkhtmltopdf.pro' % flags)
  966. shell('make -j%d' % CPU_COUNT)
  967. if osxver not in ['10.6', '10.7']:
  968. for item in ['wkhtmltoimage', 'wkhtmltopdf', 'libwkhtmltox.%s.dylib' % simple_version]:
  969. shell(' '.join([
  970. 'install_name_tool', '-change',
  971. '/System/Library/Frameworks/CoreText.framework/Versions/A/CoreText',
  972. '/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/CoreText',
  973. 'bin/'+item]))
  974. shell('make install INSTALL_ROOT=%s' % get_dir('dist'))
  975. def _osx_tar(info):
  976. info.uid = info.gid = 0
  977. info.uname = 'root'
  978. info.gname = 'wheel'
  979. return info
  980. # create tarballs for application and unxz
  981. os.chdir(get_dir('dist'))
  982. with tarfile.open('../pkg/app.tar', 'w') as tar:
  983. tar.add('.', './', filter=_osx_tar)
  984. shell('xz --compress --force --verbose -9 ../pkg/app.tar')
  985. with tarfile.open('../pkg/unxz.tar.gz', 'w:gz') as tar:
  986. unxz = get_output('which', 'unxz')
  987. lzma = os.path.join(os.path.dirname(unxz), '..', 'lib', 'liblzma.5.dylib')
  988. tar.add(unxz, './bin/unxz', filter=_osx_tar)
  989. tar.add(lzma, './lib/liblzma.5.dylib', filter=_osx_tar)
  990. args, cfg = fpm_setup('osx')
  991. open('../extract.sh', 'w').write("""#!/bin/bash
  992. TGTDIR=/usr/local
  993. BASEDIR=%s
  994. if [ -x $TGTDIR/bin/unxz ]
  995. then
  996. cd $TGTDIR;
  997. tar zxf $BASEDIR/unxz.tar.gz
  998. fi
  999. cd $BASEDIR
  1000. $TGTDIR/bin/unxz -k $BASEDIR/app.tar.xz
  1001. cd $TGTDIR
  1002. tar xf $BASEDIR/app.tar
  1003. rm -f $BASEDIR/app.tar
  1004. """ % cfg['--prefix'])
  1005. os.chdir(os.path.join(basedir, config))
  1006. shell('fpm --force %s --package ../%s-%s_%s.pkg .' % (args.replace('$1', version), cfg['--name'], version, config))
  1007. # --------------------------------------------------------------- command line
  1008. def usage(exit_code=2):
  1009. message("Usage: scripts/build.py <target> [-clean] [-debug]\n\nThe supported targets are:\n")
  1010. opts = list(BUILDERS.keys())
  1011. opts.sort()
  1012. for opt in opts:
  1013. message('* %s\n' % opt)
  1014. sys.exit(exit_code)
  1015. def main():
  1016. rootdir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
  1017. basedir = os.path.join(rootdir, 'static-build')
  1018. if len(sys.argv) == 1:
  1019. usage(0)
  1020. config = sys.argv[1]
  1021. if config not in BUILDERS:
  1022. usage()
  1023. for arg in sys.argv[2:]:
  1024. if not arg in ['-clean', '-debug']:
  1025. usage()
  1026. final_config = config
  1027. if '-debug' in sys.argv[2:]:
  1028. final_config += '-dbg'
  1029. QT_CONFIG['common'].extend(['remove:-release', 'remove:-webkit', '-debug', '-webkit-debug'])
  1030. if '-clean' in sys.argv[2:]:
  1031. rmdir(os.path.join(basedir, config))
  1032. os.chdir(rootdir)
  1033. globals()['check_%s' % BUILDERS[config]](final_config)
  1034. globals()['build_%s' % BUILDERS[config]](final_config, basedir)
  1035. if __name__ == '__main__':
  1036. main()