xref: /freebsd/share/mk/bsd.man.mk (revision 09fa52f83f1a26013acb3f4a95a15d72a99ac136)
17f3dea24SPeter Wemm# $FreeBSD$
253996fadSWolfram Schneider#
353996fadSWolfram Schneider# The include file <bsd.man.mk> handles installing manual pages and
470e244f8SWolfram Schneider# their links.
553996fadSWolfram Schneider#
653996fadSWolfram Schneider#
753996fadSWolfram Schneider# +++ variables +++
853996fadSWolfram Schneider#
953996fadSWolfram Schneider# DESTDIR	Change the tree where the man pages gets installed. [not set]
1053996fadSWolfram Schneider#
1153996fadSWolfram Schneider# MANDIR	Base path for manual installation. [${SHAREDIR}/man/man]
1253996fadSWolfram Schneider#
1353996fadSWolfram Schneider# MANOWN	Manual owner. [${SHAREOWN}]
1453996fadSWolfram Schneider#
1553996fadSWolfram Schneider# MANGRP	Manual group. [${SHAREGRP}]
1653996fadSWolfram Schneider#
1753996fadSWolfram Schneider# MANMODE	Manual mode. [${NOBINMODE}]
1853996fadSWolfram Schneider#
1953996fadSWolfram Schneider# MANSUBDIR	Subdirectory under the manual page section, i.e. "/i386"
2053996fadSWolfram Schneider#		or "/tahoe" for machine specific manual pages.
2153996fadSWolfram Schneider#
22862d3deaSRuslan Ermilov# MAN		The manual pages to be installed. For sections see
2353996fadSWolfram Schneider#		variable ${SECTIONS}
2453996fadSWolfram Schneider#
25f7ea12a0SWolfram Schneider# MCOMPRESS_CMD	Program to compress man pages. Output is to
26f7ea12a0SWolfram Schneider#		stdout. [${COMPRESS_CMD}]
2753996fadSWolfram Schneider#
2853996fadSWolfram Schneider# MLINKS	List of manual page links (using a suffix). The
2953996fadSWolfram Schneider#		linked-to file must come first, the linked file
3053996fadSWolfram Schneider#		second, and there may be multiple pairs. The files
3153996fadSWolfram Schneider#		are hard-linked.
3253996fadSWolfram Schneider#
3353996fadSWolfram Schneider# NOMANCOMPRESS	If you do not want unformatted manual pages to be
3453996fadSWolfram Schneider#		compressed when they are installed. [not set]
3553996fadSWolfram Schneider#
36236fc12aSWolfram Schneider# NOMLINKS	If you do not want install manual page links. [not set]
37236fc12aSWolfram Schneider#
381663ea58STim Vanderhoek# MANFILTER	command to pipe the raw man page through before compressing
39d5dcd8e6SPeter Wemm#		or installing.  Can be used to do sed substitution.
4053996fadSWolfram Schneider#
415191ded8SPaul Traina# MANBUILDCAT	create preformatted manual pages in addition to normal
425191ded8SPaul Traina#		pages. [not set]
435191ded8SPaul Traina#
445191ded8SPaul Traina# MROFF_CMD	command and flags to create preformatted pages
455191ded8SPaul Traina#
4653996fadSWolfram Schneider# +++ targets +++
4753996fadSWolfram Schneider#
4853996fadSWolfram Schneider#	maninstall:
4953996fadSWolfram Schneider#		Install the manual pages and their links.
5053996fadSWolfram Schneider#
5153996fadSWolfram Schneider
523585b293SGarrett WollmanMINSTALL=	${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
53afe61c15SRodney W. Grimes
545191ded8SPaul TrainaCATDIR=		${MANDIR:H:S/$/\/cat/}
555191ded8SPaul TrainaCATEXT=		.cat
560a3a9126SRuslan ErmilovMROFF_CMD?=	groff -Tascii -man
575191ded8SPaul Traina
58f7ea12a0SWolfram SchneiderMCOMPRESS_CMD?=	${COMPRESS_CMD}
59f7ea12a0SWolfram SchneiderMCOMPRESS_EXT?=	${COMPRESS_EXT}
60afe61c15SRodney W. Grimes
6109fa52f8SRuslan ErmilovSECTIONS=	1 1aout 2 3 4 5 6 7 8 9
6209fa52f8SRuslan Ermilov.SUFFIXES:	${SECTIONS:S/^/./g}
63862d3deaSRuslan Ermilov
64862d3deaSRuslan Ermilov# Backwards compatibility.
6509fa52f8SRuslan Ermilov.if !defined(MAN)
6609fa52f8SRuslan Ermilov.for sect in ${SECTIONS}
67862d3deaSRuslan Ermilov.if defined(MAN${sect}) && !empty(MAN${sect})
68862d3deaSRuslan ErmilovMAN+=	${MAN${sect}}
69eb896871SBruce Evans.endif
70eb896871SBruce Evans.endfor
7109fa52f8SRuslan Ermilov.endif
72eb896871SBruce Evans
73862d3deaSRuslan Ermilovall-man:
74e8f9a073SBruce Evans
75e8f9a073SBruce Evans.if defined(NOMANCOMPRESS)
76e8f9a073SBruce Evans
77eb896871SBruce EvansCOPY=		-c
78eb0085f4SPeter Wemm
79eb0085f4SPeter Wemm# Make special arrangements to filter to a temporary file at build time
80eb0085f4SPeter Wemm# for NOMANCOMPRESS.
81eb0085f4SPeter Wemm.if defined(MANFILTER)
82eb0085f4SPeter WemmFILTEXTENSION=		.filt
83eb0085f4SPeter Wemm.else
84eb0085f4SPeter WemmFILTEXTENSION=
85eb0085f4SPeter Wemm.endif
86eb0085f4SPeter Wemm
87e8f9a073SBruce EvansZEXT=
88e8f9a073SBruce Evans
89d5dcd8e6SPeter Wemm.if defined(MANFILTER)
90862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
91862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
92862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
93862d3deaSRuslan Ermilov.for page in ${MAN}
94eb0085f4SPeter Wemm.for target in ${page:T:S/$/${FILTEXTENSION}/g}
95d5dcd8e6SPeter Wemmall-man: ${target}
96d5dcd8e6SPeter Wemm${target}: ${page}
975e7d3affSPeter Wemm	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
98d5dcd8e6SPeter Wemm.endfor
995d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1005191ded8SPaul Traina.for target in ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
1015191ded8SPaul Trainaall-man: ${target}
1025191ded8SPaul Traina${target}: ${page}
1035191ded8SPaul Traina	${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} > ${.TARGET}
104d5dcd8e6SPeter Wemm.endfor
105d5dcd8e6SPeter Wemm.endif
106d5dcd8e6SPeter Wemm.endfor
107d5dcd8e6SPeter Wemm.endif
1085191ded8SPaul Traina.else
109862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
110862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
1115d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
112862d3deaSRuslan Ermilov.for page in ${MAN}
1135191ded8SPaul Traina.for target in ${page:T:S/$/${CATEXT}/g}
1145191ded8SPaul Trainaall-man: ${target}
1155191ded8SPaul Traina${target}: ${page}
1165191ded8SPaul Traina	${MROFF_CMD} ${.ALLSRC} > ${.TARGET}
1175191ded8SPaul Traina.endfor
1185191ded8SPaul Traina.endfor
1195191ded8SPaul Traina.endif
1205191ded8SPaul Traina.endif
1215191ded8SPaul Traina.endif
122d5dcd8e6SPeter Wemm
123e8f9a073SBruce Evans.else
124e8f9a073SBruce Evans
125f7ea12a0SWolfram SchneiderZEXT=		${MCOMPRESS_EXT}
126e8f9a073SBruce Evans
127862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
128862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
129862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
130862d3deaSRuslan Ermilov.for page in ${MAN}
131f7ea12a0SWolfram Schneider.for target in ${page:T:S/$/${MCOMPRESS_EXT}/}
132e8f9a073SBruce Evansall-man: ${target}
133e8f9a073SBruce Evans${target}: ${page}
1345e7d3affSPeter Wemm.if defined(MANFILTER)
135f7ea12a0SWolfram Schneider	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
136d5dcd8e6SPeter Wemm.else
137f7ea12a0SWolfram Schneider	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
138d5dcd8e6SPeter Wemm.endif
139e8f9a073SBruce Evans.endfor
1405d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1415191ded8SPaul Traina.for target in ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
1425191ded8SPaul Trainaall-man: ${target}
1435191ded8SPaul Traina${target}: ${page}
1445191ded8SPaul Traina.if defined(MANFILTER)
1455191ded8SPaul Traina	${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
1465191ded8SPaul Traina.else
1475191ded8SPaul Traina	${MROFF_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
1485191ded8SPaul Traina.endif
1495191ded8SPaul Traina.endfor
1505191ded8SPaul Traina.endif
151e8f9a073SBruce Evans.endfor
152e8f9a073SBruce Evans.endif
153e8f9a073SBruce Evans
1543585b293SGarrett Wollman.endif
1553585b293SGarrett Wollman
156eb896871SBruce Evansmaninstall::
157862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
158862d3deaSRuslan Ermilovmaninstall:: ${MAN}
159973f098aSGarrett Wollman.if defined(NOMANCOMPRESS)
160eb0085f4SPeter Wemm.if defined(MANFILTER)
161862d3deaSRuslan Ermilov.for page in ${MAN}
1625191ded8SPaul Traina	${MINSTALL} ${page:T:S/$/${FILTEXTENSION}/g} \
163862d3deaSRuslan Ermilov		${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}/${page}
1645d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1655191ded8SPaul Traina	${MINSTALL} ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
166862d3deaSRuslan Ermilov		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page}
1675191ded8SPaul Traina.endif
168eb0085f4SPeter Wemm.endfor
169eb0085f4SPeter Wemm.else
170862d3deaSRuslan Ermilov	@set `echo ${.ALLSRC} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
171862d3deaSRuslan Ermilov	while : ; do \
172862d3deaSRuslan Ermilov		case $$# in \
173862d3deaSRuslan Ermilov			0) break;; \
174862d3deaSRuslan Ermilov			1) echo "warn: missing extension: $$1"; break;; \
175862d3deaSRuslan Ermilov		esac; \
176862d3deaSRuslan Ermilov		page=$$1; shift; sect=$$1; shift; \
177862d3deaSRuslan Ermilov		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
178862d3deaSRuslan Ermilov		${ECHO} ${MINSTALL} $${page} $${d}; \
179862d3deaSRuslan Ermilov		${MINSTALL} $${page} $${d}; \
180862d3deaSRuslan Ermilov	done
1815d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
182862d3deaSRuslan Ermilov.for page in ${MAN}
1835191ded8SPaul Traina	${MINSTALL} ${page:T:S/$/${CATEXT}/} \
184862d3deaSRuslan Ermilov		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T}
1855191ded8SPaul Traina.endfor
1865191ded8SPaul Traina.endif
187eb0085f4SPeter Wemm.endif
188973f098aSGarrett Wollman.else
189862d3deaSRuslan Ermilov.for page in ${MAN}
190862d3deaSRuslan Ermilov	${MINSTALL} ${page:T:S/$/${MCOMPRESS_EXT}/g} \
191862d3deaSRuslan Ermilov		${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}
1925d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1935191ded8SPaul Traina	${MINSTALL} ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
194862d3deaSRuslan Ermilov		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T:S/$/${MCOMPRESS_EXT}/}
195973f098aSGarrett Wollman.endif
196973f098aSGarrett Wollman.endfor
197862d3deaSRuslan Ermilov.endif
198862d3deaSRuslan Ermilov.endif
199e8f9a073SBruce Evans
200236fc12aSWolfram Schneider.if !defined(NOMLINKS) && defined(MLINKS) && !empty(MLINKS)
201d8982a6aSWolfram Schneider	@set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
202d8982a6aSWolfram Schneider	while : ; do \
203d8982a6aSWolfram Schneider		case $$# in \
204d8982a6aSWolfram Schneider			0) break;; \
205d8982a6aSWolfram Schneider			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
206d8982a6aSWolfram Schneider		esac; \
207d8982a6aSWolfram Schneider		name=$$1; shift; sect=$$1; shift; \
208d8982a6aSWolfram Schneider		l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
209d8982a6aSWolfram Schneider		name=$$1; shift; sect=$$1; shift; \
210d8982a6aSWolfram Schneider		t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
21180c02d59SBruce Evans		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
212f7ea12a0SWolfram Schneider		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
2133585b293SGarrett Wollman		ln $${l}${ZEXT} $${t}${ZEXT}; \
214d8982a6aSWolfram Schneider	done
2155d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2165191ded8SPaul Traina	@set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
2175191ded8SPaul Traina	while : ; do \
2185191ded8SPaul Traina		case $$# in \
2195191ded8SPaul Traina			0) break;; \
2205191ded8SPaul Traina			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
2215191ded8SPaul Traina		esac; \
2225191ded8SPaul Traina		name=$$1; shift; sect=$$1; shift; \
2235191ded8SPaul Traina		l=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
2245191ded8SPaul Traina		name=$$1; shift; sect=$$1; shift; \
2255191ded8SPaul Traina		t=${DESTDIR}${CATDIR}$${sect}${MANSUBDIR}/$$name; \
2265191ded8SPaul Traina		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
2275191ded8SPaul Traina		rm -f $${t} $${t}${MCOMPRESS_EXT}; \
2285191ded8SPaul Traina		ln $${l}${ZEXT} $${t}${ZEXT}; \
2295191ded8SPaul Traina	done
2305191ded8SPaul Traina.endif
231afe61c15SRodney W. Grimes.endif
232