No empty .Rs/.Re
[netbsd-mini2440.git] / share / mk / bsd.man.mk
blob697a304caf2605f06f8af169a2003930bcc2ca16
1 # $NetBSD: bsd.man.mk,v 1.101 2009/10/23 22:14:37 joerg Exp $
2 # @(#)bsd.man.mk 8.1 (Berkeley) 6/8/93
4 .include <bsd.init.mk>
6 ##### Basic targets
7 .PHONY: catinstall maninstall catpages manpages catlinks manlinks
8 .PHONY: htmlinstall htmlpages htmllinks
9 .if ${MKMANDOC} == "yes"
10 .PHONY: lintmanpages
11 .endif
12 realinstall: ${MANINSTALL}
14 ##### Default values
15 .if ${USETOOLS} == "yes"
16 TMACDEPDIR?= ${TOOLDIR}/share/groff/tmac
17 .else
18 TMACDEPDIR?= /usr/share/tmac
19 .endif
21 HTMLDIR?= ${DESTDIR}${MANDIR}
22 CATDEPS?= ${TMACDEPDIR}/andoc.tmac \
23 ${TMACDEPDIR}/doc.tmac \
24 ${TMACDEPDIR}/mdoc/doc-common \
25 ${TMACDEPDIR}/mdoc/doc-ditroff \
26 ${TMACDEPDIR}/mdoc/doc-nroff \
27 ${TMACDEPDIR}/mdoc/doc-syms
28 HTMLDEPS?= ${TMACDEPDIR}/doc2html.tmac
29 MANTARGET?= cat
31 MAN?=
32 MLINKS?=
33 _MNUMBERS= 1 2 3 4 5 6 7 8 9
34 .SUFFIXES: ${_MNUMBERS:@N@.$N@}
36 .if ${MKMANZ} == "no"
37 MANCOMPRESS?=
38 MANSUFFIX?=
39 .else
40 MANCOMPRESS?= gzip -ncf
41 MANSUFFIX?= .gz
42 .endif
44 # make MANCOMPRESS a filter, so it can be inserted on an as-needed basis
45 .if !empty(MANCOMPRESS)
46 MANCOMPRESS:= | ${MANCOMPRESS}
47 .endif
49 __installpage: .USE
50 @cmp -s ${.ALLSRC} ${.TARGET} > /dev/null 2>&1 || \
51 (${_MKSHMSG_INSTALL} ${.TARGET}; \
52 ${_MKSHECHO} "${INSTALL_FILE} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
53 ${.ALLSRC} ${.TARGET}" && \
54 ${INSTALL_FILE} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
55 ${.ALLSRC} ${.TARGET})
57 # XXX consider including bsd.links.mk and using __linkinstall instead
58 __linkinstallpage: .USE
59 ${_MKSHMSG_INSTALL} ${.TARGET}; \
60 ${_MKSHECHO} "${INSTALL_LINK} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
61 ${.ALLSRC} ${.TARGET}" && \
62 ${INSTALL_LINK} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
63 ${.ALLSRC} ${.TARGET}
65 ##### Build and install rules (source form pages)
67 .if ${MKMAN} != "no"
68 maninstall: manpages manlinks
69 manpages:: # ensure target exists
70 MANPAGES= ${MAN:C/.$/&${MANSUFFIX}/}
72 realall: ${MANPAGES}
73 .if !empty(MANSUFFIX)
74 .NOPATH: ${MANPAGES}
75 .SUFFIXES: ${_MNUMBERS:@N@.$N${MANSUFFIX}@}
77 ${_MNUMBERS:@N@.$N.$N${MANSUFFIX}@}: # build rule
78 ${_MKTARGET_FORMAT}
79 cat ${.IMPSRC} ${MANCOMPRESS} > ${.TARGET}.tmp && mv ${.TARGET}.tmp ${.TARGET}
80 .endif # !empty(MANSUFFIX)
82 .for F in ${MANPAGES:S/${MANSUFFIX}$//:O:u}
83 _F:= ${DESTDIR}${MANDIR}/man${F:T:E}${MANSUBDIR}/${F}${MANSUFFIX}
85 .if ${MKUPDATE} == "no"
86 ${_F}! ${F}${MANSUFFIX} __installpage # install rule
87 .if !defined(BUILD) && !make(all) && !make(${F})
88 ${_F}! .MADE # no build at install
89 .endif
90 .else
91 ${_F}: ${F}${MANSUFFIX} __installpage # install rule
92 .if !defined(BUILD) && !make(all) && !make(${F})
93 ${_F}: .MADE # no build at install
94 .endif
95 .endif
97 manpages:: ${_F}
98 .PRECIOUS: ${_F} # keep if install fails
99 .endfor
101 manlinks:: # link install
103 .for _src _dst in ${MLINKS}
104 _l:=${DESTDIR}${MANDIR}/man${_src:T:E}${MANSUBDIR}/${_src}${MANSUFFIX}
105 _t:=${DESTDIR}${MANDIR}/man${_dst:T:E}${MANSUBDIR}/${_dst}${MANSUFFIX}
107 # Handle case conflicts carefully, when _dst occurs
108 # more than once after case flattening
109 .if ${MKUPDATE} == "no" || ${MLINKS:tl:M${_dst:tl:Q}:[\#]} > 1
110 ${_t}! ${_l} __linkinstallpage
111 .else
112 ${_t}: ${_l} __linkinstallpage
113 .endif
115 manlinks:: ${_t}
116 .PRECIOUS: ${_t}
117 .endfor
118 .endif # ${MKMAN} != "no"
120 ##### Build and install rules (plaintext pages)
122 .if (${MKCATPAGES} != "no") && (${MKMAN} != "no")
123 catinstall: catpages catlinks
124 catpages:: # ensure target exists
125 CATPAGES= ${MAN:C/\.([1-9])$/.cat\1${MANSUFFIX}/}
127 realall: ${CATPAGES}
128 .NOPATH: ${CATPAGES}
129 .SUFFIXES: ${_MNUMBERS:@N@.cat$N${MANSUFFIX}@}
130 .MADE: ${CATDEPS}
132 ${_MNUMBERS:@N@.$N.cat$N${MANSUFFIX}@}: ${CATDEPS} # build rule
133 ${_MKTARGET_FORMAT}
134 .if defined(USETBL)
135 ${TOOL_TBL} ${.IMPSRC} | ${TOOL_ROFF_ASCII} -mandoc ${MANCOMPRESS} \
136 > ${.TARGET}.tmp && mv ${.TARGET}.tmp ${.TARGET}
137 .elif ${MKMANDOC} == yes && !defined(NOMANDOC)
138 if test ""${NOMANDOC.${.IMPSRC:T}:tl:Q} != "yes"; then \
139 ${TOOL_MANDOC_ASCII} ${.IMPSRC} ${MANCOMPRESS} \
140 > ${.TARGET}.tmp && mv ${.TARGET}.tmp ${.TARGET}; \
141 else \
142 ${TOOL_ROFF_ASCII} -mandoc ${.IMPSRC} ${MANCOMPRESS} \
143 > ${.TARGET}.tmp && mv ${.TARGET}.tmp ${.TARGET}; \
145 .else
146 ${TOOL_ROFF_ASCII} -mandoc ${.IMPSRC} ${MANCOMPRESS} \
147 > ${.TARGET}.tmp && mv ${.TARGET}.tmp ${.TARGET}
148 .endif
150 .for F in ${CATPAGES:S/${MANSUFFIX}$//:O:u}
151 _F:= ${DESTDIR}${MANDIR}/${F:T:E}${MANSUBDIR}/${F:R}.0${MANSUFFIX}
153 .if ${MKUPDATE} == "no"
154 ${_F}! ${F}${MANSUFFIX} __installpage # install rule
155 .if !defined(BUILD) && !make(all) && !make(${F})
156 ${_F}! .MADE # no build at install
157 .endif
158 .else
159 ${_F}: ${F}${MANSUFFIX} __installpage # install rule
160 .if !defined(BUILD) && !make(all) && !make(${F})
161 ${_F}: .MADE # no build at install
162 .endif
163 .endif
165 catpages:: ${_F}
166 .PRECIOUS: ${_F} # keep if install fails
167 .endfor
169 catlinks:: # link install
171 .for _src _dst in ${MLINKS}
172 _l:=${DESTDIR}${MANDIR}/cat${_src:T:E}${MANSUBDIR}/${_src:R}.0${MANSUFFIX}
173 _t:=${DESTDIR}${MANDIR}/cat${_dst:T:E}${MANSUBDIR}/${_dst:R}.0${MANSUFFIX}
175 # Handle case conflicts carefully, when _dst occurs
176 # more than once after case flattening
177 .if ${MKUPDATE} == "no" || ${MLINKS:tl:M${_dst:tl:Q}:[\#]} > 1
178 ${_t}! ${_l} __linkinstallpage
179 .else
180 ${_t}: ${_l} __linkinstallpage
181 .endif
183 catlinks:: ${_t}
184 .PRECIOUS: ${_t}
185 .endfor
186 .endif # (${MKCATPAGES} != "no") && (${MKMAN} != "no")
188 ##### Build and install rules (HTML pages)
190 .if (${MKHTML} != "no") && (${MKMAN} != "no") # {
191 htmlinstall: htmlpages htmllinks
192 htmlpages:: # ensure target exists
193 HTMLPAGES= ${MAN:C/\.([1-9])$/.html\1/}
195 realall: ${HTMLPAGES}
196 .NOPATH: ${HTMLPAGES}
197 .SUFFIXES: ${_MNUMBERS:@N@.html$N@}
198 .MADE: ${HTMLDEPS}
200 ${_MNUMBERS:@N@.$N.html$N@}: ${HTMLDEPS} # build rule
201 ${_MKTARGET_FORMAT}
202 .if ${MKMANDOC} == "yes" && !defined(NOMANDOC)
203 if test ""${NOMANDOC.${.IMPSRC:T}:tl:Q} != "yes"; then \
204 ${TOOL_MANDOC_HTML} ${.IMPSRC} > ${.TARGET}.tmp && \
205 mv ${.TARGET}.tmp ${.TARGET}; \
206 else \
207 ${TOOL_ROFF_HTML} ${.IMPSRC} > ${.TARGET}.tmp && \
208 mv ${.TARGET}.tmp ${.TARGET}; \
210 .else
211 ${TOOL_ROFF_HTML} ${.IMPSRC} > ${.TARGET}.tmp && \
212 mv ${.TARGET}.tmp ${.TARGET}
213 .endif
215 .for F in ${HTMLPAGES:O:u}
216 # construct installed path
217 _F:= ${HTMLDIR}/${F:T:E}${MANSUBDIR}/${F:R:S-/index$-/x&-}.html
219 .if ${MKUPDATE} == "no"
220 ${_F}! ${F} __installpage # install rule
221 .if !defined(BUILD) && !make(all) && !make(${F})
222 ${_F}! .MADE # no build at install
223 .endif
224 .else
225 ${_F}: ${F} __installpage # install rule
226 .if !defined(BUILD) && !make(all) && !make(${F})
227 ${_F}: .MADE # no build at install
228 .endif
229 .endif
231 htmlpages:: ${_F}
232 .PRECIOUS: ${_F} # keep if install fails
233 .endfor
235 htmllinks:: # link install
237 .for _src _dst in ${MLINKS}
238 _l:=${HTMLDIR}/html${_src:T:E}${MANSUBDIR}/${_src:R:S-/index$-/x&-}.html
239 _t:=${HTMLDIR}/html${_dst:T:E}${MANSUBDIR}/${_dst:R:S-/index$-/x&-}.html
241 # Handle case conflicts carefully, when _dst occurs
242 # more than once after case flattening
243 .if ${MKUPDATE} == "no" || ${MLINKS:tl:M${_dst:tl:Q}:[\#]} > 1
244 ${_t}! ${_l} __linkinstallpage
245 .else
246 ${_t}: ${_l} __linkinstallpage
247 .endif
249 htmllinks:: ${_t}
250 .PRECIOUS: ${_t}
251 .endfor
253 .endif # }
255 ##### Clean rules
256 .undef _F
258 cleandir: cleanman
259 .if !empty(CLEANFILES)
260 rm -f ${CLEANFILES}
261 .endif
263 cleanman: .PHONY
264 .if !empty(MAN) && (${MKMAN} != "no")
265 .if (${MKCATPAGES} != "no")
266 rm -f ${CATPAGES}
267 .endif
268 .if !empty(MANSUFFIX)
269 rm -f ${MANPAGES} ${CATPAGES:S/${MANSUFFIX}$//}
270 .endif
271 .if ${MKHTML} != "no"
272 rm -f ${HTMLPAGES}
273 .endif
274 .endif
275 # (XXX ${CATPAGES:S...} cleans up old .catN files where .catN.gz now used)
277 .if ${MKMANDOC} == "yes" && !empty(MANPAGES)
278 lintmanpages: ${MANPAGES}
279 ${TOOL_MANDOC_LINT} -Tlint -fstrict ${.ALLSRC}
280 .endif
282 ##### Pull in related .mk logic
283 .include <bsd.obj.mk>
284 .include <bsd.files.mk>
285 .include <bsd.sys.mk>
287 ${TARGETS} catinstall maninstall htmlinstall: # ensure existence