Merge branch 'master' into staging
[jackhill/guix/guix.git] / gnu / packages / scanner.scm
CommitLineData
45c151d9 1;;; GNU Guix --- Functional package management for GNU
3b71b36c
AW
2;;; Copyright © 2014 John Darrington <jmd@gnu.org>
3;;; Copyright © 2015 Andy Wingo <wingo@igalia.com>
4c928743 4;;; Copyright © 2016 Andy Patterson <ajpatter@uwaterloo.ca>
ad149383 5;;; Copyright © 2017, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
8e189596 6;;; Copyright © 2018 Efraim Flashner <efraim@flashner.co.il>
45c151d9
JD
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)
a608666d
TGR
24 #:use-module (gnu packages)
25 #:use-module (gnu packages freedesktop)
26 #:use-module (gnu packages ghostscript)
27 #:use-module (gnu packages gtk)
6845ab52 28 #:use-module (gnu packages image)
3b71b36c 29 #:use-module (gnu packages libusb)
21b9c6fa
TGR
30 #:use-module (gnu packages pkg-config)
31 #:use-module (guix build-system gnu)
32 #:use-module (guix download)
a608666d 33 #:use-module (guix git-download)
45c151d9 34 #:use-module ((guix licenses)
21b9c6fa
TGR
35 #:prefix licence:)
36 #:use-module (guix packages)
37 #:use-module (guix utils))
45c151d9 38
32aa37a2 39(define-public sane-backends-minimal
45c151d9 40 (package
32aa37a2 41 (name "sane-backends-minimal")
ad149383 42 (version "1.0.30")
45c151d9
JD
43 (source (origin
44 (method url-fetch)
d976eccd 45 (uri (string-append
7018f926 46 "https://gitlab.com/sane-project/backends/uploads/"
ad149383 47 "c3dd60c9e054b5dee1e7b01a7edc98b0/"
32aa37a2 48 "sane-backends-" version ".tar.gz"))
45c151d9
JD
49 (sha256
50 (base32
ad149383 51 "18vryaycps3zpjzxh0wjgg8nv2f4pdvcfxxmdfj28qbzqjlrcp9z"))
a32d0c83
LC
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.
6cbee49d
MW
56 '(begin
57 (substitute* "tools/sane-desc.c"
58 (("asctime \\(localtime \\(&current_time\\)\\)")
59 "\"1970-01-01\""))
60 #t))))
45c151d9 61 (build-system gnu-build-system)
3b71b36c
AW
62 (native-inputs
63 `(("pkg-config" ,pkg-config)))
64 (inputs
abe6e670 65 `(("libusb" ,libusb)))
45c151d9 66 (arguments
4ed390a0 67 `(#:phases
3b71b36c 68 (modify-phases %standard-phases
33a14e29
AP
69 (add-before 'configure 'disable-backends
70 (lambda _
71 (setenv "BACKENDS" " ")
7018f926
TGR
72
73 ;; Disable tests that may require back ends to be built.
74 (substitute* "testsuite/Makefile.in"
75 ((" backend ") " "))
33a14e29 76 #t))
abe6e670 77 (add-after 'unpack 'disable-failing-tests
4ed390a0 78 (lambda _
abe6e670
TGR
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
4ed390a0
TGR
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"))
abe6e670
TGR
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\\) ") ""))
4ed390a0
TGR
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/"
37294772
MW
106 "60-libsane.rules"))
107 #t))))))
45c151d9 108 (home-page "http://www.sane-project.org")
32aa37a2
AP
109 (synopsis
110 "Raster image scanner library and drivers, without scanner support")
45c151d9
JD
111 (description "SANE stands for \"Scanner Access Now Easy\" and is an API
112proving access to any raster image scanner hardware (flatbed scanner,
113hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
32aa37a2 114package contains the library, but no drivers.")
45c151d9 115 (license licence:gpl2+))) ; plus linking exception
4c928743
AP
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
8e189596 125 `(("hplip" ,(@ (gnu packages cups) hplip-minimal))
4bd428a7 126 ("libjpeg" ,libjpeg-turbo) ; wanted by pixma, epsonds, others
10bd2889 127 ("libpng" ,libpng) ; support ‘scanimage --format=png’
4c928743
AP
128 ,@(package-inputs sane-backends-minimal)))
129 (arguments
130 (substitute-keyword-arguments (package-arguments sane-backends-minimal)
131 ((#:phases phases)
132 `(modify-phases ,phases
133 (delete 'disable-backends)
5f6ce90a
LP
134 (add-after 'disable-failing-tests 'disable-failing-backend-tests
135 (lambda _
136 ;; Disable test that fails on i686:
137 ;; <https://bugs.gnu.org/39449>
138 (substitute* "testsuite/backend/genesys/Makefile.in"
139 ((" genesys_unit_tests\\$\\(EXEEXT\\)") ""))
140 #t))
4c928743
AP
141 (add-after 'unpack 'add-backends
142 (lambda _
143 (substitute* "backend/dll.conf.in"
144 (("hp5590" all) (format #f "~a~%~a" all "hpaio")))
145 #t))
146 (add-after 'install 'install-hpaio
147 (lambda* (#:key inputs outputs #:allow-other-keys)
148 (define hplip (string-append (assoc-ref inputs "hplip")
149 "/lib/sane"))
150 (define out (string-append (assoc-ref outputs "out")
151 "/lib/sane"))
152 (for-each
153 (lambda (file)
154 (symlink file (string-append out "/" (basename file))))
155 (find-files hplip))
156 #t))))))
157 (synopsis
158 "Raster image scanner library and drivers, with scanner support")
159 (description "SANE stands for \"Scanner Access Now Easy\" and is an API
160proving access to any raster image scanner hardware (flatbed scanner,
161hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
162package contains the library and drivers.")))
a608666d
TGR
163
164(define-public xsane
165 (package
166 (name "xsane")
167 (version "0.999")
168 (source
169 (origin
170 (method git-fetch)
171 (uri (git-reference
172 (url "https://gitlab.com/sane-project/frontend/xsane.git")
173 (commit version)))
174 (file-name (git-file-name name version))
175 (sha256
176 (base32 "08zvxj7i1s88ckrsqldmsrikc3g62a6p3s3i5b5x4krcfpi3vs50"))
177 ;; Apply some important-looking fixes. There are many more unreleased
178 ;; commits upstream. A 1.0 release is planned.
179 (patches (search-patches "xsane-fix-memory-leak.patch"
180 "xsane-fix-pdf-floats.patch"
99b10602 181 "xsane-fix-snprintf-buffer-length.patch"
a608666d
TGR
182 "xsane-support-ipv6.patch"
183 "xsane-tighten-default-umask.patch"))
184 (modules '((guix build utils)))
185 (snippet
186 '(begin
187 ;; Remove ancient bundled lprng code under a non-free licence. See
188 ;; <https://trisquel.info/en/issues/10713>, which solves the problem
189 ;; by replacing it with a newer (free) copy. We let the build fall
190 ;; back to the system version instead, which appears to work fine.
191 (delete-file "lib/snprintf.c")
192 (substitute* "lib/Makefile.in"
193 (("snprintf\\.o ") ""))
194 #t))))
195 (build-system gnu-build-system)
196 (arguments
197 `(#:make-flags
198 (list (string-append "xsanedocdir=" (assoc-ref %outputs "out")
199 "/share/doc/" ,name "-" ,version))
200 #:tests? #f ; no test suite
201 #:phases
202 (modify-phases %standard-phases
203 (add-after 'unpack 'patch-invalid-dereference
204 ;; Fix the following compilation error with libpng:
205 ;; xsane-save.c: In function ‘xsane_save_png’:
206 ;; xsane-save.c:4913:21: error: dereferencing pointer to
207 ;; incomplete type ‘png_struct {aka struct png_struct_def}’
208 ;; if (setjmp(png_ptr->jmpbuf))
209 ;; ^
210 (lambda _
211 (substitute* "src/xsane-save.c"
212 (("png_ptr->jmpbuf") "png_jmpbuf(png_ptr)"))
213 #t))
214 (add-after 'unpack 'use-sane-help-browser
215 (lambda _
216 (substitute* "src/xsane.h"
217 (("netscape") (which "xdg-open")))
218 #t))
219 (add-after 'install 'delete-empty-/sbin
220 (lambda* (#:key outputs #:allow-other-keys)
221 (let ((out (assoc-ref outputs "out")))
222 (rmdir (string-append out "/sbin"))
223 #t))))))
224 (native-inputs
225 `(("pkg-config" ,pkg-config)))
226 (inputs
227 `(("gtk+" ,gtk+-2)
228 ("lcms" ,lcms)
4bd428a7 229 ("libjpeg" ,libjpeg-turbo)
a608666d
TGR
230 ("libtiff" ,libtiff)
231 ("sane-backends" ,sane-backends)
232
233 ;; To open the manual from the Help menu.
234 ("xdg-utils" ,xdg-utils)))
235 (home-page "https://gitlab.com/sane-project/frontend/xsane")
236 (synopsis "Featureful graphical interface for document and image scanners")
237 (description
238 "XSane is a graphical interface for controlling a scanner and acquiring
239images from it. You can photocopy multi-page documents and save, fax, print,
240or e-mail your scanned images. It is highly configurable and exposes all
241device settings, letting you fine-tune the final result. It can also be used
242as a GIMP plugin to acquire images directly from a scanner.
243
244XSane talks to scanners through the @acronym{SANE, Scanner Access Now Easy}
245back-end library, which supports almost all existing scanners.")
246 (license licence:gpl2+)))