build.py 46 KB

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