scanner.scm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. (define-module (gnu packages scanner)
  23. #:use-module (gnu packages)
  24. #:use-module (gnu packages autotools)
  25. #:use-module (gnu packages compression)
  26. #:use-module (gnu packages freedesktop)
  27. #:use-module (gnu packages gettext)
  28. #:use-module (gnu packages ghostscript)
  29. #:use-module (gnu packages glib)
  30. #:use-module (gnu packages gtk)
  31. #:use-module (gnu packages image)
  32. #:use-module (gnu packages libusb)
  33. #:use-module (gnu packages linux)
  34. #:use-module (gnu packages pkg-config)
  35. #:use-module (gnu packages python)
  36. #:use-module (gnu packages textutils)
  37. #:use-module (gnu packages xml)
  38. #:use-module (guix build-system gnu)
  39. #:use-module (guix download)
  40. #:use-module (guix git-download)
  41. #:use-module ((guix licenses)
  42. #:prefix license:)
  43. #:use-module (guix packages)
  44. #:use-module (guix utils))
  45. (define-public sane-backends-minimal
  46. (package
  47. (name "sane-backends-minimal")
  48. (version "1.0.32")
  49. (source (origin
  50. (method git-fetch)
  51. (uri (git-reference
  52. (url "https://gitlab.com/sane-project/backends")
  53. (commit version)))
  54. (file-name (git-file-name name version))
  55. (sha256
  56. (base32 "13jlqdp7n7z2n78v6idl3ri5idk7ddk9j8wrmh73lba8l9y8xnsi"))
  57. (modules '((guix build utils)))
  58. (snippet
  59. ;; Generated HTML files and udev rules normally embed a
  60. ;; timestamp. Work around that to build things reproducibly.
  61. '(begin
  62. (substitute* "tools/sane-desc.c"
  63. (("asctime \\(localtime \\(&current_time\\)\\)")
  64. "\"1970-01-01\""))))))
  65. (build-system gnu-build-system)
  66. (native-inputs
  67. `(("autoconf" ,autoconf)
  68. ("autoconf-archive" ,autoconf-archive)
  69. ("automake" ,automake)
  70. ("gettext" ,gettext-minimal)
  71. ("libtool" ,libtool)
  72. ("pkg-config" ,pkg-config)
  73. ;; For scripts/pixma_gen_options.py.
  74. ("python" ,python-wrapper)))
  75. (inputs
  76. `(("libusb" ,libusb)))
  77. (arguments
  78. `(#:phases
  79. (modify-phases %standard-phases
  80. (add-before 'bootstrap 'zap-unnecessary-git-dependency
  81. (lambda _
  82. ;; This runs before default patch-shebangs phase.
  83. (substitute* "tools/git-version-gen"
  84. (("/bin/sh") (which "sh")))
  85. (with-output-to-file ".tarball-version"
  86. (lambda _ (format #t ,version)))))
  87. (add-before 'configure 'disable-backends
  88. (lambda _
  89. (setenv "BACKENDS" " ")
  90. ;; Disable tests that may require back ends to be built.
  91. (substitute* "testsuite/Makefile.in"
  92. ((" backend ") " "))))
  93. (add-before 'configure 'disable-failing-tests
  94. (lambda _
  95. ;; Disable unmaintained tests that that fail with errors resembling:
  96. ;;
  97. ;; < # by sane-desc 3.5 from sane-backends 1.0.24git on Jul 31 2013
  98. ;; ---
  99. ;; > # by sane-desc 3.5 from sane-backends 1.0.27 on 1970-01-01#
  100. ;; FAIL: sane-desc -m usermap -s ./data
  101. (for-each
  102. (lambda (pattern)
  103. (substitute* "testsuite/tools/Makefile.in"
  104. (((string-append " " pattern " ")) " ")))
  105. (list "usermap" "db" "udev" "udev\\+acl" "udev\\+hwdb" "hwdb"))
  106. ;; Disable tests that try to connect to actual USB hardware & fail
  107. ;; with the following error when no USB access is allowed at all:
  108. ;;
  109. ;; sanei_usb_test: sanei_usb_test.c:849: main: Assertion
  110. ;; `test_init (1)' failed.
  111. (substitute* "testsuite/sanei/Makefile.in"
  112. (("sanei_usb_test\\$\\(EXEEXT\\) ") ""))))
  113. (add-before 'build 'build-pixma_sane_options.c
  114. ;; "No rule to make target '../backend/pixma/pixma_sane_options.c',
  115. ;; needed by 'sane-backends.pot-update'."
  116. (lambda _
  117. (invoke "make" "-C" "backend" "pixma/pixma_sane_options.c")))
  118. (add-after 'install 'install-udev-rules
  119. (lambda* (#:key outputs #:allow-other-keys)
  120. (let ((out (assoc-ref outputs "out")))
  121. (mkdir-p (string-append out "/lib/udev/rules.d"))
  122. (copy-file "tools/udev/libsane.rules"
  123. (string-append out
  124. "/lib/udev/rules.d/"
  125. "60-libsane.rules")))))
  126. (add-after 'install 'make-reproducible
  127. ;; XXX Work around an old bug <https://issues.guix.gnu.org/26247>.
  128. ;; Then work around "Throw to key `decoding-error' ..." by using sed.
  129. (lambda* (#:key outputs #:allow-other-keys)
  130. (let* ((out (assoc-ref outputs "out"))
  131. (locale (string-append out "/share/locale")))
  132. (with-directory-excursion locale
  133. (for-each (lambda (file)
  134. (invoke "sed" "-i" "/^PO-Revision-Date:/d" file))
  135. (list "en@boldquot/LC_MESSAGES/sane-backends.mo"
  136. "en@quot/LC_MESSAGES/sane-backends.mo")))))))))
  137. (home-page "http://www.sane-project.org")
  138. (synopsis
  139. "Raster image scanner library and drivers, without scanner support")
  140. (description "SANE stands for \"Scanner Access Now Easy\" and is an API
  141. proving access to any raster image scanner hardware (flatbed scanner,
  142. hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
  143. package contains the library, but no drivers.")
  144. (license license:gpl2+))) ; plus linking exception
  145. ;; This variant links in the hpaio backend provided by hplip, which adds
  146. ;; support for HP scanners whose backends are not maintained by the SANE
  147. ;; project, and builds all of those backends.
  148. (define-public sane-backends
  149. (package/inherit sane-backends-minimal
  150. (name "sane-backends")
  151. (inputs
  152. `(("hplip" ,(@ (gnu packages cups) hplip-minimal))
  153. ("libjpeg" ,libjpeg-turbo) ; for pixma/epsonds/other back ends
  154. ("libpng" ,libpng) ; support ‘scanimage --format=png’
  155. ("libxml2" ,libxml2) ; for pixma back end
  156. ,@(package-inputs sane-backends-minimal)))
  157. (arguments
  158. (substitute-keyword-arguments (package-arguments sane-backends-minimal)
  159. ((#:phases phases)
  160. `(modify-phases ,phases
  161. (delete 'disable-backends)
  162. (add-after 'disable-failing-tests 'disable-failing-backend-tests
  163. (lambda _
  164. ;; Disable test that fails on i686:
  165. ;; <https://bugs.gnu.org/39449>
  166. (substitute* "testsuite/backend/genesys/Makefile.in"
  167. ((" genesys_unit_tests\\$\\(EXEEXT\\)") ""))
  168. #t))
  169. (add-after 'unpack 'add-backends
  170. (lambda _
  171. (substitute* "backend/dll.conf.in"
  172. (("hp5590" all) (format #f "~a~%~a" all "hpaio")))
  173. #t))
  174. (add-after 'install 'install-hpaio
  175. (lambda* (#:key inputs outputs #:allow-other-keys)
  176. (define hplip (string-append (assoc-ref inputs "hplip")
  177. "/lib/sane"))
  178. (define out (string-append (assoc-ref outputs "out")
  179. "/lib/sane"))
  180. (for-each
  181. (lambda (file)
  182. (symlink file (string-append out "/" (basename file))))
  183. (find-files hplip))
  184. #t))))))
  185. (synopsis
  186. "Raster image scanner library and drivers, with scanner support")
  187. (description "SANE stands for \"Scanner Access Now Easy\" and is an API
  188. proving access to any raster image scanner hardware (flatbed scanner,
  189. hand-held scanner, video- and still-cameras, frame-grabbers, etc.). The
  190. package contains the library and drivers.")))
  191. (define-public scanbd
  192. (package
  193. (name "scanbd")
  194. (version "1.5.1")
  195. (source
  196. (origin
  197. (method url-fetch)
  198. (uri (string-append "mirror://sourceforge/scanbd/releases/"
  199. "scanbd-" version ".tgz"))
  200. (sha256
  201. (base32 "0pvy4qirfjdfm8aj6x5rkbgl7hk3jfa2s21qkk8ic5dqfjjab75n"))))
  202. (build-system gnu-build-system)
  203. (arguments
  204. `(#:configure-flags
  205. (list "--disable-debug"
  206. "--sysconfdir=/etc")
  207. #:phases
  208. (modify-phases %standard-phases
  209. (replace 'install
  210. (lambda* (#:key make-flags outputs #:allow-other-keys)
  211. (let* ((out (assoc-ref outputs "out"))
  212. (conf (string-append out "/etc/scanbd")))
  213. (apply invoke "make" "install"
  214. ;; Install example configuration to the store, not /etc.
  215. ;; These don't inherit from each other, so we need both.
  216. (string-append "scanbdconfdir=" conf)
  217. (string-append "scannerconfdir=" conf "/scanner.d")
  218. make-flags))))
  219. (add-after 'install 'install-extra-documentation
  220. ;; The README provides more detailed set-up instructions than the
  221. ;; man page.
  222. (lambda* (#:key outputs #:allow-other-keys)
  223. (let* ((out (assoc-ref outputs "out"))
  224. (doc (string-append out "/share/doc/"
  225. ,name "-" ,version)))
  226. (install-file "doc/README.txt" doc)))))))
  227. (native-inputs
  228. `(("pkg-config" ,pkg-config)))
  229. (inputs
  230. `(("dbus" ,dbus)
  231. ("libconfuse" ,libconfuse)
  232. ("sane-backends" ,sane-backends)
  233. ("udev" ,eudev)
  234. ("zlib" ,zlib)))
  235. (home-page "https://scanbd.sourceforge.io")
  236. (synopsis "Configurable scanner button monitor")
  237. (description "Scanbd stands for scanner button daemon. It regulary polls
  238. scanners for pressed buttons, function knob changes, or other events such
  239. as (un)plugging the scanner or inserting and removing paper. Then it performs
  240. the desired action(s) such as saving, copying, or e-mailing the image.
  241. Actions can be fully customized through scripts, based on any combination of
  242. switch or knob settings. Events are also signaled over D-Bus and scans can
  243. even be triggered over D-Bus from foreign applications.
  244. Scanbd talks to scanners through the @acronym{SANE, Scanner Access Now Easy}
  245. back-end library. This means that it supports almost all existing scanners,
  246. provided the driver also exposes the buttons.")
  247. (license license:gpl2+)))
  248. (define-public xsane
  249. (package
  250. (name "xsane")
  251. (version "0.999")
  252. (source
  253. (origin
  254. (method git-fetch)
  255. (uri (git-reference
  256. (url "https://gitlab.com/sane-project/frontend/xsane.git")
  257. (commit version)))
  258. (file-name (git-file-name name version))
  259. (sha256
  260. (base32 "08zvxj7i1s88ckrsqldmsrikc3g62a6p3s3i5b5x4krcfpi3vs50"))
  261. ;; Apply some important-looking fixes. There are many more unreleased
  262. ;; commits upstream. A 1.0 release is planned.
  263. (patches (search-patches "xsane-fix-memory-leak.patch"
  264. "xsane-fix-pdf-floats.patch"
  265. "xsane-fix-snprintf-buffer-length.patch"
  266. "xsane-support-ipv6.patch"
  267. "xsane-tighten-default-umask.patch"))
  268. (modules '((guix build utils)))
  269. (snippet
  270. '(begin
  271. ;; Remove ancient bundled lprng code under a non-free licence. See
  272. ;; <https://trisquel.info/en/issues/10713>, which solves the problem
  273. ;; by replacing it with a newer (free) copy. We let the build fall
  274. ;; back to the system version instead, which appears to work fine.
  275. (delete-file "lib/snprintf.c")
  276. (substitute* "lib/Makefile.in"
  277. (("snprintf\\.o ") ""))
  278. #t))))
  279. (build-system gnu-build-system)
  280. (arguments
  281. `(#:make-flags
  282. (list (string-append "xsanedocdir=" (assoc-ref %outputs "out")
  283. "/share/doc/" ,name "-" ,version))
  284. #:tests? #f ; no test suite
  285. #:phases
  286. (modify-phases %standard-phases
  287. (add-after 'unpack 'patch-invalid-dereference
  288. ;; Fix the following compilation error with libpng:
  289. ;; xsane-save.c: In function ‘xsane_save_png’:
  290. ;; xsane-save.c:4913:21: error: dereferencing pointer to
  291. ;; incomplete type ‘png_struct {aka struct png_struct_def}’
  292. ;; if (setjmp(png_ptr->jmpbuf))
  293. ;; ^
  294. (lambda _
  295. (substitute* "src/xsane-save.c"
  296. (("png_ptr->jmpbuf") "png_jmpbuf(png_ptr)"))
  297. #t))
  298. (add-after 'unpack 'use-sane-help-browser
  299. (lambda _
  300. (substitute* "src/xsane.h"
  301. (("netscape") (which "xdg-open")))
  302. #t))
  303. (add-after 'install 'delete-empty-/sbin
  304. (lambda* (#:key outputs #:allow-other-keys)
  305. (let ((out (assoc-ref outputs "out")))
  306. (rmdir (string-append out "/sbin"))
  307. #t))))))
  308. (native-inputs
  309. `(("pkg-config" ,pkg-config)))
  310. (inputs
  311. `(("gtk+" ,gtk+-2)
  312. ("lcms" ,lcms)
  313. ("libjpeg" ,libjpeg-turbo)
  314. ("libtiff" ,libtiff)
  315. ("sane-backends" ,sane-backends)
  316. ;; To open the manual from the Help menu.
  317. ("xdg-utils" ,xdg-utils)))
  318. (home-page "https://gitlab.com/sane-project/frontend/xsane")
  319. (synopsis "Featureful graphical interface for document and image scanners")
  320. (description
  321. "XSane is a graphical interface for controlling a scanner and acquiring
  322. images from it. You can photocopy multi-page documents and save, fax, print,
  323. or e-mail your scanned images. It is highly configurable and exposes all
  324. device settings, letting you fine-tune the final result. It can also be used
  325. as a GIMP plugin to acquire images directly from a scanner.
  326. XSane talks to scanners through the @acronym{SANE, Scanner Access Now Easy}
  327. back-end library, which supports almost all existing scanners.")
  328. (license license:gpl2+)))