Merge remote-tracking branch 'origin/master' into core-updates
[jackhill/guix/guix.git] / gnu / packages / cups.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; Copyright © 2015, 2016 Efraim Flashner <efraim@flashner.co.il>
5 ;;; Copyright © 2016 Danny Milosavljevic <dannym@scratchpost.org>
6 ;;; Copyright © 2017 Leo Famulari <leo@famulari.name>
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 cups)
24 #:use-module ((guix licenses) #:prefix license:)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix build-system gnu)
28 #:use-module (gnu packages)
29 #:use-module (gnu packages avahi)
30 #:use-module (gnu packages compression)
31 #:use-module (gnu packages libusb)
32 #:use-module (gnu packages autotools)
33 #:use-module (gnu packages python)
34 #:use-module (gnu packages scanner)
35 #:use-module (gnu packages image)
36 #:use-module (gnu packages fonts) ;font-dejavu
37 #:use-module (gnu packages fontutils)
38 #:use-module (gnu packages ghostscript)
39 #:use-module (gnu packages glib)
40 #:use-module (gnu packages pdf)
41 #:use-module (gnu packages pkg-config)
42 #:use-module (gnu packages tls))
43
44 ;; Delay to avoid module circularity problems.
45 (define ghostscript/cups
46 (delay
47 (package (inherit ghostscript)
48 (name "ghostscript-with-cups")
49 (inputs `(("cups" ,cups-minimal)
50 ,@(package-inputs ghostscript))))))
51
52 (define-public cups-filters
53 (package
54 (name "cups-filters")
55 (version "1.13.1")
56 (source(origin
57 (method url-fetch)
58 (uri
59 (string-append "http://openprinting.org/download/cups-filters/"
60 "cups-filters-" version ".tar.xz"))
61 (sha256
62 (base32
63 "0s7hylp2lcvc1vrqpywpv7lspkrh4xf7cyi4nbg10cf38rshj474"))
64 (modules '((guix build utils)))
65 (snippet
66 ;; install backends, banners and filters to cups-filters output
67 ;; directory, not the cups server directory
68 '(begin
69 (substitute* "Makefile.in"
70 (("CUPS_DATADIR = @CUPS_DATADIR@")
71 "CUPS_DATADIR = $(PREFIX)/share/cups")
72 (("pkgcupsserverrootdir = \\$\\(CUPS_SERVERROOT\\)")
73 "pkgcupsserverrootdir = $(PREFIX)")
74 ;; Choose standard directories notably so that binaries are
75 ;; stripped.
76 (("pkgbackenddir = \\$\\(CUPS_SERVERBIN\\)/backend")
77 "pkgbackenddir = $(PREFIX)/lib/cups/backend")
78 (("pkgfilterdir = \\$\\(CUPS_SERVERBIN\\)/filter")
79 "pkgfilterdir = $(PREFIX)/lib/cups/filter"))
80 ;; Find bannertopdf data such as the print test page in our
81 ;; output directory, not CUPS's prefix.
82 (substitute* "configure"
83 (("\\{CUPS_DATADIR\\}/data")
84 "{prefix}/share/cups/data"))))))
85 (build-system gnu-build-system)
86 (arguments
87 `(#:make-flags (list (string-append "PREFIX=" %output))
88 #:configure-flags
89 `("--disable-driverless" ; TODO: enable this
90 "--disable-mutool" ; depends on yet another PDF library (mupdf)
91 ,(string-append "--with-test-font-path="
92 (assoc-ref %build-inputs "font-dejavu")
93 "/share/fonts/truetype/DejaVuSans.ttf")
94 ,(string-append "--with-gs-path="
95 (assoc-ref %build-inputs "ghostscript")
96 "/bin/gsc")
97 ,(string-append "--with-shell="
98 (assoc-ref %build-inputs "bash")
99 "/bin/bash")
100 ,(string-append "--with-rcdir="
101 (assoc-ref %outputs "out") "/etc/rc.d"))))
102 (native-inputs
103 `(("glib" ,glib "bin") ; for gdbus-codegen
104 ("pkg-config" ,pkg-config)))
105 (inputs
106 `(("avahi" ,avahi)
107 ("fontconfig" ,fontconfig)
108 ("freetype" ,freetype)
109 ("font-dejavu" ,font-dejavu) ; also needed by test suite
110 ("ghostscript" ,(force ghostscript/cups))
111 ("ijs" ,ijs)
112 ("dbus" ,dbus)
113 ("lcms" ,lcms)
114 ("libjpeg" ,libjpeg)
115 ("libpng" ,libpng)
116 ("libtiff" ,libtiff)
117 ("glib" ,glib)
118 ("qpdf" ,qpdf)
119 ("poppler" ,poppler)
120 ("cups-minimal" ,cups-minimal)))
121 (home-page "https://wiki.linuxfoundation.org/openprinting/cups-filters")
122 (synopsis "OpenPrinting CUPS filters and backends")
123 (description
124 "Contains backends, filters, and other software that was once part of the
125 core CUPS distribution but is no longer maintained by Apple Inc. In addition
126 it contains additional filters developed independently of Apple, especially
127 filters for the PDF-centric printing workflow introduced by OpenPrinting.")
128 ;; Different filters and backends have different licenses; see COPYING for
129 ;; details
130 (license (list license:gpl2
131 license:gpl2+
132 license:gpl3
133 license:gpl3+
134 license:lgpl2.0+
135 license:expat))))
136
137 ;; CUPS on non-MacOS systems requires cups-filters. Since cups-filters also
138 ;; depends on CUPS libraries and binaries, cups-minimal has been added to
139 ;; satisfy this dependency.
140 (define-public cups-minimal
141 (package
142 (name "cups-minimal")
143 (version "2.2.1")
144 (source
145 (origin
146 (method url-fetch)
147 (uri (string-append "https://github.com/apple/cups/releases/download/v"
148 version "/cups-" version "-source.tar.gz"))
149 (sha256
150 (base32
151 "1m8rwhbk0l8n19iwm51r2569jj15d0x6mpqhfig0bk3pm4577f43"))))
152 (build-system gnu-build-system)
153 (arguments
154 `(#:configure-flags
155 '("--disable-launchd"
156 "--disable-systemd"
157 "--disable-avahi"
158 "--disable-dnssd")
159 ;; Seven tests fail, mostly because of files that are provided by the
160 ;; cups-filters package.
161 #:tests? #f
162 #:phases
163 (modify-phases %standard-phases
164 (add-before 'configure 'patch-makedefs
165 (lambda _
166 (substitute* "Makedefs.in"
167 (("INITDIR.*=.*@INITDIR@") "INITDIR = @prefix@/@INITDIR@")
168 (("/bin/sh") (which "sh")))))
169 ;; Make the compressed manpages writable so that the
170 ;; reset-gzip-timestamps phase does not error out.
171 (add-before 'reset-gzip-timestamps 'make-manpages-writable
172 (lambda* (#:key outputs #:allow-other-keys)
173 (let* ((out (assoc-ref outputs "out"))
174 (man (string-append out "/share/man")))
175 (for-each (lambda (file) (chmod file #o644))
176 (find-files man "\\.gz")))))
177 (add-before 'build 'patch-tests
178 (lambda _
179 (substitute* "test/ippserver.c"
180 (("# else /\\* HAVE_AVAHI \\*/")
181 "#elif defined(HAVE_AVAHI)")))))))
182 (native-inputs
183 `(("pkg-config" ,pkg-config)))
184 (inputs
185 `(("zlib" ,zlib)
186 ("gnutls" ,gnutls)))
187 (home-page "https://www.cups.org")
188 (synopsis "The Common Unix Printing System")
189 (description
190 "CUPS is a printing system that uses the Internet Printing
191 Protocol (IPP). It provides System V and BSD command-line interfaces, as well
192 as a Web interface and a C programming interface to manage printers and print
193 jobs. It supports printing to both local (parallel, serial, USB) and
194 networked printers, and printers can be shared from one computer to another.
195 Internally, CUPS uses PostScript Printer Description (PPD) files to describe
196 printer capabilities and features and a wide variety of generic and
197 device-specific programs to convert and print many types of files.")
198 (license license:gpl2)))
199
200 (define-public cups
201 (package (inherit cups-minimal)
202 (name "cups")
203 (arguments
204 `(;; Three tests fail:
205 ;; * two tests in ipp-1.1.test related to "RFC 2911 section 3.2.6:
206 ;; Get-Jobs Operation"
207 ;; * test of number of error/warning messages, probably related to a
208 ;; missing font.
209 #:tests? #f
210 #:configure-flags
211 '("--disable-launchd"
212 "--disable-systemd")
213 #:phases
214 (modify-phases %standard-phases
215 (add-before 'configure 'patch-makedefs
216 (lambda _
217 (substitute* "Makedefs.in"
218 (("INITDIR.*=.*@INITDIR@") "INITDIR = @prefix@/@INITDIR@")
219 (("/bin/sh") (which "sh")))))
220 (add-before 'check 'patch-tests
221 (lambda _
222 (let ((filters (assoc-ref %build-inputs "cups-filters"))
223 (catpath (string-append
224 (assoc-ref %build-inputs "coreutils") "/bin/"))
225 (testdir (string-append (getcwd) "/tmp/")))
226 (mkdir testdir)
227 (substitute* "test/run-stp-tests.sh"
228 ((" *BASE=/tmp/") (string-append "BASE=" testdir))
229
230 ;; allow installation of filters from output dir and from
231 ;; cups-filters
232 (("for dir in /usr/libexec/cups/filter /usr/lib/cups/filter")
233 (string-append
234 "for dir in "
235 (assoc-ref %outputs "out") "/lib/cups/filter "
236 filters "/lib/cups/filter"))
237
238 ;; check for charsets in cups-filters output
239 (("/usr/share/cups/charsets")
240 (string-append filters "/share/cups/charsets"))
241
242 ;; install additional required filters
243 (("instfilter texttopdf texttopdf pdf")
244 (string-append
245 "instfilter texttopdf texttopdf pdf;"
246 "instfilter imagetoraster imagetoraster raster;"
247 "instfilter gstoraster gstoraster raster;"
248 "instfilter urftopdf urftopdf pdf;"
249 "instfilter rastertopdf rastertopdf pdf;"
250 "instfilter pstopdf pstopdf pdf"))
251
252 ;; specify location of lpstat binary
253 (("description=\"`lpstat -l")
254 "description=\"`../systemv/lpstat -l")
255
256 ;; patch shebangs of embedded scripts
257 (("#!/bin/sh") (string-append "#!" (which "sh")))
258
259 ;; also link mime definitions from cups-filters
260 ;; to enable the additional filters for the test suite
261 (("ln -s \\$root/conf/mime\\.types")
262 (string-append
263 "ln -s " filters
264 "/share/cups/mime/cupsfilters.types $BASE/share/mime; "
265 "ln -s $root/conf/mime.types"))
266 (("ln -s \\$root/conf/mime\\.convs")
267 (string-append
268 "ln -s " filters
269 "/share/cups/mime/cupsfilters.convs $BASE/share/mime; "
270 "ln -s $root/conf/mime.convs")))
271
272 ;; fix search path for "cat"
273 (substitute* "cups/testfile.c"
274 (("cupsFileFind\\(\"cat\", \"/bin\"")
275 (string-append "cupsFileFind(\"cat\", \"" catpath "\""))
276 (("cupsFileFind\\(\"cat\", \"/bin:/usr/bin\"")
277 (string-append "cupsFileFind(\"cat\", \"" catpath "\""))))))
278 ;; Make the compressed manpages writable so that the
279 ;; reset-gzip-timestamps phase does not error out.
280 (add-before 'reset-gzip-timestamps 'make-manpages-writable
281 (lambda* (#:key outputs #:allow-other-keys)
282 (let* ((out (assoc-ref outputs "out"))
283 (man (string-append out "/share/man")))
284 (for-each (lambda (file) (chmod file #o644))
285 (find-files man "\\.gz")))))
286 (add-after 'install 'install-cups-filters-symlinks
287 (lambda* (#:key inputs outputs #:allow-other-keys)
288 (let ((out (assoc-ref outputs "out"))
289 (cups-filters (assoc-ref inputs "cups-filters")))
290 ;; charsets
291 (symlink
292 (string-append cups-filters "/share/cups/charsets")
293 (string-append out "/share/charsets"))
294
295 ;; mime types, driver file, ppds
296 (for-each
297 (lambda (f)
298 (symlink (string-append cups-filters f)
299 (string-append out f)))
300 '("/share/cups/mime/cupsfilters.types"
301 "/share/cups/mime/cupsfilters.convs"
302 "/share/cups/drv/cupsfilters.drv"
303 "/share/ppd"))
304
305 ;; filters
306 (for-each
307 (lambda (f)
308 (symlink f
309 (string-append out "/lib/cups/filter" (basename f))))
310 (find-files (string-append cups-filters "/lib/cups/filter")))
311
312 ;; backends
313 (for-each
314 (lambda (f)
315 (symlink (string-append cups-filters f)
316 (string-append out "/lib/cups/backend/"
317 (basename f))))
318 '("/lib/cups/backend/parallel"
319 "/lib/cups/backend/serial"))
320
321 ;; banners
322 (let ((banners "/share/cups/banners"))
323 (delete-file-recursively (string-append out banners))
324 (symlink (string-append cups-filters banners)
325 (string-append out banners)))
326
327 ;; assorted data
328 (let ((data "/share/cups/data"))
329 (delete-file-recursively (string-append out data))
330 (symlink (string-append cups-filters data)
331 (string-append out data)))))))))
332 (inputs
333 `(("avahi" ,avahi)
334 ("gnutls" ,gnutls)
335 ("cups-filters" ,cups-filters)
336 ("zlib" ,zlib)))))
337
338 (define-public hplip
339 (package
340 (name "hplip")
341 (version "3.16.11")
342 (source (origin
343 (method url-fetch)
344 (uri (string-append "mirror://sourceforge/hplip/hplip/" version
345 "/hplip-" version ".tar.gz"))
346 (sha256
347 (base32
348 "094vkyr0rjng72m13dgr824cdl7q20x23qjxzih4w7l9njn0rqpn"))))
349 (build-system gnu-build-system)
350 (home-page "http://hplipopensource.com/")
351 (synopsis "HP Printer Drivers")
352 (description "Hewlett-Packard Printer Drivers and PPDs.")
353
354 ;; The 'COPYING' file lists directories where each of these 3 licenses
355 ;; applies.
356 (license (list license:gpl2+ license:bsd-3 license:expat))
357
358 ;; TODO install apparmor profile files eventually.
359 (arguments
360 `(#:configure-flags
361 `("--disable-network-build"
362 ,(string-append "--prefix=" (assoc-ref %outputs "out"))
363 ,(string-append "--sysconfdir=" (assoc-ref %outputs "out") "/etc")
364 ;; Disable until mime.types merging works (FIXME).
365 "--disable-fax-build"
366 "--enable-hpcups-install"
367 "--enable-new-hpcups"
368 "--enable-cups_ppd_install"
369 "--enable-cups_drv_install"
370 ;; TODO add foomatic drv install eventually.
371 ;; TODO --enable-policykit eventually.
372 ,(string-append "--with-cupsfilterdir="
373 (assoc-ref %outputs "out") "/lib/cups/filter")
374 ,(string-append "--with-cupsbackenddir="
375 (assoc-ref %outputs "out") "/lib/cups/backend")
376 ,(string-append "--with-icondir="
377 (assoc-ref %outputs "out") "/share/applications")
378 ,(string-append "--with-systraydir="
379 (assoc-ref %outputs "out") "/etc/xdg"))
380
381 #:imported-modules ((guix build python-build-system)
382 ,@%gnu-build-system-modules)
383 #:modules ((guix build gnu-build-system)
384 (guix build utils)
385 ((guix build python-build-system) #:prefix python:))
386
387 #:phases (modify-phases %standard-phases
388 (add-after 'unpack 'fix-hard-coded-file-names
389 (lambda* (#:key inputs outputs #:allow-other-keys)
390 (let ((out (assoc-ref outputs "out"))
391 ;; FIXME: use merged ppds (I think actually only
392 ;; drvs need to be merged).
393 (cupsdir (assoc-ref inputs "cups-minimal")))
394 (substitute* "base/g.py"
395 (("'/usr/share;[^']*'")
396 (string-append "'" cupsdir "/share'"))
397 (("'/etc/hp/hplip.conf'")
398 (string-append "'" out
399 "/etc/hp/hplip.conf" "'")))
400
401 (substitute* "Makefile.in"
402 (("[[:blank:]]check-plugin\\.py[[:blank:]]") " ")
403 ;; FIXME Use beginning-of-word in regexp.
404 (("[[:blank:]]plugin\\.py[[:blank:]]") " ")
405 (("/usr/include/libusb-1.0")
406 (string-append (assoc-ref inputs "libusb")
407 "/include/libusb-1.0"))
408 (("^\tinstall-dist_hplip_stateDATA")
409 ;; Remove dependencies on
410 ;; 'install-dist_hplip_stateDATA' so we don't bail
411 ;; out while trying to create /var/lib/hplip.
412 "\t")
413 (("hplip_confdir = /etc/hp")
414 ;; This is only used for installing the default config.
415 (string-append "hplip_confdir = " out
416 "/etc/hp"))
417 (("halpredir = /usr/share/hal/fdi/preprobe/10osvendor")
418 ;; Note: We don't use hal.
419 (string-append "halpredir = " out
420 "/share/hal/fdi/preprobe/10osvendor"))
421 (("rulesdir = /etc/udev/rules.d")
422 ;; udev rules will be merged by base service.
423 (string-append "rulesdir = " out
424 "/lib/udev/rules.d"))
425 (("rulessystemdir = /usr/lib/systemd/system")
426 ;; We don't use systemd.
427 (string-append "rulessystemdir = " out
428 "/lib/systemd/system"))
429 (("/etc/sane.d")
430 (string-append out "/etc/sane.d"))))))
431
432 ;; Wrap bin/* so that the Python libs are found.
433 (add-after 'install 'wrap-binaries
434 (assoc-ref python:%standard-phases 'wrap)))))
435
436 ;; Python3 support is available starting from hplip@3.15.2.
437 (inputs `(("libjpeg" ,libjpeg)
438 ("cups-minimal" ,cups-minimal)
439 ("libusb" ,libusb)
440 ("sane-backends" ,sane-backends-minimal)
441 ("dbus" ,dbus)
442 ("python-wrapper" ,python-wrapper)
443 ("python" ,python)
444 ;; TODO: Make hp-setup find python-dbus.
445 ("python-dbus" ,python-dbus)))
446 (native-inputs `(("pkg-config" ,pkg-config)))))