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