bsd.man.mk: change `mandiff' from groff to nroff
[dragonfly.git] / share / mk / bsd.man.mk
1 # $FreeBSD: src/share/mk/bsd.man.mk,v 1.31.2.11 2002/12/19 13:48:33 ru Exp $
2 #
3 # The include file <bsd.man.mk> handles installing manual pages and 
4 # their links.
5 #
6 #
7 # +++ variables +++
8 #
9 # DESTDIR       Change the tree where the man pages gets installed. [not set]
10 #
11 # MANDIR        Base path for manual installation. [${SHAREDIR}/man/man]
12 #
13 # MANOWN        Manual owner. [${SHAREOWN}]
14 #
15 # MANGRP        Manual group. [${SHAREGRP}]
16 #
17 # MANMODE       Manual mode. [${NOBINMODE}]
18 #
19 # MANSUBDIR     Subdirectory under the manual page section, i.e. "/i386"
20 #               or "/tahoe" for machine specific manual pages.
21 #
22 # MAN           The manual pages to be installed. For sections see
23 #               variable ${SECTIONS}
24 #
25 # MCOMPRESS_CMD Program to compress man pages. Output is to
26 #               stdout. [${COMPRESS_CMD}]
27 #
28 # MLINKS        List of manual page links (using a suffix). The
29 #               linked-to file must come first, the linked file 
30 #               second, and there may be multiple pairs. The files 
31 #               are hard-linked.
32 #
33 # NOMANCOMPRESS If you do not want unformatted manual pages to be 
34 #               compressed when they are installed. [not set]
35 #
36 # NOMLINKS      If you do not want install manual page links. [not set]
37 #
38 # MANFILTER     command to pipe the raw man page through before compressing
39 #               or installing.  Can be used to do sed substitution.
40 #
41 # MANBUILDCAT   create preformatted manual pages in addition to normal
42 #               pages. [not set]
43 #
44 # MROFF_CMD     command and flags to create preformatted pages
45 #
46 # +++ targets +++
47 #
48 #       maninstall:
49 #               Install the manual pages and their links.
50 #
51
52 .if !target(__<bsd.init.mk>__)
53 .error bsd.man.mk cannot be included directly.
54 .endif
55
56 _MANINSTALLFLAGS:= ${MANINSTALLFLAGS}
57
58 MINSTALL?=      ${INSTALL} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
59                 ${_MANINSTALLFLAGS}
60
61 CATDIR=         ${MANDIR:H:S/$/\/cat/}
62 CATEXT=         .cat
63 MROFF_CMD?=     groff -Tascii -mtty-char -man -t
64
65 MCOMPRESS_CMD?= ${COMPRESS_CMD}
66 MCOMPRESS_EXT?= ${COMPRESS_EXT}
67
68 SECTIONS=       1 2 3 4 5 6 7 8 9
69 .SUFFIXES:      ${SECTIONS:S/^/./g}
70
71 # Backwards compatibility.
72 .if !defined(MAN)
73 .for sect in ${SECTIONS}
74 .if defined(MAN${sect}) && !empty(MAN${sect})
75 MAN+=   ${MAN${sect}}
76 .endif
77 .endfor
78 .endif
79
80 _manpages:
81 all-man: _manpages
82
83 .if defined(NOMANCOMPRESS)
84
85 # Make special arrangements to filter to a temporary file at build time
86 # for NOMANCOMPRESS.
87 .if defined(MANFILTER)
88 FILTEXTENSION=          .filt
89 .else
90 FILTEXTENSION=
91 .endif
92
93 ZEXT=
94
95 .if defined(MANFILTER)
96 .if defined(MAN) && !empty(MAN)
97 CLEANFILES+=    ${MAN:T:S/$/${FILTEXTENSION}/g}
98 CLEANFILES+=    ${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
99 .for page in ${MAN}
100 .for target in ${page:T:S/$/${FILTEXTENSION}/g}
101 _manpages: ${target}
102 ${target}: ${page}
103         ${MANFILTER} < ${.ALLSRC} > ${.TARGET}
104 .endfor
105 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
106 .for target in ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
107 _manpages: ${target}
108 ${target}: ${page}
109         ${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} > ${.TARGET}
110 .endfor
111 .endif
112 .endfor
113 .endif
114 .else
115 .if defined(MAN) && !empty(MAN)
116 CLEANFILES+=    ${MAN:T:S/$/${CATEXT}/g}
117 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
118 .for page in ${MAN}
119 .for target in ${page:T:S/$/${CATEXT}/g}
120 _manpages: ${target}
121 ${target}: ${page}
122         ${MROFF_CMD} ${.ALLSRC} > ${.TARGET}
123 .endfor
124 .endfor
125 .else
126 _manpages: ${MAN}
127 .endif
128 .endif
129 .endif
130
131 .else
132
133 ZEXT=           ${MCOMPRESS_EXT}
134
135 .if defined(MAN) && !empty(MAN)
136 CLEANFILES+=    ${MAN:T:S/$/${MCOMPRESS_EXT}/g}
137 CLEANFILES+=    ${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
138 .for page in ${MAN}
139 .for target in ${page:T:S/$/${MCOMPRESS_EXT}/}
140 _manpages: ${target}
141 ${target}: ${page}
142 .if defined(MANFILTER)
143         ${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
144 .else
145         ${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
146 .endif
147 .endfor
148 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
149 .for target in ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
150 _manpages: ${target}
151 ${target}: ${page}
152 .if defined(MANFILTER)
153         ${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
154 .else
155         ${MROFF_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
156 .endif
157 .endfor
158 .endif
159 .endfor
160 .endif
161
162 .endif
163
164 maninstall: _maninstall
165 _maninstall:
166 .if defined(MAN) && !empty(MAN)
167 _maninstall: ${MAN}
168 .if defined(NOMANCOMPRESS)
169 .if defined(MANFILTER)
170 .for page in ${MAN}
171         ${MINSTALL} ${page:T:S/$/${FILTEXTENSION}/g} \
172                 ${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}/${page}
173 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
174         ${MINSTALL} ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
175                 ${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page}
176 .endif
177 .endfor
178 .else
179         @set `echo ${.ALLSRC} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
180         while : ; do \
181                 case $$# in \
182                         0) break;; \
183                         1) echo "warn: missing extension: $$1"; break;; \
184                 esac; \
185                 page=$$1; shift; sect=$$1; shift; \
186                 d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
187                 ${ECHO} ${MINSTALL} $${page} $${d}; \
188                 ${MINSTALL} $${page} $${d}; \
189         done
190 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
191 .for page in ${MAN}
192         ${MINSTALL} ${page:T:S/$/${CATEXT}/} \
193                 ${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T}
194 .endfor
195 .endif
196 .endif
197 .else
198 .for page in ${MAN}
199         ${MINSTALL} ${page:T:S/$/${MCOMPRESS_EXT}/g} \
200                 ${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}
201 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
202         ${MINSTALL} ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
203                 ${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T:S/$/${MCOMPRESS_EXT}/}
204 .endif
205 .endfor
206 .endif
207 .endif
208
209 .if !defined(NOMLINKS) && defined(MLINKS) && !empty(MLINKS)
210         @set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
211         while : ; do \
212                 case $$# in \
213                         0) break;; \
214                         [123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
215                 esac; \
216                 name=$$1; shift; sect=$$1; shift; \
217                 l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
218                 name=$$1; shift; sect=$$1; shift; \
219                 t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
220                 ${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
221                 rm -f $${t} $${t}${MCOMPRESS_EXT}; \
222                 ${LN} $${l}${ZEXT} $${t}${ZEXT}; \
223         done
224 .if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
225         @set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
226         while : ; do \
227                 case $$# in \
228                         0) break;; \
229                         [123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
230                 esac; \
231                 name=$$1; shift; sect=$$1; shift; \
232                 l=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
233                 name=$$1; shift; sect=$$1; shift; \
234                 t=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
235                 ${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
236                 rm -f $${t} $${t}${MCOMPRESS_EXT}; \
237                 ${LN} $${l}${ZEXT} $${t}${ZEXT}; \
238         done
239 .endif
240 .endif
241
242 manlint:
243 mandiff:
244 .if defined(MAN) && !empty(MAN)
245 .for page in ${MAN}
246 manlint: ${page}lint
247 mandiff: ${page}diff
248 ${page}lint: ${page}
249 .if defined(MANFILTER)
250         @${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} -ww -z
251         @-${MANFILTER} < ${.ALLSRC} | mandoc -Tlint
252 .else
253         @${MROFF_CMD} -ww -z ${.ALLSRC}
254         @-mandoc -Tlint ${.ALLSRC}
255 .endif
256 ${page}.out.groff: ${page}
257         @-nroff -man -t ${.ALLSRC} 2>&1 > ${.TARGET}
258 ${page}.out.mandoc: ${page}
259         @-mandoc -Werror ${.ALLSRC} 2>&1 > ${.TARGET}
260 ${page}diff: ${page}.out.groff ${page}.out.mandoc
261         @-diff -au ${.ALLSRC}
262         @rm ${.ALLSRC}
263 .endfor
264 .endif