build.py 48 KB

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