xref: /freebsd/share/mk/bsd.man.mk (revision b1f9167f94059fd55c630891d359bcff987bd7eb)
1# $FreeBSD$
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# NO_MLINKS	If you do not want install manual page links. [not set]
34#
35# MANFILTER	command to pipe the raw man page through before compressing
36#		or installing.  Can be used to do sed substitution.
37#
38# MANBUILDCAT	create preformatted manual pages in addition to normal
39#		pages. [not set]
40#
41# MROFF_CMD	command and flags to create preformatted pages
42#
43# +++ targets +++
44#
45#	maninstall:
46#		Install the manual pages and their links.
47#
48
49.if !target(__<bsd.init.mk>__)
50.error bsd.man.mk cannot be included directly.
51.endif
52
53MINSTALL?=	${INSTALL} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
54
55CATDIR=		${MANDIR:H:S/$/\/cat/}
56CATEXT=		.cat
57MROFF_CMD?=	groff -Tascii -mtty-char -man -t
58
59MCOMPRESS_CMD?=	${COMPRESS_CMD}
60MCOMPRESS_EXT?=	${COMPRESS_EXT}
61
62SECTIONS=	1 2 3 4 5 6 7 8 9
63.SUFFIXES:	${SECTIONS:S/^/./g}
64
65# Backwards compatibility.
66.if !defined(MAN)
67.for __sect in ${SECTIONS}
68.if defined(MAN${__sect}) && !empty(MAN${__sect})
69MAN+=	${MAN${__sect}}
70.endif
71.endfor
72.endif
73
74_manpages:
75all-man: _manpages
76
77.if ${MK_MANCOMPRESS} == "no"
78
79# Make special arrangements to filter to a temporary file at build time
80# for MK_MANCOMPRESS == no.
81.if defined(MANFILTER)
82FILTEXTENSION=		.filt
83.else
84FILTEXTENSION=
85.endif
86
87ZEXT=
88
89.if defined(MANFILTER)
90.if defined(MAN) && !empty(MAN)
91CLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
92CLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
93.for __page in ${MAN}
94.for __target in ${__page:T:S/$/${FILTEXTENSION}/g}
95_manpages: ${__target}
96${__target}: ${__page}
97	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
98.endfor
99.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
100.for __target in ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
101_manpages: ${__target}
102${__target}: ${__page}
103	${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} > ${.TARGET}
104.endfor
105.endif
106.endfor
107.endif
108.else
109.if defined(MAN) && !empty(MAN)
110CLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
111.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
112.for __page in ${MAN}
113.for __target in ${__page:T:S/$/${CATEXT}/g}
114_manpages: ${__target}
115${__target}: ${__page}
116	${MROFF_CMD} ${.ALLSRC} > ${.TARGET}
117.endfor
118.endfor
119.else
120_manpages: ${MAN}
121.endif
122.endif
123.endif
124
125.else
126
127ZEXT=		${MCOMPRESS_EXT}
128
129.if defined(MAN) && !empty(MAN)
130CLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
131CLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
132.for __page in ${MAN}
133.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
134_manpages: ${__target}
135${__target}: ${__page}
136.if defined(MANFILTER)
137	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
138.else
139	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
140.endif
141.endfor
142.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
143.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
144_manpages: ${__target}
145${__target}: ${__page}
146.if defined(MANFILTER)
147	${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
148.else
149	${MROFF_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
150.endif
151.endfor
152.endif
153.endfor
154.endif
155
156.endif
157
158maninstall: _maninstall
159_maninstall:
160.if defined(MAN) && !empty(MAN)
161_maninstall: ${MAN}
162.if ${MK_MANCOMPRESS} == "no"
163.if defined(MANFILTER)
164.for __page in ${MAN}
165	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
166		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
167.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
168	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
169		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
170.endif
171.endfor
172.else
173	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
174	while : ; do \
175		case $$# in \
176			0) break;; \
177			1) echo "warn: missing extension: $$1"; break;; \
178		esac; \
179		page=$$1; shift; sect=$$1; shift; \
180		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
181		${ECHO} ${MINSTALL} $${page} $${d}; \
182		${MINSTALL} $${page} $${d}; \
183	done
184.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
185.for __page in ${MAN}
186	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
187		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
188.endfor
189.endif
190.endif
191.else
192.for __page in ${MAN}
193	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
194		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}
195.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
196	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
197		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
198.endif
199.endfor
200.endif
201.endif
202
203.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
204	@set ${MLINKS:C/\.([^.]*)$/.\1 \1/}; \
205	while : ; do \
206		case $$# in \
207			0) break;; \
208			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
209		esac; \
210		name=$$1; shift; sect=$$1; shift; \
211		l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
212		name=$$1; shift; sect=$$1; shift; \
213		t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
214		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
215		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
216		${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}; \
217	done
218.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
219	@set ${MLINKS:C/\.([^.]*)$/.\1 \1/}; \
220	while : ; do \
221		case $$# in \
222			0) break;; \
223			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
224		esac; \
225		name=$$1; shift; sect=$$1; shift; \
226		l=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
227		name=$$1; shift; sect=$$1; shift; \
228		t=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
229		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
230		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
231		${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}; \
232	done
233.endif
234.endif
235
236manlint:
237.if defined(MAN) && !empty(MAN)
238.for __page in ${MAN}
239manlint: ${__page}lint
240${__page}lint: ${__page}
241.if defined(MANFILTER)
242	${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} -ww -z
243.else
244	${MROFF_CMD} -ww -z ${.ALLSRC}
245.endif
246.endfor
247.endif
248