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