gnu: Replace uses of 'libjpeg' with 'libjpeg-turbo'.
[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 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 (guix build-system gnu)
32 #:use-module (guix download)
33 #:use-module (guix git-download)
34 #:use-module ((guix licenses)
35 #:prefix licence:)
36 #:use-module (guix packages)
37 #:use-module (guix utils))
38
39 (define-public sane-backends-minimal
40 (package
41 (name "sane-backends-minimal")
42 (version "1.0.28")
43 (source (origin
44 (method url-fetch)
45 (uri (string-append
46 "https://gitlab.com/sane-project/backends/uploads/"
47 "9e718daff347826f4cfe21126c8d5091/"
48 "sane-backends-" version ".tar.gz"))
49 (sha256
50 (base32
51 "00yy8q9hqdf0zjxxl4d8njr9zf0hhi3a9ib23ikc2anqf8zhy9ii"))
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) ; wanted by pixma, epsonds, others
127 ("libpng" ,libpng) ; support ‘scanimage --format=png’
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)
134 (add-after 'unpack 'add-backends
135 (lambda _
136 (substitute* "backend/dll.conf.in"
137 (("hp5590" all) (format #f "~a~%~a" all "hpaio")))
138 #t))
139 (add-after 'install 'install-hpaio
140 (lambda* (#:key inputs outputs #:allow-other-keys)
141 (define hplip (string-append (assoc-ref inputs "hplip")
142 "/lib/sane"))
143 (define out (string-append (assoc-ref outputs "out")
144 "/lib/sane"))
145 (for-each
146 (lambda (file)
147 (symlink file (string-append out "/" (basename file))))
148 (find-files hplip))
149 #t))))))
150 (synopsis
151 "Raster image scanner library and drivers, with scanner support")
152 (description "SANE stands for \"Scanner Access Now Easy\" and is an API
153 proving access to any raster image scanner hardware (flatbed scanner,
154 hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
155 package contains the library and drivers.")))
156
157 (define-public xsane
158 (package
159 (name "xsane")
160 (version "0.999")
161 (source
162 (origin
163 (method git-fetch)
164 (uri (git-reference
165 (url "https://gitlab.com/sane-project/frontend/xsane.git")
166 (commit version)))
167 (file-name (git-file-name name version))
168 (sha256
169 (base32 "08zvxj7i1s88ckrsqldmsrikc3g62a6p3s3i5b5x4krcfpi3vs50"))
170 ;; Apply some important-looking fixes. There are many more unreleased
171 ;; commits upstream. A 1.0 release is planned.
172 (patches (search-patches "xsane-fix-memory-leak.patch"
173 "xsane-fix-pdf-floats.patch"
174 "xsane-fix-snprintf-buffer-length.patch"
175 "xsane-support-ipv6.patch"
176 "xsane-tighten-default-umask.patch"))
177 (modules '((guix build utils)))
178 (snippet
179 '(begin
180 ;; Remove ancient bundled lprng code under a non-free licence. See
181 ;; <https://trisquel.info/en/issues/10713>, which solves the problem
182 ;; by replacing it with a newer (free) copy. We let the build fall
183 ;; back to the system version instead, which appears to work fine.
184 (delete-file "lib/snprintf.c")
185 (substitute* "lib/Makefile.in"
186 (("snprintf\\.o ") ""))
187 #t))))
188 (build-system gnu-build-system)
189 (arguments
190 `(#:make-flags
191 (list (string-append "xsanedocdir=" (assoc-ref %outputs "out")
192 "/share/doc/" ,name "-" ,version))
193 #:tests? #f ; no test suite
194 #:phases
195 (modify-phases %standard-phases
196 (add-after 'unpack 'patch-invalid-dereference
197 ;; Fix the following compilation error with libpng:
198 ;; xsane-save.c: In function ‘xsane_save_png’:
199 ;; xsane-save.c:4913:21: error: dereferencing pointer to
200 ;; incomplete type ‘png_struct {aka struct png_struct_def}’
201 ;; if (setjmp(png_ptr->jmpbuf))
202 ;; ^
203 (lambda _
204 (substitute* "src/xsane-save.c"
205 (("png_ptr->jmpbuf") "png_jmpbuf(png_ptr)"))
206 #t))
207 (add-after 'unpack 'use-sane-help-browser
208 (lambda _
209 (substitute* "src/xsane.h"
210 (("netscape") (which "xdg-open")))
211 #t))
212 (add-after 'install 'delete-empty-/sbin
213 (lambda* (#:key outputs #:allow-other-keys)
214 (let ((out (assoc-ref outputs "out")))
215 (rmdir (string-append out "/sbin"))
216 #t))))))
217 (native-inputs
218 `(("pkg-config" ,pkg-config)))
219 (inputs
220 `(("gtk+" ,gtk+-2)
221 ("lcms" ,lcms)
222 ("libjpeg" ,libjpeg-turbo)
223 ("libtiff" ,libtiff)
224 ("sane-backends" ,sane-backends)
225
226 ;; To open the manual from the Help menu.
227 ("xdg-utils" ,xdg-utils)))
228 (home-page "https://gitlab.com/sane-project/frontend/xsane")
229 (synopsis "Featureful graphical interface for document and image scanners")
230 (description
231 "XSane is a graphical interface for controlling a scanner and acquiring
232 images from it. You can photocopy multi-page documents and save, fax, print,
233 or e-mail your scanned images. It is highly configurable and exposes all
234 device settings, letting you fine-tune the final result. It can also be used
235 as a GIMP plugin to acquire images directly from a scanner.
236
237 XSane talks to scanners through the @acronym{SANE, Scanner Access Now Easy}
238 back-end library, which supports almost all existing scanners.")
239 (license licence:gpl2+)))