gnu: calibre: Wrap QTWEBENGINEPROCESS_PATH.
[jackhill/guix/guix.git] / gnu / packages / ebook.scm
CommitLineData
947ae545 1;;; GNU Guix --- Functional package management for GNU
7d1f8d4f 2;;; Copyright © 2015, 2016 Andreas Enge <andreas@enge.fr>
152d6bf0 3;;; Copyright © 2016, 2018 Efraim Flashner <efraim@flashner.co.il>
37e8a2e2 4;;; Copyright © 2016, 2017 Alex Griffin <a@ajgrf.com>
29f61501 5;;; Copyright © 2017, 2019, 2020 Brendan Tildesley <mail@brendan.scot>
f70f3407 6;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
8cd23410 7;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
6266a48d 8;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
947ae545
AE
9;;;
10;;; This file is part of GNU Guix.
11;;;
12;;; GNU Guix is free software; you can redistribute it and/or modify it
13;;; under the terms of the GNU General Public License as published by
14;;; the Free Software Foundation; either version 3 of the License, or (at
15;;; your option) any later version.
16;;;
17;;; GNU Guix is distributed in the hope that it will be useful, but
18;;; WITHOUT ANY WARRANTY; without even the implied warranty of
19;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;;; GNU General Public License for more details.
21;;;
22;;; You should have received a copy of the GNU General Public License
23;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
24
25(define-module (gnu packages ebook)
affaf98f 26 #:use-module ((guix licenses) #:prefix license:)
947ae545
AE
27 #:use-module (guix packages)
28 #:use-module (guix download)
6f0ae143 29 #:use-module (guix git-download)
a34816ef 30 #:use-module (guix build-system gnu)
b8ac8c28
AE
31 #:use-module (guix build-system python)
32 #:use-module (gnu packages)
d6ef422f
DM
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages curl)
b8ac8c28 35 #:use-module (gnu packages databases)
b3399a09 36 #:use-module (gnu packages fonts)
b8ac8c28
AE
37 #:use-module (gnu packages fontutils)
38 #:use-module (gnu packages freedesktop)
d6ef422f 39 #:use-module (gnu packages fribidi)
04842543 40 #:use-module (gnu packages gcc)
d6ef422f 41 #:use-module (gnu packages gtk)
eeba7d3a 42 #:use-module (gnu packages gnome)
b8ac8c28
AE
43 #:use-module (gnu packages glib)
44 #:use-module (gnu packages icu4c)
45 #:use-module (gnu packages image)
d243b41d 46 #:use-module (gnu packages javascript)
b8ac8c28 47 #:use-module (gnu packages libusb)
d79ec4fd 48 #:use-module (gnu packages libreoffice)
b8ac8c28
AE
49 #:use-module (gnu packages pdf)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages python)
1b2f753d 52 #:use-module (gnu packages python-web)
44d10b1f 53 #:use-module (gnu packages python-xyz)
b8ac8c28 54 #:use-module (gnu packages qt)
9ef5940c 55 #:use-module (gnu packages serialization)
cd0322a3 56 #:use-module (gnu packages sqlite)
33dc54b0 57 #:use-module (gnu packages time)
cc2b77df 58 #:use-module (gnu packages tls)
d94a99ec 59 #:use-module (gnu packages web)
d6ef422f 60 #:use-module (gnu packages xml)
7c041187
JL
61 #:use-module (gnu packages xorg)
62 #:use-module (gnu packages wxwidgets))
947ae545
AE
63
64(define-public chmlib
65 (package
66 (name "chmlib")
67 (version "0.40")
68 (source (origin
69 (method url-fetch)
70 (uri (string-append "http://www.jedrea.com/chmlib/chmlib-"
71 version ".tar.bz2"))
72 (sha256
73 (base32
a34816ef 74 "18zzb4x3z0d7fjh1x5439bs62dmgsi4c1pg3qyr7h5gp1i5xcj9l"))
fc1adab1 75 (patches (search-patches "chmlib-inttypes.patch"))))
947ae545
AE
76 (build-system gnu-build-system)
77 (home-page "http://www.jedrea.com/chmlib/")
78 (synopsis "Library for CHM files")
79 (description "CHMLIB is a library for dealing with ITSS/CHM format files.")
affaf98f 80 (license license:lgpl2.1+)))
b8ac8c28
AE
81
82(define-public calibre
83 (package
84 (name "calibre")
d79ec4fd 85 (version "4.18.0")
b8ac8c28
AE
86 (source
87 (origin
88 (method url-fetch)
89 (uri (string-append "http://download.calibre-ebook.com/"
90 version "/calibre-"
91 version ".tar.xz"))
92 (sha256
9acd40fe 93 (base32
d79ec4fd 94 "0w9pcfvskjh4v00vjw3i6hzrafy863pgsmmqdx4lffip3p856brw"))
b8ac8c28
AE
95 (modules '((guix build utils)))
96 (snippet
97 '(begin
d79ec4fd 98 ;; Unbundle python2-odfpy.
68435a7f 99 (delete-file-recursively "src/odf")
d79ec4fd
MB
100 ;; Disable test that attempts to load it.
101 (substitute* "setup/test.py"
102 ((".*SRC, 'odf'.*")
103 ""))
104
105 ;; Remove unneeded resources.
f3f017db
BT
106 (delete-file "resources/viewer.js")
107 (delete-file "resources/viewer.html")
108 (delete-file "resources/mozilla-ca-certs.pem")
109 (delete-file "resources/calibre-portable.bat")
110 (delete-file "resources/calibre-portable.sh")
68435a7f 111 #t))
15871b40 112 (patches (search-patches "calibre-no-updates-dialog.patch"
cbe399e7 113 "calibre-remove-test-sqlite.patch" ; TODO: fix test.
15871b40 114 "calibre-remove-test-unrar.patch"))))
b8ac8c28
AE
115 (build-system python-build-system)
116 (native-inputs
117 `(("pkg-config" ,pkg-config)
c5ea9120 118 ("qtbase" ,qtbase) ; for qmake
9b7dcc27 119 ("python2-flake8" ,python2-flake8)
b8ac8c28 120 ("xdg-utils" ,xdg-utils)))
b8ac8c28
AE
121 (inputs
122 `(("chmlib" ,chmlib)
123 ("fontconfig" ,fontconfig)
13068a8c 124 ("font-liberation" ,font-liberation)
b8ac8c28 125 ("glib" ,glib)
d79ec4fd
MB
126 ("hunspell" ,hunspell)
127 ("hyphen" ,hyphen)
b8ac8c28 128 ("icu4c" ,icu4c)
d243b41d 129 ("js-mathjax" ,js-mathjax)
b8ac8c28
AE
130 ("libmtp" ,libmtp)
131 ("libpng" ,libpng)
132 ("libusb" ,libusb)
df00e148 133 ("openssl" ,openssl)
9132212f 134 ("optipng" ,optipng)
b8ac8c28 135 ("podofo" ,podofo)
9b7dcc27 136 ("poppler" ,poppler)
b8ac8c28
AE
137 ("python" ,python-2)
138 ("python2-apsw" ,python2-apsw)
d79ec4fd 139 ("python2-beautifulsoup4" ,python2-beautifulsoup4)
eeba7d3a 140 ("python2-chardet" ,python2-chardet)
b8ac8c28 141 ("python2-cssselect" ,python2-cssselect)
4e6f8a14 142 ("python2-css-parser" ,python2-css-parser)
b8ac8c28
AE
143 ("python2-dateutil" ,python2-dateutil)
144 ("python2-dbus" ,python2-dbus)
9b7dcc27 145 ("python2-dnspython" ,python2-dnspython)
bf4a40db 146 ("python2-dukpy" ,python2-dukpy)
d94a99ec 147 ("python2-feedparser" ,python2-feedparser)
adc25b68 148 ("python2-html2text" ,python2-html2text)
026ebc14 149 ("python2-html5-parser" ,python2-html5-parser)
4f299020 150 ("python2-html5lib" ,python2-html5lib)
b8ac8c28 151 ("python2-lxml" ,python2-lxml)
29ec0851 152 ("python2-markdown" ,python2-markdown)
b8ac8c28 153 ("python2-mechanize" ,python2-mechanize)
9ef5940c
MR
154 ;; python2-msgpack is needed for the network content server to work.
155 ("python2-msgpack" ,python2-msgpack)
b8ac8c28 156 ("python2-netifaces" ,python2-netifaces)
68435a7f 157 ("python2-odfpy" ,python2-odfpy)
2fbec762 158 ("python2-pillow" ,python2-pillow)
4f299020 159 ("python2-psutil" ,python2-psutil)
9b7dcc27 160 ("python2-pygments" ,python2-pygments)
d79ec4fd 161 ("python2-pyqtwebengine" ,python2-pyqtwebengine)
c5ea9120 162 ("python2-pyqt" ,python2-pyqt)
b8ac8c28 163 ("python2-sip" ,python2-sip)
f70f3407 164 ("python2-regex" ,python2-regex)
d79ec4fd 165 ("qtwebengine" ,qtwebengine)
b8ac8c28
AE
166 ("sqlite" ,sqlite)))
167 (arguments
168 `(#:python ,python-2
e89aceab
HG
169 ;; Calibre is using setuptools by itself, but the setup.py is not
170 ;; compatible with the shim wrapper (taken from pip) we are using.
171 #:use-setuptools? #f
b8ac8c28 172 #:phases
b111bdb6 173 (modify-phases %standard-phases
1326166e
BT
174 (add-after 'unpack 'patch-source
175 (lambda _
176 (substitute* "src/calibre/linux.py"
177 ;; We can't use the uninstaller in Guix. Don't build it.
178 (("self\\.create_uninstaller()") ""))
179 #t))
d79ec4fd
MB
180 (add-after 'patch-source-shebangs 'patch-more-shebangs
181 (lambda _
182 ;; Patch various inline shebangs.
183 (substitute* '("src/calibre/gui2/preferences/tweaks.py"
184 "src/calibre/gui2/dialogs/custom_recipes.py"
185 "setup/install.py"
186 "setup/linux-installer.sh")
187 (("#!/usr/bin/env python")
188 (string-append "#!" (which "python")))
189 (("#!/bin/sh")
190 (string-append "#!" (which "sh"))))
191 #t))
f70f3407
RJ
192 (add-after 'unpack 'dont-load-remote-icons
193 (lambda _
194 (substitute* "setup/plugins_mirror.py"
195 (("href=\"//calibre-ebook.com/favicon.ico\"")
196 "href=\"favicon.ico\""))
197 #t))
b111bdb6 198 (add-before 'build 'configure
6e1ab5fa 199 (lambda* (#:key inputs outputs #:allow-other-keys)
b8ac8c28 200 (let ((podofo (assoc-ref inputs "podofo"))
6e1ab5fa 201 (pyqt (assoc-ref inputs "python2-pyqt"))
d79ec4fd 202 (python-sip (assoc-ref inputs "python2-sip"))
6e1ab5fa 203 (out (assoc-ref outputs "out")))
b8ac8c28 204 (substitute* "setup/build_environment.py"
d79ec4fd
MB
205 (("= get_sip_dir\\(\\)")
206 (string-append "= '" pyqt "/share/sip'")))
207
b65b78ff
MO
208 (substitute* "src/calibre/ebooks/pdf/pdftohtml.py"
209 (("PDFTOHTML = 'pdftohtml'")
210 (string-append "PDFTOHTML = \"" (assoc-ref inputs "poppler")
6e1ab5fa
BT
211 "/bin/pdftohtml\"")))
212
213 ;; Calibre thinks we are installing desktop files into a home
214 ;; directory, but here we butcher the script in to installing
215 ;; to calibres /share directory.
216 (setenv "XDG_DATA_HOME" (string-append out "/share"))
217 (substitute* "src/calibre/linux.py"
218 (("'~/.local/share'") "''"))
219
d79ec4fd
MB
220 ;; 'python setup.py rapydscript' uses QtWebEngine, which
221 ;; needs to create temporary files in $HOME.
222 (setenv "HOME" "/tmp")
223
224 ;; XXX: QtWebEngine will fail if no fonts are available. This
225 ;; can likely be removed when fontconfig has been patched to
226 ;; include TrueType fonts by default.
227 (symlink (string-append (assoc-ref inputs "font-liberation")
228 "/share/fonts")
229 "/tmp/.fonts")
230
231 (setenv "SIP_BIN" (string-append python-sip "/bin/sip"))
b8ac8c28 232 (setenv "PODOFO_INC_DIR" (string-append podofo "/include/podofo"))
ae16afe9 233 (setenv "PODOFO_LIB_DIR" (string-append podofo "/lib"))
b01cde1a
BT
234 ;; This informs the tests we are a continuous integration
235 ;; environment and thus have no networking.
236 (setenv "CI" "true")
4bcd0647
BT
237 ;; The Qt test complains about being unable to load all image plugins, and I
238 ;; notice the available plugins list it shows lacks 'svg'. Adding qtsvg doesn't
239 ;; fix it, so I'm not sure how to fix it. TODO: Fix test and remove this.
240 (setenv "SKIP_QT_BUILD_TEST" "true")
ae16afe9 241 #t)))
d243b41d
BT
242 (add-after 'build 'build-extra
243 (lambda* (#:key inputs #:allow-other-keys)
421c5e92
BT
244 (invoke "python2" "setup.py" "mathjax""--system-mathjax"
245 "--path-to-mathjax" (string-append
246 (assoc-ref inputs "js-mathjax")
247 "/share/javascript/mathjax"))
b0038957 248 (invoke "python2" "setup.py" "rapydscript")))
fd3eac4d
BT
249 (replace 'wrap
250 ;; Here we wrap PYTHONPATH exactly as it would be in
251 ;; python-build-system, plus the addition of
252 ;; QTWEBENGINEPROCESS_PATH, fixing a bug where Calibre would not
253 ;; find Qtwebengine.
254 (lambda* (#:key inputs outputs #:allow-other-keys)
255 (let* ((out (assoc-ref outputs "out"))
256 (bin (string-append out "/bin"))
257 (python (assoc-ref inputs "python"))
258 (site-packages
259 (cons (string-append out "/lib/python"
260 (python-version python)
261 "/site-packages")
262 (search-path-as-string->list (getenv "PYTHONPATH"))))
263 (qtwebengineprocess
264 (string-append (assoc-ref inputs "qtwebengine")
265 "/lib/qt5/libexec/QtWebEngineProcess")))
266 (for-each (lambda (program)
267 (wrap-program program
268 `("QTWEBENGINEPROCESS_PATH" = (,qtwebengineprocess))
269 `("PYTHONPATH" prefix ,site-packages)))
270 (find-files bin ".")))
271 #t))
d6dfe8b6
BT
272 (add-after 'install 'install-man-pages
273 (lambda* (#:key outputs #:allow-other-keys)
274 (copy-recursively
275 "man-pages"
276 (string-append (assoc-ref outputs "out") "/share/man"))
277 #t))
13068a8c
BT
278 ;; The font TTF files are used in some miscellaneous tests, so we
279 ;; unbundle them here to avoid patching the tests.
280 (add-after 'install 'unbundle-font-liberation
b3399a09 281 (lambda* (#:key inputs outputs #:allow-other-keys)
13068a8c
BT
282 (let ((font-dest (string-append (assoc-ref outputs "out")
283 "/share/calibre/fonts/liberation"))
284 (font-src (string-append (assoc-ref inputs "font-liberation")
285 "/share/fonts/truetype")))
286 (delete-file-recursively font-dest)
287 (symlink font-src font-dest))
b3399a09 288 #t)))))
2ea6d499 289 (home-page "https://calibre-ebook.com/")
b8ac8c28 290 (synopsis "E-book library management software")
8572adb2
TGR
291 (description "Calibre is an e-book library manager. It can view, convert
292and catalog e-books in most of the major e-book formats. It can also talk
293to many e-book reader devices. It can go out to the Internet and fetch
b8ac8c28 294metadata for books. It can download newspapers and convert them into
8572adb2 295e-books for convenient reading.")
affaf98f
BT
296 ;; Calibre is largely GPL3+, but includes a number of components covered
297 ;; by other licenses. See COPYRIGHT for more details.
298 (license (list license:gpl3+
299 license:gpl2+
300 license:lgpl2.1+
301 license:lgpl2.1
302 license:bsd-3
303 license:expat
304 license:zpl2.1
305 license:asl2.0
306 license:public-domain
307 license:silofl1.1
308 license:cc-by-sa3.0))))
84a52639
DM
309
310(define-public liblinebreak
311 (package
312 (name "liblinebreak")
313 (version "2.1")
314 (source (origin
315 (method url-fetch)
316 (uri (string-append "mirror://sourceforge/vimgadgets"
317 "/liblinebreak/" version
318 "/liblinebreak-" version ".tar.gz"))
319 (sha256
320 (base32
321 "1f36dbq7nc77lln1by2n1yl050g9dc63viawhs3gc3169mavm36x"))))
322 (build-system gnu-build-system)
323 (home-page "http://vimgadgets.sourceforge.net/liblinebreak/")
324 (synopsis "Library for detecting where linebreaks are allowed in text")
325 (description "@code{liblinebreak} is an implementation of the line
326breaking algorithm as described in Unicode 6.0.0 Standard Annex 14,
327Revision 26. It breaks lines that contain Unicode characters. It is
328designed to be used in a generic text renderer.")
329 (license license:zlib)))
d6ef422f
DM
330
331(define-public fbreader
332 (package
333 (name "fbreader")
334 (version "0.99.6")
335 (source (origin
6f0ae143
EF
336 (method git-fetch)
337 (uri (git-reference
338 (url "https://github.com/geometer/FBReader")
339 (commit (string-append version "-freebsdport"))))
340 (file-name (git-file-name name version))
d6ef422f
DM
341 (sha256
342 (base32
6f0ae143 343 "0c0s4silpax74kwfz3dfmzn4lkv6jsyb800vfak166vii0hvbv3d"))
152d6bf0 344 (patches (search-patches "fbreader-curl-7.62.patch"))))
d6ef422f
DM
345 (build-system gnu-build-system)
346 (inputs
347 `(("curl" ,curl)
348 ("expat" ,expat)
349 ("fribidi" ,fribidi)
350 ("glib" ,glib)
351 ("gtk+-2" ,gtk+-2)
4bd428a7 352 ("libjpeg" ,libjpeg-turbo)
d6ef422f
DM
353 ("liblinebreak" ,liblinebreak)
354 ("libxft" ,libxft)
355 ("sqlite" ,sqlite)
356 ("zlib" ,zlib)))
357 (native-inputs
6266a48d 358 `(("gcc@5" ,gcc-5)
04842543 359 ("pkg-config" ,pkg-config)))
d6ef422f
DM
360 (arguments
361 `(#:tests? #f ; No tests exist.
362 #:make-flags `("CC=gcc" "TARGET_ARCH=desktop" "UI_TYPE=gtk"
363 "TARGET_STATUS=release"
364 ,(string-append "INSTALLDIR="
365 (assoc-ref %outputs "out"))
366 ,(string-append "LDFLAGS=-Wl,-rpath="
367 (assoc-ref %outputs "out") "/lib"))
368 #:phases
369 (modify-phases %standard-phases
6266a48d
MB
370 (add-after 'set-paths 'augment-CPLUS_INCLUDE_PATH
371 (lambda* (#:key inputs #:allow-other-keys)
372 ;; Hide the default GCC from CPLUS_INCLUDE_PATH to prevent a header
373 ;; conflict with the GCC provided in native-inputs.
374 (let ((gcc (assoc-ref inputs "gcc")))
375 (setenv "CPLUS_INCLUDE_PATH"
376 (string-join
377 (delete (string-append gcc "/include/c++")
378 (string-split (getenv "CPLUS_INCLUDE_PATH")
379 #\:))
380 ":"))
381 #t)))
5dc5c5ea
EF
382 (delete 'configure)
383 (add-after 'unpack 'fix-install-locations
384 (lambda* (#:key outputs #:allow-other-keys)
385 (let ((out (assoc-ref outputs "out")))
386 (substitute* "fbreader/desktop/Makefile"
387 (("/usr") out))
388 #t))))))
d6ef422f
DM
389 (home-page "https://fbreader.org/")
390 (synopsis "E-Book reader")
391 (description "@code{fbreader} is an E-Book reader. It supports the
392following formats:
393
394@enumerate
395@item CHM
396@item Docbook
397@item FB2
398@item HTML
399@item OEB
400@item PDB
401@item RTF
402@item TCR
403@item TXT
404@item XHTML
405@end enumerate")
406 (license license:gpl2+)))
7c041187
JL
407
408(define-public xchm
409 (package
410 (name "xchm")
8cd23410 411 (version "1.31")
7c041187
JL
412 (source (origin
413 (method url-fetch)
414 (uri (string-append "https://github.com/rzvncj/xCHM"
415 "/releases/download/"
416 version "/xchm-" version ".tar.gz"))
417 (sha256
418 (base32
8cd23410 419 "0aw6bysqiwbw75n3ad229ihlmh7chqs1wlxm0398z3lfp2y6n7qf"))))
7c041187
JL
420 (build-system gnu-build-system)
421 (inputs
422 `(("wxwidgets" ,wxwidgets)
423 ("chmlib" ,chmlib)))
424 (native-inputs
425 `(("pkg-config" ,pkg-config)))
426 (home-page "https://github.com/rzvncj/xCHM")
427 (synopsis "CHM file viewer")
428 (description "xCHM is a graphical CHM file viewer. It is a frontend to
429the CHM library CHMLIB.")
430 (license license:gpl2+)))