xref: /freebsd/share/mk/bsd.man.mk (revision 1f4bcc459a76b7aa664f3fd557684cd0ba6da352)
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} ${TAG_ARGS} -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
66# Backwards compatibility.
67.if !defined(MAN)
68.for __sect in ${SECTIONS}
69.if defined(MAN${__sect}) && !empty(MAN${__sect})
70MAN+=	${MAN${__sect}}
71.endif
72.endfor
73.endif
74
75_manpages:
76all-man: _manpages
77
78.if ${MK_MANCOMPRESS} == "no"
79
80# Make special arrangements to filter to a temporary file at build time
81# for MK_MANCOMPRESS == no.
82.if defined(MANFILTER)
83FILTEXTENSION=		.filt
84.else
85FILTEXTENSION=
86.endif
87
88ZEXT=
89
90.if defined(MANFILTER)
91.if defined(MAN) && !empty(MAN)
92CLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
93CLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
94.for __page in ${MAN}
95.for __target in ${__page:T:S/$/${FILTEXTENSION}/g}
96_manpages: ${__target}
97${__target}: ${__page}
98	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
99.endfor
100.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
101.for __target in ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
102_manpages: ${__target}
103${__target}: ${__page}
104	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
105.endfor
106.endif
107.endfor
108.endif	# !empty(MAN)
109.else	# !defined(MANFILTER)
110.if defined(MAN) && !empty(MAN)
111CLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
112.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
113.for __page in ${MAN}
114.for __target in ${__page:T:S/$/${CATEXT}/g}
115_manpages: ${__target}
116${__target}: ${__page}
117	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
118.endfor
119.endfor
120.else
121_manpages: ${MAN}
122.endif
123.endif
124.endif	# defined(MANFILTER)
125
126.else	# ${MK_MANCOMPRESS} == "yes"
127
128ZEXT=		${MCOMPRESS_EXT}
129
130.if defined(MAN) && !empty(MAN)
131.if ${MK_STAGING_MAN} == "yes"
132STAGE_TARGETS+= stage_files
133_mansets:= ${MAN:E:O:u:M*[1-9]:@s@man$s@}
134STAGE_SETS+= ${_mansets}
135.for _page in ${MAN}
136stage_files.man${_page:T:E}: ${_page}
137STAGE_DIR.man${_page:T:E}?= ${STAGE_OBJTOP}${MANDIR}${_page:T:E}${MANSUBDIR}
138.endfor
139.if !empty(MLINKS)
140STAGE_SETS+= mlinks
141STAGE_TARGETS+= stage_links
142STAGE_LINKS.mlinks:= ${MLINKS:@f@${f:S,^,${MANDIR}${f:E}${MANSUBDIR}/,}@}
143stage_links.mlinks: ${_mansets:@s@stage_files.$s@}
144.endif
145.endif
146
147CLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
148CLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
149.for __page in ${MAN}
150.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
151_manpages: ${__target}
152${__target}: ${__page}
153.if defined(MANFILTER)
154	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
155.else
156	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
157.endif
158.endfor
159.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
160.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
161_manpages: ${__target}
162${__target}: ${__page}
163.if defined(MANFILTER)
164	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
165.else
166	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
167.endif
168.endfor
169.endif
170.endfor
171.endif
172
173.endif	# ${MK_MANCOMPRESS} == "no"
174
175maninstall: _maninstall
176_maninstall:
177.if defined(MAN) && !empty(MAN)
178_maninstall: ${MAN}
179.if ${MK_MANCOMPRESS} == "no"
180.if defined(MANFILTER)
181.for __page in ${MAN}
182	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
183		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
184.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
185	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
186		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
187.endif
188.endfor
189.else	# !defined(MANFILTER)
190	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
191	while : ; do \
192		case $$# in \
193			0) break;; \
194			1) echo "warn: missing extension: $$1"; break;; \
195		esac; \
196		page=$$1; shift; sect=$$1; shift; \
197		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
198		${ECHO} ${MINSTALL} $${page} $${d}; \
199		${MINSTALL} $${page} $${d}; \
200	done
201.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
202.for __page in ${MAN}
203	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
204		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
205.endfor
206.endif
207.endif	# defined(MANFILTER)
208.else	# ${MK_MANCOMPRESS} == "yes"
209.for __page in ${MAN}
210	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
211		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
212.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
213	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
214		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
215.endif
216.endfor
217.endif	# ${MK_MANCOMPRESS} == "no"
218.endif
219
220.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
221.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
222	@l=${DESTDIR}${MANDIR}${_osect}${MANSUBDIR}/${_oname}; \
223	t=${DESTDIR}${MANDIR}${_dsect}${MANSUBDIR}/${_dname}; \
224	${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
225	rm -f $${t} $${t}${MCOMPRESS_EXT}; \
226	${INSTALL_LINK} ${TAG_ARGS} $${l}${ZEXT} $${t}${ZEXT}
227.endfor
228.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
229.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
230	@l=${DESTDIR}${MANDIR}${_osect}${MANSUBDIR}/${_oname}; \
231	t=${DESTDIR}${MANDIR}${_dsect}${MANSUBDIR}/${_dname}; \
232	${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
233	rm -f $${t} $${t}${MCOMPRESS_EXT}; \
234	${INSTALL_LINK} ${TAG_ARGS} $${l}${ZEXT} $${t}${ZEXT}
235.endfor
236.endif
237.endif
238
239manlint:
240.if defined(MAN) && !empty(MAN)
241.for __page in ${MAN}
242manlint: ${__page}lint
243${__page}lint: ${__page}
244.if defined(MANFILTER)
245	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
246.else
247	${MANDOC_CMD} -Tlint ${.ALLSRC}
248.endif
249.endfor
250.endif
251