xref: /freebsd/share/mk/bsd.man.mk (revision c7e6cb9e08d6b51e677a9f5546b8e36d678687d0)
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#
339a9bc31fSRuslan Ermilov# NO_MLINKS	If you do not want install manual page links. [not set]
34236fc12aSWolfram Schneider#
351663ea58STim Vanderhoek# MANFILTER	command to pipe the raw man page through before compressing
36d5dcd8e6SPeter Wemm#		or installing.  Can be used to do sed substitution.
3753996fadSWolfram Schneider#
385191ded8SPaul Traina# MANBUILDCAT	create preformatted manual pages in addition to normal
395191ded8SPaul Traina#		pages. [not set]
405191ded8SPaul Traina#
410df7827eSBaptiste Daroussin# MANDOC_CMD	command and flags to create preformatted pages
425191ded8SPaul Traina#
4353996fadSWolfram Schneider# +++ targets +++
4453996fadSWolfram Schneider#
4553996fadSWolfram Schneider#	maninstall:
4653996fadSWolfram Schneider#		Install the manual pages and their links.
4753996fadSWolfram Schneider#
4853996fadSWolfram Schneider
492bdaf7e8SRuslan Ermilov.if !target(__<bsd.init.mk>__)
502bdaf7e8SRuslan Ermilov.error bsd.man.mk cannot be included directly.
512bdaf7e8SRuslan Ermilov.endif
522bdaf7e8SRuslan Ermilov
53*c7e6cb9eSEmmanuel Vadot.if ${MK_MANSPLITPKG} == "no"
54dc6d22c9SBaptiste DaroussinMINSTALL?=	${INSTALL} ${TAG_ARGS} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
55*c7e6cb9eSEmmanuel Vadot.else
56*c7e6cb9eSEmmanuel VadotMINSTALL?=	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},man} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
57*c7e6cb9eSEmmanuel Vadot.endif
58afe61c15SRodney W. Grimes
595191ded8SPaul TrainaCATDIR=		${MANDIR:H:S/$/\/cat/}
605191ded8SPaul TrainaCATEXT=		.cat
610df7827eSBaptiste DaroussinMANDOC_CMD?=	mandoc -Tascii
625191ded8SPaul Traina
63f7ea12a0SWolfram SchneiderMCOMPRESS_CMD?=	${COMPRESS_CMD}
64f7ea12a0SWolfram SchneiderMCOMPRESS_EXT?=	${COMPRESS_EXT}
65afe61c15SRodney W. Grimes
668b4f1f91SBrooks DavisSECTIONS=	1 2 3 4 5 6 7 8 9
6709fa52f8SRuslan Ermilov.SUFFIXES:	${SECTIONS:S/^/./g}
68862d3deaSRuslan Ermilov
69dc6d22c9SBaptiste Daroussin
70862d3deaSRuslan Ermilov# Backwards compatibility.
7109fa52f8SRuslan Ermilov.if !defined(MAN)
725b83a06cSRuslan Ermilov.for __sect in ${SECTIONS}
735b83a06cSRuslan Ermilov.if defined(MAN${__sect}) && !empty(MAN${__sect})
745b83a06cSRuslan ErmilovMAN+=	${MAN${__sect}}
75eb896871SBruce Evans.endif
76eb896871SBruce Evans.endfor
7709fa52f8SRuslan Ermilov.endif
78eb896871SBruce Evans
79f1702f87SBryan Dreweryall-man:
80e8f9a073SBruce Evans
810abe2561SWarner Losh.if ${MK_MANCOMPRESS} == "no"
82e8f9a073SBruce Evans
83eb0085f4SPeter Wemm# Make special arrangements to filter to a temporary file at build time
840abe2561SWarner Losh# for MK_MANCOMPRESS == no.
85eb0085f4SPeter Wemm.if defined(MANFILTER)
86eb0085f4SPeter WemmFILTEXTENSION=		.filt
87eb0085f4SPeter Wemm.else
88eb0085f4SPeter WemmFILTEXTENSION=
89eb0085f4SPeter Wemm.endif
90eb0085f4SPeter Wemm
91e8f9a073SBruce EvansZEXT=
92e8f9a073SBruce Evans
93d5dcd8e6SPeter Wemm.if defined(MANFILTER)
94862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
95862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
96862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
975b83a06cSRuslan Ermilov.for __page in ${MAN}
985b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${FILTEXTENSION}/g}
99f1702f87SBryan Dreweryall-man: ${__target}
1005b83a06cSRuslan Ermilov${__target}: ${__page}
1015e7d3affSPeter Wemm	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
102d5dcd8e6SPeter Wemm.endfor
1035d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1045b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
105f1702f87SBryan Dreweryall-man: ${__target}
1065852ae2dSBryan Drewery${__target}: ${__page}
1070df7827eSBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
108d5dcd8e6SPeter Wemm.endfor
109d5dcd8e6SPeter Wemm.endif
110d5dcd8e6SPeter Wemm.endfor
111c22afe52SBryan Drewery.endif	# !empty(MAN)
112c22afe52SBryan Drewery.else	# !defined(MANFILTER)
113862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
114862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
1155d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1165b83a06cSRuslan Ermilov.for __page in ${MAN}
1175b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}/g}
118f1702f87SBryan Dreweryall-man: ${__target}
1195852ae2dSBryan Drewery${__target}: ${__page}
1200df7827eSBaptiste Daroussin	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
1215191ded8SPaul Traina.endfor
1225191ded8SPaul Traina.endfor
1238f08b6b2SRuslan Ermilov.else
124f1702f87SBryan Dreweryall-man: ${MAN}
1255191ded8SPaul Traina.endif
1265191ded8SPaul Traina.endif
127c22afe52SBryan Drewery.endif	# defined(MANFILTER)
128d5dcd8e6SPeter Wemm
129c22afe52SBryan Drewery.else	# ${MK_MANCOMPRESS} == "yes"
130e8f9a073SBruce Evans
131f7ea12a0SWolfram SchneiderZEXT=		${MCOMPRESS_EXT}
132e8f9a073SBruce Evans
133862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
1341e344376SSimon J. Gerraty.if ${MK_STAGING_MAN} == "yes"
135eef72759SSimon J. GerratySTAGE_TARGETS+= stage_files
136924b88f6SSimon J. Gerraty_mansets:= ${MAN:E:O:u:M*[1-9]:@s@man$s@}
13709cdd180SSimon J. GerratySTAGE_SETS+= ${_mansets}
13809cdd180SSimon J. Gerraty.for _page in ${MAN}
13909cdd180SSimon J. Gerratystage_files.man${_page:T:E}: ${_page}
14009cdd180SSimon J. GerratySTAGE_DIR.man${_page:T:E}?= ${STAGE_OBJTOP}${MANDIR}${_page:T:E}${MANSUBDIR}
14109cdd180SSimon J. Gerraty.endfor
14209cdd180SSimon J. Gerraty.if !empty(MLINKS)
1431e344376SSimon J. GerratySTAGE_SETS+= mlinks
144eef72759SSimon J. GerratySTAGE_TARGETS+= stage_links
1451e344376SSimon J. GerratySTAGE_LINKS.mlinks:= ${MLINKS:@f@${f:S,^,${MANDIR}${f:E}${MANSUBDIR}/,}@}
1461e344376SSimon J. Gerratystage_links.mlinks: ${_mansets:@s@stage_files.$s@}
14709cdd180SSimon J. Gerraty.endif
14809cdd180SSimon J. Gerraty.endif
14909cdd180SSimon J. Gerraty
150862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
151862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
1525b83a06cSRuslan Ermilov.for __page in ${MAN}
1535b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
154f1702f87SBryan Dreweryall-man: ${__target}
1555852ae2dSBryan Drewery${__target}: ${__page}
1565e7d3affSPeter Wemm.if defined(MANFILTER)
157f7ea12a0SWolfram Schneider	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
158d5dcd8e6SPeter Wemm.else
159f7ea12a0SWolfram Schneider	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
160d5dcd8e6SPeter Wemm.endif
161e8f9a073SBruce Evans.endfor
1625d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1635b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
164f1702f87SBryan Dreweryall-man: ${__target}
1655852ae2dSBryan Drewery${__target}: ${__page}
1665191ded8SPaul Traina.if defined(MANFILTER)
1670df7827eSBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
1685191ded8SPaul Traina.else
1690df7827eSBaptiste Daroussin	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
1705191ded8SPaul Traina.endif
1715191ded8SPaul Traina.endfor
1725191ded8SPaul Traina.endif
173e8f9a073SBruce Evans.endfor
174e8f9a073SBruce Evans.endif
175e8f9a073SBruce Evans
176c22afe52SBryan Drewery.endif	# ${MK_MANCOMPRESS} == "no"
1773585b293SGarrett Wollman
1785f3a77a5SBryan Drewery.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
1795f3a77a5SBryan Drewery.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
1805f3a77a5SBryan Drewery_MANLINKS+=	${MANDIR}${_osect}${MANSUBDIR}/${_oname} \
1815f3a77a5SBryan Drewery		${MANDIR}${_dsect}${MANSUBDIR}/${_dname}
1825f3a77a5SBryan Drewery.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1835f3a77a5SBryan Drewery_MANLINKS+=	${CATDIR}${_osect}${MANSUBDIR}/${_oname} \
1845f3a77a5SBryan Drewery		${CATDIR}${_dsect}${MANSUBDIR}/${_dname}
1855f3a77a5SBryan Drewery.endif
1865f3a77a5SBryan Drewery.endfor
1875f3a77a5SBryan Drewery.endif
1885f3a77a5SBryan Drewery
189f1702f87SBryan Drewerymaninstall:
190862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
191f1702f87SBryan Drewerymaninstall: ${MAN}
1920abe2561SWarner Losh.if ${MK_MANCOMPRESS} == "no"
193eb0085f4SPeter Wemm.if defined(MANFILTER)
1945b83a06cSRuslan Ermilov.for __page in ${MAN}
1955b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
1965b83a06cSRuslan Ermilov		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
1975d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1985b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
1995b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
2005191ded8SPaul Traina.endif
201eb0085f4SPeter Wemm.endfor
202c22afe52SBryan Drewery.else	# !defined(MANFILTER)
203c22afe52SBryan Drewery	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
204c22afe52SBryan Drewery	while : ; do \
205c22afe52SBryan Drewery		case $$# in \
206c22afe52SBryan Drewery			0) break;; \
207c22afe52SBryan Drewery			1) echo "warn: missing extension: $$1"; break;; \
208c22afe52SBryan Drewery		esac; \
209c22afe52SBryan Drewery		page=$$1; shift; sect=$$1; shift; \
210c22afe52SBryan Drewery		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
211c22afe52SBryan Drewery		${ECHO} ${MINSTALL} $${page} $${d}; \
212c22afe52SBryan Drewery		${MINSTALL} $${page} $${d}; \
213c22afe52SBryan Drewery	done
2145d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2155b83a06cSRuslan Ermilov.for __page in ${MAN}
2165b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
2175b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
2185191ded8SPaul Traina.endfor
2195191ded8SPaul Traina.endif
220c22afe52SBryan Drewery.endif	# defined(MANFILTER)
221c22afe52SBryan Drewery.else	# ${MK_MANCOMPRESS} == "yes"
2225b83a06cSRuslan Ermilov.for __page in ${MAN}
2235b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
22461c20fc7SBryan Drewery		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
2255d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2265b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
2275b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
228973f098aSGarrett Wollman.endif
229973f098aSGarrett Wollman.endfor
230c22afe52SBryan Drewery.endif	# ${MK_MANCOMPRESS} == "no"
231862d3deaSRuslan Ermilov.endif
2325f3a77a5SBryan Drewery.for l t in ${_MANLINKS}
233*c7e6cb9eSEmmanuel Vadot.if ${MK_MANSPLITPKG} == "no"
2345f3a77a5SBryan Drewery	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
235fa8c921eSBrooks Davis	    ${INSTALL_MANLINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
236*c7e6cb9eSEmmanuel Vadot.else
237*c7e6cb9eSEmmanuel Vadot	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
238*c7e6cb9eSEmmanuel Vadot	    ${INSTALL_MANLINK} ${TAG_ARGS:D${TAG_ARGS},man} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
239*c7e6cb9eSEmmanuel Vadot.endif
240a82117a6SBaptiste Daroussin.endfor
24159e44d72SRuslan Ermilov
24259e44d72SRuslan Ermilovmanlint:
24359e44d72SRuslan Ermilov.if defined(MAN) && !empty(MAN)
2445b83a06cSRuslan Ermilov.for __page in ${MAN}
2455b83a06cSRuslan Ermilovmanlint: ${__page}lint
2465b83a06cSRuslan Ermilov${__page}lint: ${__page}
24759e44d72SRuslan Ermilov.if defined(MANFILTER)
2482f335df9SBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
24959e44d72SRuslan Ermilov.else
2502f335df9SBaptiste Daroussin	${MANDOC_CMD} -Tlint ${.ALLSRC}
25159e44d72SRuslan Ermilov.endif
25259e44d72SRuslan Ermilov.endfor
25359e44d72SRuslan Ermilov.endif
254