gnu: r-fields: Update to 11.4.
[jackhill/guix/guix.git] / gnu / packages / scanner.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 John Darrington <jmd@gnu.org>
3 ;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
4 ;;; Copyright © 2016 Andy Patterson <ajpatter@uwaterloo.ca>
5 ;;; Copyright © 2017, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
6 ;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
7 ;;;
8 ;;; This file is part of GNU Guix.
9 ;;;
10 ;;; GNU Guix is free software; you can redistribute it and/or modify it
11 ;;; under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 3 of the License, or (at
13 ;;; your option) any later version.
14 ;;;
15 ;;; GNU Guix is distributed in the hope that it will be useful, but
16 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23 (define-module (gnu packages scanner)
24 #:use-module (gnu packages)
25 #:use-module (gnu packages freedesktop)
26 #:use-module (gnu packages ghostscript)
27 #:use-module (gnu packages gtk)
28 #:use-module (gnu packages image)
29 #:use-module (gnu packages libusb)
30 #:use-module (gnu packages pkg-config)
31 #:use-module (gnu packages xml)
32 #:use-module (guix build-system gnu)
33 #:use-module (guix download)
34 #:use-module (guix git-download)
35 #:use-module ((guix licenses)
36 #:prefix licence:)
37 #:use-module (guix packages)
38 #:use-module (guix utils))
39
40 (define-public sane-backends-minimal
41 (package
42 (name "sane-backends-minimal")
43 (version "1.0.31")
44 (source (origin
45 (method url-fetch)
46 (uri (string-append
47 "https://gitlab.com/sane-project/backends/uploads/"
48 "8bf1cae2e1803aefab9e5331550e5d5d/"
49 "sane-backends-" version ".tar.gz"))
50 (sha256
51 (base32 "1am5w92zyybs26wx4brgmky6dzpd8n34jyfrfx3qbvcqngy10fsa"))
52 (modules '((guix build utils)))
53 (snippet
54 ;; Generated HTML files and udev rules normally embed a
55 ;; timestamp. Work around that to build things reproducibly.
56 '(begin
57 (substitute* "tools/sane-desc.c"
58 (("asctime \\(localtime \\(&current_time\\)\\)")
59 "\"1970-01-01\""))
60 #t))))
61 (build-system gnu-build-system)
62 (native-inputs
63 `(("pkg-config" ,pkg-config)))
64 (inputs
65 `(("libusb" ,libusb)))
66 (arguments
67 `(#:phases
68 (modify-phases %standard-phases
69 (add-before 'configure 'disable-backends
70 (lambda _
71 (setenv "BACKENDS" " ")
72
73 ;; Disable tests that may require back ends to be built.
74 (substitute* "testsuite/Makefile.in"
75 ((" backend ") " "))
76 #t))
77 (add-after 'unpack 'disable-failing-tests
78 (lambda _
79 ;; Disable unmaintained tests that that fail with errors resembling:
80 ;;
81 ;; < # by sane-desc 3.5 from sane-backends 1.0.24git on Jul 31 2013
82 ;; ---
83 ;; > # by sane-desc 3.5 from sane-backends 1.0.27 on 1970-01-01#
84 ;; FAIL: sane-desc -m usermap -s ./data
85 (for-each
86 (lambda (pattern)
87 (substitute* "testsuite/tools/Makefile.in"
88 (((string-append " " pattern " ")) " ")))
89 (list "usermap" "db" "udev" "udev\\+acl" "udev\\+hwdb" "hwdb"))
90
91 ;; Disable tests that try to connect to actual USB hardware & fail
92 ;; with the following error when no USB access is allowed at all:
93 ;;
94 ;; sanei_usb_test: sanei_usb_test.c:849: main: Assertion
95 ;; `test_init (1)' failed.
96 (substitute* "testsuite/sanei/Makefile.in"
97 (("sanei_usb_test\\$\\(EXEEXT\\) ") ""))
98 #t))
99 (add-after 'install 'install-udev-rules
100 (lambda* (#:key outputs #:allow-other-keys)
101 (let ((out (assoc-ref outputs "out")))
102 (mkdir-p (string-append out "/lib/udev/rules.d"))
103 (copy-file "tools/udev/libsane.rules"
104 (string-append out
105 "/lib/udev/rules.d/"
106 "60-libsane.rules"))
107 #t))))))
108 (home-page "http://www.sane-project.org")
109 (synopsis
110 "Raster image scanner library and drivers, without scanner support")
111 (description "SANE stands for \"Scanner Access Now Easy\" and is an API
112 proving access to any raster image scanner hardware (flatbed scanner,
113 hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
114 package contains the library, but no drivers.")
115 (license licence:gpl2+))) ; plus linking exception
116
117 ;; This variant links in the hpaio backend, provided by hplip, which adds
118 ;; support for HP scanners whose backends are not maintained by
119 ;; 'sane-backends'. It also builds all of those backends.
120 (define-public sane-backends
121 (package
122 (inherit sane-backends-minimal)
123 (name "sane-backends")
124 (inputs
125 `(("hplip" ,(@ (gnu packages cups) hplip-minimal))
126 ("libjpeg" ,libjpeg-turbo) ; for pixma/epsonds/other back ends
127 ("libpng" ,libpng) ; support ‘scanimage --format=png’
128 ("libxml2" ,libxml2) ; for pixma back end
129 ,@(package-inputs sane-backends-minimal)))
130 (arguments
131 (substitute-keyword-arguments (package-arguments sane-backends-minimal)
132 ((#:phases phases)
133 `(modify-phases ,phases
134 (delete 'disable-backends)
135 (add-after 'disable-failing-tests 'disable-failing-backend-tests
136 (lambda _
137 ;; Disable test that fails on i686:
138 ;; <https://bugs.gnu.org/39449>
139 (substitute* "testsuite/backend/genesys/Makefile.in"
140 ((" genesys_unit_tests\\$\\(EXEEXT\\)") ""))
141 #t))
142 (add-after 'unpack 'add-backends
143 (lambda _
144 (substitute* "backend/dll.conf.in"
145 (("hp5590" all) (format #f "~a~%~a" all "hpaio")))
146 #t))
147 (add-after 'install 'install-hpaio
148 (lambda* (#:key inputs outputs #:allow-other-keys)
149 (define hplip (string-append (assoc-ref inputs "hplip")
150 "/lib/sane"))
151 (define out (string-append (assoc-ref outputs "out")
152 "/lib/sane"))
153 (for-each
154 (lambda (file)
155 (symlink file (string-append out "/" (basename file))))
156 (find-files hplip))
157 #t))))))
158 (synopsis
159 "Raster image scanner library and drivers, with scanner support")
160 (description "SANE stands for \"Scanner Access Now Easy\" and is an API
161 proving access to any raster image scanner hardware (flatbed scanner,
162 hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
163 package contains the library and drivers.")))
164
165 (define-public xsane
166 (package
167 (name "xsane")
168 (version "0.999")
169 (source
170 (origin
171 (method git-fetch)
172 (uri (git-reference
173 (url "https://gitlab.com/sane-project/frontend/xsane.git")
174 (commit version)))
175 (file-name (git-file-name name version))
176 (sha256
177 (base32 "08zvxj7i1s88ckrsqldmsrikc3g62a6p3s3i5b5x4krcfpi3vs50"))
178 ;; Apply some important-looking fixes. There are many more unreleased
179 ;; commits upstream. A 1.0 release is planned.
180 (patches (search-patches "xsane-fix-memory-leak.patch"
181 "xsane-fix-pdf-floats.patch"
182 "xsane-fix-snprintf-buffer-length.patch"
183 "xsane-support-ipv6.patch"
184 "xsane-tighten-default-umask.patch"))
185 (modules '((guix build utils)))
186 (snippet
187 '(begin
188 ;; Remove ancient bundled lprng code under a non-free licence. See
189 ;; <https://trisquel.info/en/issues/10713>, which solves the problem
190 ;; by replacing it with a newer (free) copy. We let the build fall
191 ;; back to the system version instead, which appears to work fine.
192 (delete-file "lib/snprintf.c")
193 (substitute* "lib/Makefile.in"
194 (("snprintf\\.o ") ""))
195 #t))))
196 (build-system gnu-build-system)
197 (arguments
198 `(#:make-flags
199 (list (string-append "xsanedocdir=" (assoc-ref %outputs "out")
200 "/share/doc/" ,name "-" ,version))
201 #:tests? #f ; no test suite
202 #:phases
203 (modify-phases %standard-phases
204 (add-after 'unpack 'patch-invalid-dereference
205 ;; Fix the following compilation error with libpng:
206 ;; xsane-save.c: In function ‘xsane_save_png’:
207 ;; xsane-save.c:4913:21: error: dereferencing pointer to
208 ;; incomplete type ‘png_struct {aka struct png_struct_def}’
209 ;; if (setjmp(png_ptr->jmpbuf))
210 ;; ^
211 (lambda _
212 (substitute* "src/xsane-save.c"
213 (("png_ptr->jmpbuf") "png_jmpbuf(png_ptr)"))
214 #t))
215 (add-after 'unpack 'use-sane-help-browser
216 (lambda _
217 (substitute* "src/xsane.h"
218 (("netscape") (which "xdg-open")))
219 #t))
220 (add-after 'install 'delete-empty-/sbin
221 (lambda* (#:key outputs #:allow-other-keys)
222 (let ((out (assoc-ref outputs "out")))
223 (rmdir (string-append out "/sbin"))
224 #t))))))
225 (native-inputs
226 `(("pkg-config" ,pkg-config)))
227 (inputs
228 `(("gtk+" ,gtk+-2)
229 ("lcms" ,lcms)
230 ("libjpeg" ,libjpeg-turbo)
231 ("libtiff" ,libtiff)
232 ("sane-backends" ,sane-backends)
233
234 ;; To open the manual from the Help menu.
235 ("xdg-utils" ,xdg-utils)))
236 (home-page "https://gitlab.com/sane-project/frontend/xsane")
237 (synopsis "Featureful graphical interface for document and image scanners")
238 (description
239 "XSane is a graphical interface for controlling a scanner and acquiring
240 images from it. You can photocopy multi-page documents and save, fax, print,
241 or e-mail your scanned images. It is highly configurable and exposes all
242 device settings, letting you fine-tune the final result. It can also be used
243 as a GIMP plugin to acquire images directly from a scanner.
244
245 XSane talks to scanners through the @acronym{SANE, Scanner Access Now Easy}
246 back-end library, which supports almost all existing scanners.")
247 (license licence:gpl2+)))