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 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 ,(string-append "--with-test-font-path="
91 (assoc-ref %build-inputs "font-dejavu")
92 "/share/fonts/truetype/DejaVuSans.ttf")
93 ,(string-append "--with-gs-path="
94 (assoc-ref %build-inputs "ghostscript")
95 "/bin/gsc")
96 ,(string-append "--with-shell="
97 (assoc-ref %build-inputs "bash")
98 "/bin/bash")
99 ,(string-append "--with-rcdir="
100 (assoc-ref %outputs "out") "/etc/rc.d"))))
101 (native-inputs
102 `(("glib" ,glib "bin") ; for gdbus-codegen
103 ("pkg-config" ,pkg-config)))
104 (inputs
105 `(("avahi" ,avahi)
106 ("fontconfig" ,fontconfig)
107 ("freetype" ,freetype)
108 ("font-dejavu" ,font-dejavu) ; also needed by test suite
109 ("ghostscript" ,(force ghostscript/cups))
110 ("ijs" ,ijs)
111 ("dbus" ,dbus)
112 ("lcms" ,lcms)
113 ("libjpeg" ,libjpeg)
114 ("libpng" ,libpng)
115 ("libtiff" ,libtiff)
116 ("mupdf" ,mupdf)
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 (add-before 'build 'patch-tests
170 (lambda _
171 (substitute* "test/ippserver.c"
172 (("# else /\\* HAVE_AVAHI \\*/")
173 "#elif defined(HAVE_AVAHI)")))))))
174 (native-inputs
175 `(("pkg-config" ,pkg-config)))
176 (inputs
177 `(("zlib" ,zlib)
178 ("gnutls" ,gnutls)))
179 (home-page "https://www.cups.org")
180 (synopsis "The Common Unix Printing System")
181 (description
182 "CUPS is a printing system that uses the Internet Printing
183 Protocol (IPP). It provides System V and BSD command-line interfaces, as well
184 as a Web interface and a C programming interface to manage printers and print
185 jobs. It supports printing to both local (parallel, serial, USB) and
186 networked printers, and printers can be shared from one computer to another.
187 Internally, CUPS uses PostScript Printer Description (PPD) files to describe
188 printer capabilities and features and a wide variety of generic and
189 device-specific programs to convert and print many types of files.")
190 (license license:gpl2)))
191
192 (define-public cups
193 (package (inherit cups-minimal)
194 (name "cups")
195 (arguments
196 `(;; Three tests fail:
197 ;; * two tests in ipp-1.1.test related to "RFC 2911 section 3.2.6:
198 ;; Get-Jobs Operation"
199 ;; * test of number of error/warning messages, probably related to a
200 ;; missing font.
201 #:tests? #f
202 #:configure-flags
203 '("--disable-launchd"
204 "--disable-systemd")
205 #:phases
206 (modify-phases %standard-phases
207 (add-before 'configure 'patch-makedefs
208 (lambda _
209 (substitute* "Makedefs.in"
210 (("INITDIR.*=.*@INITDIR@") "INITDIR = @prefix@/@INITDIR@")
211 (("/bin/sh") (which "sh")))))
212 (add-before 'check 'patch-tests
213 (lambda _
214 (let ((filters (assoc-ref %build-inputs "cups-filters"))
215 (catpath (string-append
216 (assoc-ref %build-inputs "coreutils") "/bin/"))
217 (testdir (string-append (getcwd) "/tmp/")))
218 (mkdir testdir)
219 (substitute* "test/run-stp-tests.sh"
220 ((" *BASE=/tmp/") (string-append "BASE=" testdir))
221
222 ;; allow installation of filters from output dir and from
223 ;; cups-filters
224 (("for dir in /usr/libexec/cups/filter /usr/lib/cups/filter")
225 (string-append
226 "for dir in "
227 (assoc-ref %outputs "out") "/lib/cups/filter "
228 filters "/lib/cups/filter"))
229
230 ;; check for charsets in cups-filters output
231 (("/usr/share/cups/charsets")
232 (string-append filters "/share/cups/charsets"))
233
234 ;; install additional required filters
235 (("instfilter texttopdf texttopdf pdf")
236 (string-append
237 "instfilter texttopdf texttopdf pdf;"
238 "instfilter imagetoraster imagetoraster raster;"
239 "instfilter gstoraster gstoraster raster;"
240 "instfilter urftopdf urftopdf pdf;"
241 "instfilter rastertopdf rastertopdf pdf;"
242 "instfilter pstopdf pstopdf pdf"))
243
244 ;; specify location of lpstat binary
245 (("description=\"`lpstat -l")
246 "description=\"`../systemv/lpstat -l")
247
248 ;; patch shebangs of embedded scripts
249 (("#!/bin/sh") (string-append "#!" (which "sh")))
250
251 ;; also link mime definitions from cups-filters
252 ;; to enable the additional filters for the test suite
253 (("ln -s \\$root/conf/mime\\.types")
254 (string-append
255 "ln -s " filters
256 "/share/cups/mime/cupsfilters.types $BASE/share/mime; "
257 "ln -s $root/conf/mime.types"))
258 (("ln -s \\$root/conf/mime\\.convs")
259 (string-append
260 "ln -s " filters
261 "/share/cups/mime/cupsfilters.convs $BASE/share/mime; "
262 "ln -s $root/conf/mime.convs")))
263
264 ;; fix search path for "cat"
265 (substitute* "cups/testfile.c"
266 (("cupsFileFind\\(\"cat\", \"/bin\"")
267 (string-append "cupsFileFind(\"cat\", \"" catpath "\""))
268 (("cupsFileFind\\(\"cat\", \"/bin:/usr/bin\"")
269 (string-append "cupsFileFind(\"cat\", \"" catpath "\""))))))
270 (add-after 'install 'install-cups-filters-symlinks
271 (lambda* (#:key inputs outputs #:allow-other-keys)
272 (let ((out (assoc-ref outputs "out"))
273 (cups-filters (assoc-ref inputs "cups-filters")))
274 ;; charsets
275 (symlink
276 (string-append cups-filters "/share/cups/charsets")
277 (string-append out "/share/charsets"))
278
279 ;; mime types, driver file, ppds
280 (for-each
281 (lambda (f)
282 (symlink (string-append cups-filters f)
283 (string-append out f)))
284 '("/share/cups/mime/cupsfilters.types"
285 "/share/cups/mime/cupsfilters.convs"
286 "/share/cups/drv/cupsfilters.drv"
287 "/share/ppd"))
288
289 ;; filters
290 (for-each
291 (lambda (f)
292 (symlink f
293 (string-append out "/lib/cups/filter" (basename f))))
294 (find-files (string-append cups-filters "/lib/cups/filter")))
295
296 ;; backends
297 (for-each
298 (lambda (f)
299 (symlink (string-append cups-filters f)
300 (string-append out "/lib/cups/backend/"
301 (basename f))))
302 '("/lib/cups/backend/parallel"
303 "/lib/cups/backend/serial"))
304
305 ;; banners
306 (let ((banners "/share/cups/banners"))
307 (delete-file-recursively (string-append out banners))
308 (symlink (string-append cups-filters banners)
309 (string-append out banners)))
310
311 ;; assorted data
312 (let ((data "/share/cups/data"))
313 (delete-file-recursively (string-append out data))
314 (symlink (string-append cups-filters data)
315 (string-append out data)))))))))
316 (inputs
317 `(("avahi" ,avahi)
318 ("gnutls" ,gnutls)
319 ("cups-filters" ,cups-filters)
320 ("zlib" ,zlib)))))
321
322 (define-public hplip
323 (package
324 (name "hplip")
325 (version "3.16.11")
326 (source (origin
327 (method url-fetch)
328 (uri (string-append "mirror://sourceforge/hplip/hplip/" version
329 "/hplip-" version ".tar.gz"))
330 (sha256
331 (base32
332 "094vkyr0rjng72m13dgr824cdl7q20x23qjxzih4w7l9njn0rqpn"))))
333 (build-system gnu-build-system)
334 (home-page "http://hplipopensource.com/")
335 (synopsis "HP Printer Drivers")
336 (description "Hewlett-Packard Printer Drivers and PPDs.")
337
338 ;; The 'COPYING' file lists directories where each of these 3 licenses
339 ;; applies.
340 (license (list license:gpl2+ license:bsd-3 license:expat))
341
342 ;; TODO install apparmor profile files eventually.
343 (arguments
344 `(#:configure-flags
345 `("--disable-network-build"
346 ,(string-append "--prefix=" (assoc-ref %outputs "out"))
347 ,(string-append "--sysconfdir=" (assoc-ref %outputs "out") "/etc")
348 ;; Disable until mime.types merging works (FIXME).
349 "--disable-fax-build"
350 "--enable-hpcups-install"
351 "--enable-new-hpcups"
352 "--enable-cups_ppd_install"
353 "--enable-cups_drv_install"
354 ;; TODO add foomatic drv install eventually.
355 ;; TODO --enable-policykit eventually.
356 ,(string-append "--with-cupsfilterdir="
357 (assoc-ref %outputs "out") "/lib/cups/filter")
358 ,(string-append "--with-cupsbackenddir="
359 (assoc-ref %outputs "out") "/lib/cups/backend")
360 ,(string-append "--with-icondir="
361 (assoc-ref %outputs "out") "/share/applications")
362 ,(string-append "--with-systraydir="
363 (assoc-ref %outputs "out") "/etc/xdg"))
364
365 #:imported-modules ((guix build python-build-system)
366 ,@%gnu-build-system-modules)
367 #:modules ((guix build gnu-build-system)
368 (guix build utils)
369 ((guix build python-build-system) #:prefix python:))
370
371 #:phases (modify-phases %standard-phases
372 (add-after 'unpack 'fix-hard-coded-file-names
373 (lambda* (#:key inputs outputs #:allow-other-keys)
374 (let ((out (assoc-ref outputs "out"))
375 ;; FIXME: use merged ppds (I think actually only
376 ;; drvs need to be merged).
377 (cupsdir (assoc-ref inputs "cups-minimal")))
378 (substitute* "base/g.py"
379 (("'/usr/share;[^']*'")
380 (string-append "'" cupsdir "/share'"))
381 (("'/etc/hp/hplip.conf'")
382 (string-append "'" out
383 "/etc/hp/hplip.conf" "'")))
384
385 (substitute* "Makefile.in"
386 (("[[:blank:]]check-plugin\\.py[[:blank:]]") " ")
387 ;; FIXME Use beginning-of-word in regexp.
388 (("[[:blank:]]plugin\\.py[[:blank:]]") " ")
389 (("/usr/include/libusb-1.0")
390 (string-append (assoc-ref inputs "libusb")
391 "/include/libusb-1.0"))
392 (("^\tinstall-dist_hplip_stateDATA")
393 ;; Remove dependencies on
394 ;; 'install-dist_hplip_stateDATA' so we don't bail
395 ;; out while trying to create /var/lib/hplip.
396 "\t")
397 (("hplip_confdir = /etc/hp")
398 ;; This is only used for installing the default config.
399 (string-append "hplip_confdir = " out
400 "/etc/hp"))
401 (("halpredir = /usr/share/hal/fdi/preprobe/10osvendor")
402 ;; Note: We don't use hal.
403 (string-append "halpredir = " out
404 "/share/hal/fdi/preprobe/10osvendor"))
405 (("rulesdir = /etc/udev/rules.d")
406 ;; udev rules will be merged by base service.
407 (string-append "rulesdir = " out
408 "/lib/udev/rules.d"))
409 (("rulessystemdir = /usr/lib/systemd/system")
410 ;; We don't use systemd.
411 (string-append "rulessystemdir = " out
412 "/lib/systemd/system"))
413 (("/etc/sane.d")
414 (string-append out "/etc/sane.d"))))))
415
416 ;; Wrap bin/* so that the Python libs are found.
417 (add-after 'install 'wrap-binaries
418 (assoc-ref python:%standard-phases 'wrap)))))
419
420 ;; Python3 support is available starting from hplip@3.15.2.
421 (inputs `(("libjpeg" ,libjpeg)
422 ("cups-minimal" ,cups-minimal)
423 ("libusb" ,libusb)
424 ("sane-backends" ,sane-backends-minimal)
425 ("dbus" ,dbus)
426 ("python-wrapper" ,python-wrapper)
427 ("python" ,python)
428 ;; TODO: Make hp-setup find python-dbus.
429 ("python-dbus" ,python-dbus)))
430 (native-inputs `(("pkg-config" ,pkg-config)))))