1{
2 lib,
3 stdenv,
4 fetchurl,
5 perl,
6 enableGhostscript ? false,
7 ghostscript,
8 gawk,
9 libX11,
10 libXaw,
11 libXt,
12 libXmu, # for postscript and html output
13 enableHtml ? false,
14 psutils,
15 netpbm, # for html output
16 enableIconv ? false,
17 iconv,
18 enableLibuchardet ? false,
19 libuchardet, # for detecting input file encoding in preconv(1)
20 buildPackages,
21 autoreconfHook,
22 pkg-config,
23 texinfo,
24 bison,
25 bashNonInteractive,
26}:
27
28stdenv.mkDerivation rec {
29 pname = "groff";
30 version = "1.23.0";
31
32 src = fetchurl {
33 url = "mirror://gnu/groff/${pname}-${version}.tar.gz";
34 hash = "sha256-a5dX9ZK3UYtJAutq9+VFcL3Mujeocf3bLTCuOGNRHBM=";
35 };
36
37 outputs = [
38 "out"
39 "man"
40 "doc"
41 "info"
42 "perl"
43 ];
44
45 enableParallelBuilding = true;
46
47 postPatch = ''
48 # BASH_PROG gets replaced with a path to the build bash which doesn't get automatically patched by patchShebangs
49 substituteInPlace contrib/gdiffmk/gdiffmk.sh \
50 --replace "@BASH_PROG@" "/bin/sh"
51 ''
52 + lib.optionalString enableHtml ''
53 substituteInPlace src/preproc/html/pre-html.cpp \
54 --replace "psselect" "${psutils}/bin/psselect" \
55 --replace "pnmcut" "${lib.getBin netpbm}/bin/pnmcut" \
56 --replace "pnmcrop" "${lib.getBin netpbm}/bin/pnmcrop" \
57 --replace "pnmtopng" "${lib.getBin netpbm}/bin/pnmtopng"
58 substituteInPlace tmac/www.tmac.in \
59 --replace "pnmcrop" "${lib.getBin netpbm}/bin/pnmcrop" \
60 --replace "pngtopnm" "${lib.getBin netpbm}/bin/pngtopnm" \
61 --replace "@PNMTOPS_NOSETPAGE@" "${lib.getBin netpbm}/bin/pnmtops -nosetpage"
62 ''
63 + lib.optionalString (enableGhostscript || enableHtml) ''
64 substituteInPlace contrib/pdfmark/pdfroff.sh \
65 --replace '$GROFF_GHOSTSCRIPT_INTERPRETER' "${lib.getBin ghostscript}/bin/gs" \
66 --replace '$GROFF_AWK_INTERPRETER' "${lib.getBin gawk}/bin/gawk"
67 '';
68
69 strictDeps = true;
70 nativeBuildInputs = [
71 autoreconfHook
72 pkg-config
73 texinfo
74 ]
75 # Required due to the patch that changes .ypp files.
76 ++ lib.optional (stdenv.cc.isClang && lib.versionAtLeast stdenv.cc.version "9") bison;
77 buildInputs = [
78 perl
79 bashNonInteractive
80 ]
81 ++ lib.optionals enableGhostscript [
82 ghostscript
83 gawk
84 libX11
85 libXaw
86 libXt
87 libXmu
88 ]
89 ++ lib.optionals enableHtml [
90 psutils
91 netpbm
92 ]
93 ++ lib.optionals enableIconv [ iconv ]
94 ++ lib.optionals enableLibuchardet [ libuchardet ];
95
96 # Builds running without a chroot environment may detect the presence
97 # of /usr/X11 in the host system, leading to an impure build of the
98 # package. To avoid this issue, X11 support is explicitly disabled.
99 configureFlags =
100 lib.optionals (!enableGhostscript) [
101 "--without-x"
102 ]
103 ++ [
104 "ac_cv_path_PERL=${buildPackages.perl}/bin/perl"
105 ]
106 ++ lib.optionals enableGhostscript [
107 "--with-gs=${lib.getBin ghostscript}/bin/gs"
108 "--with-awk=${lib.getBin gawk}/bin/gawk"
109 "--with-appresdir=${placeholder "out"}/lib/X11/app-defaults"
110 ]
111 ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
112 "gl_cv_func_signbit=yes"
113 ];
114
115 makeFlags = lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
116 # Trick to get the build system find the proper 'native' groff
117 # http://www.mail-archive.com/bug-groff@gnu.org/msg01335.html
118 "GROFF_BIN_PATH=${buildPackages.groff}/bin"
119 "GROFFBIN=${buildPackages.groff}/bin/groff"
120 ];
121
122 doCheck = true;
123
124 postInstall = ''
125 for f in 'man.local' 'mdoc.local'; do
126 cat '${./site.tmac}' >>"$out/share/groff/site-tmac/$f"
127 done
128
129 moveToOutput bin/gropdf $perl
130 moveToOutput bin/pdfmom $perl
131 moveToOutput bin/roff2text $perl
132 moveToOutput bin/roff2pdf $perl
133 moveToOutput bin/roff2ps $perl
134 moveToOutput bin/roff2dvi $perl
135 moveToOutput bin/roff2ps $perl
136 moveToOutput bin/roff2html $perl
137 moveToOutput bin/glilypond $perl
138 moveToOutput bin/mmroff $perl
139 moveToOutput bin/roff2x $perl
140 moveToOutput bin/afmtodit $perl
141 moveToOutput bin/gperl $perl
142 moveToOutput bin/chem $perl
143
144 moveToOutput bin/gpinyin $perl
145 moveToOutput lib/groff/gpinyin $perl
146 substituteInPlace $perl/bin/gpinyin \
147 --replace $out/lib/groff/gpinyin $perl/lib/groff/gpinyin
148
149 moveToOutput bin/grog $perl
150 moveToOutput lib/groff/grog $perl
151 substituteInPlace $perl/bin/grog \
152 --replace $out/lib/groff/grog $perl/lib/groff/grog
153
154 find $perl/ -type f -print0 | xargs --null sed -i 's|${buildPackages.perl}|${perl}|'
155 '';
156
157 meta = with lib; {
158 homepage = "https://www.gnu.org/software/groff/";
159 description = "GNU Troff, a typesetting package that reads plain text and produces formatted output";
160 license = licenses.gpl3Plus;
161 platforms = platforms.all;
162 maintainers = with maintainers; [ pSub ];
163
164 longDescription = ''
165 groff is the GNU implementation of troff, a document formatting
166 system. Included in this release are implementations of troff,
167 pic, eqn, tbl, grn, refer, -man, -mdoc, -mom, and -ms macros,
168 and drivers for PostScript, TeX dvi format, HP LaserJet 4
169 printers, Canon CAPSL printers, HTML and XHTML format (beta
170 status), and typewriter-like devices. Also included is a
171 modified version of the Berkeley -me macros, the enhanced
172 version gxditview of the X11 xditview previewer, and an
173 implementation of the -mm macros.
174 '';
175
176 outputsToInstall = [
177 "out"
178 "perl"
179 ];
180 };
181}