xref: /freebsd/share/mk/bsd.man.mk (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1#
2# The include file <bsd.man.mk> handles installing manual pages and
3# their links.
4#
5#
6# +++ variables +++
7#
8# DESTDIR	Change the tree where the man pages gets installed. [not set]
9#
10# MANDIR	Base path for manual installation. [${SHAREDIR}/man/man]
11#
12# MANOWN	Manual owner. [${SHAREOWN}]
13#
14# MANGRP	Manual group. [${SHAREGRP}]
15#
16# MANMODE	Manual mode. [${NOBINMODE}]
17#
18# MANSUBDIR	Subdirectory under the manual page section, i.e. "/i386"
19#		or "/tahoe" for machine specific manual pages.
20#
21# MAN		The manual pages to be installed. For sections see
22#		variable ${SECTIONS}
23#
24# MCOMPRESS_CMD	Program to compress man pages. Output is to
25#		stdout. [${COMPRESS_CMD}]
26#
27# MLINKS	List of manual page links (using a suffix). The
28#		linked-to file must come first, the linked file
29#		second, and there may be multiple pairs. The files
30#		are hard-linked.
31#
32# NO_MLINKS	If you do not want install manual page links. [not set]
33#
34# MANFILTER	command to pipe the raw man page through before compressing
35#		or installing.  Can be used to do sed substitution.
36#
37# MANBUILDCAT	create preformatted manual pages in addition to normal
38#		pages. [not set]
39#
40# MANDOC_CMD	command and flags to create preformatted pages
41#
42# +++ targets +++
43#
44#	maninstall:
45#		Install the manual pages and their links.
46#
47
48.if !target(__<bsd.init.mk>__)
49.error bsd.man.mk cannot be included directly.
50.endif
51
52.if ${MK_MANSPLITPKG} == "no"
53MINSTALL?=	${INSTALL} ${TAG_ARGS} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
54.else
55MINSTALL?=	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},man} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
56.endif
57
58CATDIR=		${MANDIR:H:S/$/\/cat/}
59CATEXT=		.cat
60MANDOC_CMD?=	mandoc -Tascii
61
62MCOMPRESS_CMD?=	${COMPRESS_CMD}
63MCOMPRESS_EXT?=	${COMPRESS_EXT}
64
65SECTIONS=	1 2 3 4 5 6 7 8 9
66.SUFFIXES:	${SECTIONS:S/^/./g}
67
68
69# Backwards compatibility.
70.if !defined(MAN)
71.for __sect in ${SECTIONS}
72.if defined(MAN${__sect}) && !empty(MAN${__sect})
73MAN+=	${MAN${__sect}}
74.endif
75.endfor
76.endif
77
78all-man:
79
80.if ${MK_MANCOMPRESS} == "no"
81
82# Make special arrangements to filter to a temporary file at build time
83# for MK_MANCOMPRESS == no.
84.if defined(MANFILTER)
85FILTEXTENSION=		.filt
86.else
87FILTEXTENSION=
88.endif
89
90ZEXT=
91
92.if defined(MANFILTER)
93.if defined(MAN) && !empty(MAN)
94CLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
95CLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
96.for __page in ${MAN}
97.for __target in ${__page:T:S/$/${FILTEXTENSION}/g}
98all-man: ${__target}
99${__target}: ${__page}
100	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
101.endfor
102.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
103.for __target in ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
104all-man: ${__target}
105${__target}: ${__page}
106	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
107.endfor
108.endif
109.endfor
110.endif	# !empty(MAN)
111.else	# !defined(MANFILTER)
112.if defined(MAN) && !empty(MAN)
113CLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
114.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
115.for __page in ${MAN}
116.for __target in ${__page:T:S/$/${CATEXT}/g}
117all-man: ${__target}
118${__target}: ${__page}
119	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
120.endfor
121.endfor
122.else
123all-man: ${MAN}
124.endif
125.endif
126.endif	# defined(MANFILTER)
127
128.else	# ${MK_MANCOMPRESS} == "yes"
129
130ZEXT=		${MCOMPRESS_EXT}
131
132.if defined(MAN) && !empty(MAN)
133.if ${MK_STAGING_MAN} == "yes"
134STAGE_TARGETS+= stage_files
135_mansets:= ${MAN:E:O:u:M*[1-9]:@s@man$s@}
136STAGE_SETS+= ${_mansets}
137.for _page in ${MAN}
138stage_files.man${_page:T:E}: ${_page}
139STAGE_DIR.man${_page:T:E}?= ${STAGE_OBJTOP}${MANDIR}${_page:T:E}${MANSUBDIR}
140.endfor
141.if !empty(MLINKS)
142STAGE_SETS+= mlinks
143STAGE_TARGETS+= stage_links
144STAGE_LINKS.mlinks:= ${MLINKS:@f@${f:S,^,${MANDIR}${f:E}${MANSUBDIR}/,}@}
145stage_links.mlinks: ${_mansets:@s@stage_files.$s@}
146.endif
147.endif
148
149CLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
150CLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
151.for __page in ${MAN}
152.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
153all-man: ${__target}
154${__target}: ${__page}
155.if defined(MANFILTER)
156	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
157.else
158	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
159.endif
160.endfor
161.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
162.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
163all-man: ${__target}
164${__target}: ${__page}
165.if defined(MANFILTER)
166	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
167.else
168	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
169.endif
170.endfor
171.endif
172.endfor
173.endif
174
175.endif	# ${MK_MANCOMPRESS} == "no"
176
177.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
178.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
179_MANLINKS+=	${MANDIR}${_osect}${MANSUBDIR}/${_oname} \
180		${MANDIR}${_dsect}${MANSUBDIR}/${_dname}
181.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
182_MANLINKS+=	${CATDIR}${_osect}${MANSUBDIR}/${_oname} \
183		${CATDIR}${_dsect}${MANSUBDIR}/${_dname}
184.endif
185.endfor
186.endif
187
188maninstall:
189.if defined(MAN) && !empty(MAN)
190maninstall: ${MAN}
191.if ${MK_MANCOMPRESS} == "no"
192.if defined(MANFILTER)
193.for __page in ${MAN}
194	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
195		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
196.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
197	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
198		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
199.endif
200.endfor
201.else	# !defined(MANFILTER)
202	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
203	while : ; do \
204		case $$# in \
205			0) break;; \
206			1) echo "warn: missing extension: $$1"; break;; \
207		esac; \
208		page=$$1; shift; sect=$$1; shift; \
209		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
210		${ECHO} ${MINSTALL} $${page} $${d}; \
211		${MINSTALL} $${page} $${d}; \
212	done
213.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
214.for __page in ${MAN}
215	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
216		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
217.endfor
218.endif
219.endif	# defined(MANFILTER)
220.else	# ${MK_MANCOMPRESS} == "yes"
221.for __page in ${MAN}
222	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
223		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
224.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
225	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
226		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
227.endif
228.endfor
229.endif	# ${MK_MANCOMPRESS} == "no"
230.endif
231.for l t in ${_MANLINKS}
232.if ${MK_MANSPLITPKG} == "no"
233	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
234	    ${INSTALL_MANLINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
235.else
236	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
237	    ${INSTALL_MANLINK} ${TAG_ARGS:D${TAG_ARGS},man} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
238.endif
239.endfor
240
241manlint:
242.if defined(MAN) && !empty(MAN)
243.for __page in ${MAN}
244manlint: ${__page}lint
245${__page}lint: ${__page}
246.if defined(MANFILTER)
247	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
248.else
249	${MANDOC_CMD} -Tlint ${.ALLSRC}
250.endif
251.endfor
252.endif
253