xref: /freebsd/share/mk/bsd.man.mk (revision 3c5ba95ad12285ad37c182a4bfc1b240ec6d18a7)
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
75all-man:
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}
95all-man: ${__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}
101all-man: ${__target}
102${__target}: ${__page}
103	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
104.endfor
105.endif
106.endfor
107.endif	# !empty(MAN)
108.else	# !defined(MANFILTER)
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}
114all-man: ${__target}
115${__target}: ${__page}
116	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
117.endfor
118.endfor
119.else
120all-man: ${MAN}
121.endif
122.endif
123.endif	# defined(MANFILTER)
124
125.else	# ${MK_MANCOMPRESS} == "yes"
126
127ZEXT=		${MCOMPRESS_EXT}
128
129.if defined(MAN) && !empty(MAN)
130.if ${MK_STAGING_MAN} == "yes"
131STAGE_TARGETS+= 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
140STAGE_TARGETS+= 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}/}
150all-man: ${__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}/}
160all-man: ${__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	# ${MK_MANCOMPRESS} == "no"
173
174.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
175.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
176_MANLINKS+=	${MANDIR}${_osect}${MANSUBDIR}/${_oname} \
177		${MANDIR}${_dsect}${MANSUBDIR}/${_dname}
178.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
179_MANLINKS+=	${CATDIR}${_osect}${MANSUBDIR}/${_oname} \
180		${CATDIR}${_dsect}${MANSUBDIR}/${_dname}
181.endif
182.endfor
183.endif
184
185maninstall:
186.if defined(MAN) && !empty(MAN)
187maninstall: ${MAN}
188.if ${MK_MANCOMPRESS} == "no"
189.if defined(MANFILTER)
190.for __page in ${MAN}
191	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
192		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
193.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
194	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
195		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
196.endif
197.endfor
198.else	# !defined(MANFILTER)
199	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
200	while : ; do \
201		case $$# in \
202			0) break;; \
203			1) echo "warn: missing extension: $$1"; break;; \
204		esac; \
205		page=$$1; shift; sect=$$1; shift; \
206		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
207		${ECHO} ${MINSTALL} $${page} $${d}; \
208		${MINSTALL} $${page} $${d}; \
209	done
210.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
211.for __page in ${MAN}
212	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
213		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
214.endfor
215.endif
216.endif	# defined(MANFILTER)
217.else	# ${MK_MANCOMPRESS} == "yes"
218.for __page in ${MAN}
219	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
220		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
221.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
222	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
223		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
224.endif
225.endfor
226.endif	# ${MK_MANCOMPRESS} == "no"
227.endif
228.for l t in ${_MANLINKS}
229	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
230	    ${INSTALL_MANLINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
231.endfor
232
233manlint:
234.if defined(MAN) && !empty(MAN)
235.for __page in ${MAN}
236manlint: ${__page}lint
237${__page}lint: ${__page}
238.if defined(MANFILTER)
239	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
240.else
241	${MANDOC_CMD} -Tlint ${.ALLSRC}
242.endif
243.endfor
244.endif
245