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