xref: /freebsd/share/mk/bsd.man.mk (revision e8e8c939350bdf3c228a411caa9660c607c27a11)
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# MANDOC_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
57MANDOC_CMD?=	mandoc -Tascii
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} | ${MANDOC_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	${MANDOC_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)
130.if ${MK_STAGING_MAN} == "yes"
131staging: stage_files
132_mansets:= ${MAN:E:O:u:M*[1-9]:@s@man$s@}
133STAGE_SETS+= ${_mansets}
134.for _page in ${MAN}
135stage_files.man${_page:T:E}: ${_page}
136STAGE_DIR.man${_page:T:E}?= ${STAGE_OBJTOP}${MANDIR}${_page:T:E}${MANSUBDIR}
137.endfor
138.if !empty(MLINKS)
139STAGE_SETS+= mlinks
140staging: stage_links
141STAGE_LINKS.mlinks:= ${MLINKS:@f@${f:S,^,${MANDIR}${f:E}${MANSUBDIR}/,}@}
142stage_links.mlinks: ${_mansets:@s@stage_files.$s@}
143.endif
144.endif
145
146CLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
147CLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
148.for __page in ${MAN}
149.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
150_manpages: ${__target}
151${__target}: ${__page}
152.if defined(MANFILTER)
153	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
154.else
155	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
156.endif
157.endfor
158.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
159.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
160_manpages: ${__target}
161${__target}: ${__page}
162.if defined(MANFILTER)
163	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
164.else
165	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
166.endif
167.endfor
168.endif
169.endfor
170.endif
171
172.endif
173
174maninstall: _maninstall
175_maninstall:
176.if defined(MAN) && !empty(MAN)
177_maninstall: ${MAN}
178.if ${MK_MANCOMPRESS} == "no"
179.if defined(MANFILTER)
180.for __page in ${MAN}
181	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
182		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
183.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
184	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
185		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
186.endif
187.endfor
188.else
189	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
190	while : ; do \
191		case $$# in \
192			0) break;; \
193			1) echo "warn: missing extension: $$1"; break;; \
194		esac; \
195		page=$$1; shift; sect=$$1; shift; \
196		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
197		${ECHO} ${MINSTALL} $${page} $${d}; \
198		${MINSTALL} $${page} $${d}; \
199	done
200.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
201.for __page in ${MAN}
202	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
203		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
204.endfor
205.endif
206.endif
207.else
208.for __page in ${MAN}
209	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
210		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}
211.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
212	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
213		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
214.endif
215.endfor
216.endif
217.endif
218
219.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
220	@set ${MLINKS:C/\.([^.]*)$/.\1 \1/}; \
221	while : ; do \
222		case $$# in \
223			0) break;; \
224			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
225		esac; \
226		name=$$1; shift; sect=$$1; shift; \
227		l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
228		name=$$1; shift; sect=$$1; shift; \
229		t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
230		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
231		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
232		${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}; \
233	done
234.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
235	@set ${MLINKS:C/\.([^.]*)$/.\1 \1/}; \
236	while : ; do \
237		case $$# in \
238			0) break;; \
239			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
240		esac; \
241		name=$$1; shift; sect=$$1; shift; \
242		l=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
243		name=$$1; shift; sect=$$1; shift; \
244		t=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
245		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
246		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
247		${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}; \
248	done
249.endif
250.endif
251
252manlint:
253.if defined(MAN) && !empty(MAN)
254.for __page in ${MAN}
255manlint: ${__page}lint
256${__page}lint: ${__page}
257.if defined(MANFILTER)
258	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
259.else
260	${MANDOC_CMD} -Tlint ${.ALLSRC}
261.endif
262.endfor
263.endif
264