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