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