gnu: r-maldiquant: Move to (gnu packages cran).
[jackhill/guix/guix.git] / gnu / packages / ebook.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016 Andreas Enge <andreas@enge.fr>
3 ;;; Copyright © 2016, 2018 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017 Alex Griffin <a@ajgrf.com>
5 ;;; Copyright © 2017, 2019, 2020 Brendan Tildesley <mail@brendan.scot>
6 ;;; Copyright © 2017 Roel Janssen <roel@gnu.org>
7 ;;; Copyright © 2018, 2019 Tobias Geerinckx-Rice <me@tobias.gr>
8 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
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)
26 #:use-module ((guix licenses) #:prefix license:)
27 #:use-module (guix packages)
28 #:use-module (guix download)
29 #:use-module (guix git-download)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix build-system python)
32 #:use-module (gnu packages)
33 #:use-module (gnu packages compression)
34 #:use-module (gnu packages curl)
35 #:use-module (gnu packages databases)
36 #:use-module (gnu packages fonts)
37 #:use-module (gnu packages fontutils)
38 #:use-module (gnu packages freedesktop)
39 #:use-module (gnu packages fribidi)
40 #:use-module (gnu packages gcc)
41 #:use-module (gnu packages gtk)
42 #:use-module (gnu packages gnome)
43 #:use-module (gnu packages glib)
44 #:use-module (gnu packages icu4c)
45 #:use-module (gnu packages image)
46 #:use-module (gnu packages javascript)
47 #:use-module (gnu packages libusb)
48 #:use-module (gnu packages libreoffice)
49 #:use-module (gnu packages pdf)
50 #:use-module (gnu packages pkg-config)
51 #:use-module (gnu packages python)
52 #:use-module (gnu packages python-web)
53 #:use-module (gnu packages python-xyz)
54 #:use-module (gnu packages qt)
55 #:use-module (gnu packages serialization)
56 #:use-module (gnu packages sqlite)
57 #:use-module (gnu packages time)
58 #:use-module (gnu packages tls)
59 #:use-module (gnu packages web)
60 #:use-module (gnu packages xml)
61 #:use-module (gnu packages xorg)
62 #:use-module (gnu packages wxwidgets))
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
74 "18zzb4x3z0d7fjh1x5439bs62dmgsi4c1pg3qyr7h5gp1i5xcj9l"))
75 (patches (search-patches "chmlib-inttypes.patch"))))
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.")
80 (license license:lgpl2.1+)))
81
82 (define-public calibre
83 (package
84 (name "calibre")
85 (version "4.18.0")
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
93 (base32
94 "0w9pcfvskjh4v00vjw3i6hzrafy863pgsmmqdx4lffip3p856brw"))
95 (modules '((guix build utils)))
96 (snippet
97 '(begin
98 ;; Unbundle python2-odfpy.
99 (delete-file-recursively "src/odf")
100 ;; Disable test that attempts to load it.
101 (substitute* "setup/test.py"
102 ((".*SRC, 'odf'.*")
103 ""))
104
105 ;; Remove unneeded resources.
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")
111 #t))
112 (patches (search-patches "calibre-no-updates-dialog.patch"
113 "calibre-remove-test-sqlite.patch" ; TODO: fix test.
114 "calibre-remove-test-unrar.patch"))))
115 (build-system python-build-system)
116 (native-inputs
117 `(("pkg-config" ,pkg-config)
118 ("qtbase" ,qtbase) ; for qmake
119 ("python2-flake8" ,python2-flake8)
120 ("xdg-utils" ,xdg-utils)))
121 (inputs
122 `(("chmlib" ,chmlib)
123 ("fontconfig" ,fontconfig)
124 ("font-liberation" ,font-liberation)
125 ("glib" ,glib)
126 ("hunspell" ,hunspell)
127 ("hyphen" ,hyphen)
128 ("icu4c" ,icu4c)
129 ("js-mathjax" ,js-mathjax)
130 ("libmtp" ,libmtp)
131 ("libpng" ,libpng)
132 ("libusb" ,libusb)
133 ("openssl" ,openssl)
134 ("optipng" ,optipng)
135 ("podofo" ,podofo)
136 ("poppler" ,poppler)
137 ("python" ,python-2)
138 ("python2-apsw" ,python2-apsw)
139 ("python2-beautifulsoup4" ,python2-beautifulsoup4)
140 ("python2-chardet" ,python2-chardet)
141 ("python2-cssselect" ,python2-cssselect)
142 ("python2-css-parser" ,python2-css-parser)
143 ("python2-dateutil" ,python2-dateutil)
144 ("python2-dbus" ,python2-dbus)
145 ("python2-dnspython" ,python2-dnspython)
146 ("python2-dukpy" ,python2-dukpy)
147 ("python2-feedparser" ,python2-feedparser)
148 ("python2-html2text" ,python2-html2text)
149 ("python2-html5-parser" ,python2-html5-parser)
150 ("python2-html5lib" ,python2-html5lib)
151 ("python2-lxml" ,python2-lxml)
152 ("python2-markdown" ,python2-markdown)
153 ("python2-mechanize" ,python2-mechanize)
154 ;; python2-msgpack is needed for the network content server to work.
155 ("python2-msgpack" ,python2-msgpack)
156 ("python2-netifaces" ,python2-netifaces)
157 ("python2-odfpy" ,python2-odfpy)
158 ("python2-pillow" ,python2-pillow)
159 ("python2-psutil" ,python2-psutil)
160 ("python2-pygments" ,python2-pygments)
161 ("python2-pyqtwebengine" ,python2-pyqtwebengine)
162 ("python2-pyqt" ,python2-pyqt)
163 ("python2-sip" ,python2-sip)
164 ("python2-regex" ,python2-regex)
165 ("qtwebengine" ,qtwebengine)
166 ("sqlite" ,sqlite)))
167 (arguments
168 `(#:python ,python-2
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
172 #:phases
173 (modify-phases %standard-phases
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))
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))
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))
198 (add-before 'build 'configure
199 (lambda* (#:key inputs outputs #:allow-other-keys)
200 (let ((podofo (assoc-ref inputs "podofo"))
201 (pyqt (assoc-ref inputs "python2-pyqt"))
202 (python-sip (assoc-ref inputs "python2-sip"))
203 (out (assoc-ref outputs "out")))
204 (substitute* "setup/build_environment.py"
205 (("= get_sip_dir\\(\\)")
206 (string-append "= '" pyqt "/share/sip'")))
207
208 (substitute* "src/calibre/ebooks/pdf/pdftohtml.py"
209 (("PDFTOHTML = 'pdftohtml'")
210 (string-append "PDFTOHTML = \"" (assoc-ref inputs "poppler")
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
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"))
232 (setenv "PODOFO_INC_DIR" (string-append podofo "/include/podofo"))
233 (setenv "PODOFO_LIB_DIR" (string-append podofo "/lib"))
234 ;; This informs the tests we are a continuous integration
235 ;; environment and thus have no networking.
236 (setenv "CI" "true")
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")
241 #t)))
242 (add-after 'build 'build-extra
243 (lambda* (#:key inputs #:allow-other-keys)
244 (invoke "python2" "setup.py" "mathjax""--system-mathjax"
245 "--path-to-mathjax" (string-append
246 (assoc-ref inputs "js-mathjax")
247 "/share/javascript/mathjax"))
248 (invoke "python2" "setup.py" "rapydscript")))
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))
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))
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
281 (lambda* (#:key inputs outputs #:allow-other-keys)
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))
288 #t)))))
289 (home-page "https://calibre-ebook.com/")
290 (synopsis "E-book library management software")
291 (description "Calibre is an e-book library manager. It can view, convert
292 and catalog e-books in most of the major e-book formats. It can also talk
293 to many e-book reader devices. It can go out to the Internet and fetch
294 metadata for books. It can download newspapers and convert them into
295 e-books for convenient reading.")
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))))
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
326 breaking algorithm as described in Unicode 6.0.0 Standard Annex 14,
327 Revision 26. It breaks lines that contain Unicode characters. It is
328 designed to be used in a generic text renderer.")
329 (license license:zlib)))
330
331 (define-public fbreader
332 (package
333 (name "fbreader")
334 (version "0.99.6")
335 (source (origin
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))
341 (sha256
342 (base32
343 "0c0s4silpax74kwfz3dfmzn4lkv6jsyb800vfak166vii0hvbv3d"))
344 (patches (search-patches "fbreader-curl-7.62.patch"))))
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)
352 ("libjpeg" ,libjpeg-turbo)
353 ("liblinebreak" ,liblinebreak)
354 ("libxft" ,libxft)
355 ("sqlite" ,sqlite)
356 ("zlib" ,zlib)))
357 (native-inputs
358 `(("gcc@5" ,gcc-5)
359 ("pkg-config" ,pkg-config)))
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
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)))
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))))))
389 (home-page "https://fbreader.org/")
390 (synopsis "E-Book reader")
391 (description "@code{fbreader} is an E-Book reader. It supports the
392 following 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+)))
407
408 (define-public xchm
409 (package
410 (name "xchm")
411 (version "1.31")
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
419 "0aw6bysqiwbw75n3ad229ihlmh7chqs1wlxm0398z3lfp2y6n7qf"))))
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
429 the CHM library CHMLIB.")
430 (license license:gpl2+)))