222b4cb6dc97e2cd9f7c0b3489dbc9e8bb010930
[jackhill/guix/guix.git] / gnu / packages / groff.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013 Andreas Enge <andreas@enge.fr>
3 ;;; Copyright © 2014 Mark H Weaver <mhw@netris.org>
4 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
5 ;;; Copyright © 2017 Ludovic Courtès <ludo@gnu.org>
6 ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
7 ;;; Copyright © 2019 Eric Bavier <bavier@member.fsf.org>
8 ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
9 ;;; Copyright © 2020 Michael Rohleder <mike@rohleder.de>
10 ;;;
11 ;;; This file is part of GNU Guix.
12 ;;;
13 ;;; GNU Guix is free software; you can redistribute it and/or modify it
14 ;;; under the terms of the GNU General Public License as published by
15 ;;; the Free Software Foundation; either version 3 of the License, or (at
16 ;;; your option) any later version.
17 ;;;
18 ;;; GNU Guix is distributed in the hope that it will be useful, but
19 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;;; GNU General Public License for more details.
22 ;;;
23 ;;; You should have received a copy of the GNU General Public License
24 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
25
26 (define-module (gnu packages groff)
27 #:use-module (guix licenses)
28 #:use-module (guix packages)
29 #:use-module (guix utils)
30 #:use-module (guix download)
31 #:use-module (guix git-download)
32 #:use-module (guix build-system gnu)
33 #:use-module (gnu packages)
34 #:use-module (gnu packages bison)
35 #:use-module (gnu packages ghostscript)
36 #:use-module (gnu packages netpbm)
37 #:use-module (gnu packages perl)
38 #:use-module (gnu packages texinfo)
39 #:use-module (gnu packages web))
40
41 (define-public groff
42 (package
43 (name "groff")
44 (version "1.22.4")
45 (source (origin
46 (method url-fetch)
47 (uri (string-append "mirror://gnu/groff/groff-" version
48 ".tar.gz"))
49 (sha256 (base32
50 "14q2mldnr1vx0l9lqp9v2f6iww24gj28iyh4j2211hyynx67p3p7"))))
51 (build-system gnu-build-system)
52 (outputs '("out"
53 "doc")) ;12MiB of PS, PDF, HTML, and examples
54
55 ;; Note: groff's HTML backend uses executables from netpbm when they are in
56 ;; $PATH. In practice, not having them doesn't prevent it from install its
57 ;; own HTML doc, nor does it change its capabilities, so we removed netpbm
58 ;; from 'inputs'.
59
60 (inputs `(("ghostscript" ,ghostscript)))
61
62 ;; When cross-compiling, this package depends upon a native install of
63 ;; itself.
64 (native-inputs `(,@(if (%current-target-system)
65 `(("self" ,this-package))
66 '())
67 ("bison" ,bison)
68 ("perl" ,perl)
69 ("psutils" ,psutils)
70 ("texinfo" ,texinfo)))
71 (arguments
72 `(#:parallel-build? #f ; parallel build fails
73 ,@(if (%current-target-system)
74 `(#:make-flags
75 ;; In groff-minimal package, that inherits from this package,
76 ;; we'll need to locate "groff" instead of "self".
77 (let ((groff (or (assoc-ref %build-host-inputs "groff")
78 (assoc-ref %build-host-inputs "self"))))
79 (list
80 (string-append "GROFF_BIN_PATH=" groff)
81 (string-append "GROFFBIN=" groff "/bin/groff"))))
82 '())
83 #:phases
84 (modify-phases %standard-phases
85 (add-after 'unpack 'disable-relocatability
86 (lambda _
87 ;; Groff contains a Rube Goldberg-esque relocator for the file
88 ;; "charset.alias". It tries to find the current executable
89 ;; using realpath, a do-it-yourself search in $PATH and so on.
90 ;; Furthermore, the routine that does the search is buggy
91 ;; in that it doesn't handle error cases when they arise.
92 ;; This causes preconv to segfault when trying to look up
93 ;; the file "charset.alias" in the NULL location.
94 ;; The "charset.alias" parser is a copy of gnulib's, and a
95 ;; non-broken version of gnulib's "charset.alias" parser is
96 ;; part of glibc's libcharset.
97 ;; However, groff unconditionally uses their own
98 ;; "charset.alias" parser, but then DOES NOT INSTALL the
99 ;; file "charset.alias" when glibc is too new.
100 ;; In Guix, our file "charset.alias" only contains an obscure
101 ;; alias for ASCII and nothing else. So just disable relocation
102 ;; and make the entire "charset.alias" lookup fail.
103 ;; See <https://debbugs.gnu.org/cgi/bugreport.cgi?bug=30785> for
104 ;; details.
105 (substitute* "Makefile.in"
106 (("-DENABLE_RELOCATABLE=1") ""))
107 #t))
108 (add-after 'unpack 'setenv
109 (lambda _
110 (setenv "GS_GENERATE_UUIDS" "0")
111 #t))
112 (add-after 'unpack 'fix-docdir
113 (lambda _ ;see https://savannah.gnu.org/bugs/index.php?55461
114 (substitute* "Makefile.in"
115 (("^docdir =.*") "docdir = @docdir@\n"))
116 #t)))))
117 (synopsis "Typesetting from plain text mixed with formatting commands")
118 (description
119 "Groff is a typesetting package that reads plain text and produces
120 formatted output based on formatting commands contained within the text. It
121 is usually the formatter of \"man\" documentation pages.")
122 (license gpl3+)
123 (home-page "https://www.gnu.org/software/groff/")))
124
125 (define-public groff-minimal
126 ;; Minimialist groff for use by man-db. Its closure size is less than half
127 ;; that of the full-blown groff.
128 (package
129 (inherit groff)
130 (name "groff-minimal")
131 (synopsis "Minimalist variant of Groff for use by man-db")
132 (outputs '("out"))
133
134 ;; Omit the DVI, PS, PDF, and HTML backends.
135 (inputs '())
136 (native-inputs `(("bison" ,bison)
137 ("perl" ,perl)
138 ("groff" ,groff)))
139
140 (arguments
141 `(#:disallowed-references (,perl)
142
143 #:configure-flags '("--with-doc=no")
144
145 ,@(substitute-keyword-arguments (package-arguments groff)
146 ((#:phases phases)
147 `(modify-phases ,phases
148 (add-after 'install 'remove-non-essential-programs
149 (lambda* (#:key outputs #:allow-other-keys)
150 ;; Keep only the programs that man-db needs at run time,
151 ;; and make sure we don't pull in Perl.
152 (let ((out (assoc-ref outputs "out"))
153 (kept '("eqn" "neqn" "pic" "tbl" "refer" "preconv"
154 "nroff" "groff" "troff" "grotty")))
155 (for-each (lambda (file)
156 (unless (member (basename file) kept)
157 (delete-file file)))
158 (find-files (string-append out "/bin")))
159
160 ;; Remove a bunch of unneeded Perl scripts.
161 (for-each delete-file (find-files out "\\.pl$"))
162 (for-each delete-file
163 (find-files out "BuildFoundries"))
164
165 ;; Remove ~3 MiB from share/groff/X.Y/font/devBACKEND
166 ;; corresponding to the unused backends.
167 (for-each delete-file-recursively
168 (find-files out "^dev(dvi|ps|pdf|html|lj4)$"
169 #:directories? #t))
170 #t))))))))))
171
172 ;; There are no releases, so we take the latest commit.
173 (define-public roffit
174 (let ((commit "b59e6c855ebea03daf76e996b5c0f8343f11be3d")
175 (revision "1"))
176 (package
177 (name "roffit")
178 (version (string-append "0.12-" revision "." (string-take commit 9)))
179 (source (origin
180 (method git-fetch)
181 (uri (git-reference
182 (url "https://github.com/bagder/roffit")
183 (commit commit)))
184 (file-name (string-append "roffit-" commit "-checkout"))
185 (sha256
186 (base32
187 "0z4cs92yqh22sykfgbjlyxfaifdvsd47cf1yhr0f2rgcc6l0fj1r"))))
188 (build-system gnu-build-system)
189 (arguments
190 `(#:test-target "test"
191 #:make-flags
192 (list (string-append "INSTALLDIR="
193 (assoc-ref %outputs "out") "/bin"))
194 #:phases
195 (modify-phases %standard-phases
196 (delete 'configure)
197 (add-before 'install 'pre-install
198 (lambda* (#:key outputs #:allow-other-keys)
199 (mkdir-p (string-append (assoc-ref outputs "out")
200 "/bin"))
201 #t)))))
202 (native-inputs `(("html-tree" ,perl-html-tree))) ; for test
203 (inputs
204 `(("perl" ,perl)))
205 (home-page "https://daniel.haxx.se/projects/roffit/")
206 (synopsis "Convert nroff files to HTML")
207 (description
208 "Roffit is a program that reads an nroff file and outputs an HTML file.
209 It is typically used to display man pages on a web site.")
210 (license expat))))