build.py 51 KB

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