xref: /freebsd/share/mk/bsd.man.mk (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
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	# !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}
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	# 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}/}
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	# ${MK_MANCOMPRESS} == "no"
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	# !defined(MANFILTER)
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	# defined(MANFILTER)
207.else	# ${MK_MANCOMPRESS} == "yes"
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	# ${MK_MANCOMPRESS} == "no"
217.endif
218
219.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
220.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
221	@l=${DESTDIR}${MANDIR}${_osect}${MANSUBDIR}/${_oname}; \
222	t=${DESTDIR}${MANDIR}${_dsect}${MANSUBDIR}/${_dname}; \
223	${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
224	rm -f $${t} $${t}${MCOMPRESS_EXT}; \
225	${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}
226.endfor
227.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
228.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
229	@l=${DESTDIR}${MANDIR}${_osect}${MANSUBDIR}/${_oname}; \
230	t=${DESTDIR}${MANDIR}${_dsect}${MANSUBDIR}/${_dname}; \
231	${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
232	rm -f $${t} $${t}${MCOMPRESS_EXT}; \
233	${INSTALL_LINK} $${l}${ZEXT} $${t}${ZEXT}
234.endfor
235.endif
236.endif
237
238manlint:
239.if defined(MAN) && !empty(MAN)
240.for __page in ${MAN}
241manlint: ${__page}lint
242${__page}lint: ${__page}
243.if defined(MANFILTER)
244	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
245.else
246	${MANDOC_CMD} -Tlint ${.ALLSRC}
247.endif
248.endfor
249.endif
250