xref: /freebsd/share/mk/bsd.man.mk (revision d2a824c29d6925ba8675a811aa81f2ad7d92129d)
153996fadSWolfram Schneider#
253996fadSWolfram Schneider# The include file <bsd.man.mk> handles installing manual pages and
370e244f8SWolfram Schneider# their links.
453996fadSWolfram Schneider#
553996fadSWolfram Schneider#
653996fadSWolfram Schneider# +++ variables +++
753996fadSWolfram Schneider#
853996fadSWolfram Schneider# DESTDIR	Change the tree where the man pages gets installed. [not set]
953996fadSWolfram Schneider#
1053996fadSWolfram Schneider# MANDIR	Base path for manual installation. [${SHAREDIR}/man/man]
1153996fadSWolfram Schneider#
1253996fadSWolfram Schneider# MANOWN	Manual owner. [${SHAREOWN}]
1353996fadSWolfram Schneider#
1453996fadSWolfram Schneider# MANGRP	Manual group. [${SHAREGRP}]
1553996fadSWolfram Schneider#
1653996fadSWolfram Schneider# MANMODE	Manual mode. [${NOBINMODE}]
1753996fadSWolfram Schneider#
1853996fadSWolfram Schneider# MANSUBDIR	Subdirectory under the manual page section, i.e. "/i386"
1953996fadSWolfram Schneider#		or "/tahoe" for machine specific manual pages.
2053996fadSWolfram Schneider#
21862d3deaSRuslan Ermilov# MAN		The manual pages to be installed. For sections see
2253996fadSWolfram Schneider#		variable ${SECTIONS}
2353996fadSWolfram Schneider#
24f7ea12a0SWolfram Schneider# MCOMPRESS_CMD	Program to compress man pages. Output is to
25f7ea12a0SWolfram Schneider#		stdout. [${COMPRESS_CMD}]
2653996fadSWolfram Schneider#
2753996fadSWolfram Schneider# MLINKS	List of manual page links (using a suffix). The
2853996fadSWolfram Schneider#		linked-to file must come first, the linked file
2953996fadSWolfram Schneider#		second, and there may be multiple pairs. The files
3053996fadSWolfram Schneider#		are hard-linked.
3153996fadSWolfram Schneider#
329a9bc31fSRuslan Ermilov# NO_MLINKS	If you do not want install manual page links. [not set]
33236fc12aSWolfram Schneider#
341663ea58STim Vanderhoek# MANFILTER	command to pipe the raw man page through before compressing
35d5dcd8e6SPeter Wemm#		or installing.  Can be used to do sed substitution.
3653996fadSWolfram Schneider#
375191ded8SPaul Traina# MANBUILDCAT	create preformatted manual pages in addition to normal
385191ded8SPaul Traina#		pages. [not set]
395191ded8SPaul Traina#
400df7827eSBaptiste Daroussin# MANDOC_CMD	command and flags to create preformatted pages
415191ded8SPaul Traina#
4253996fadSWolfram Schneider# +++ targets +++
4353996fadSWolfram Schneider#
4453996fadSWolfram Schneider#	maninstall:
4553996fadSWolfram Schneider#		Install the manual pages and their links.
4653996fadSWolfram Schneider#
4753996fadSWolfram Schneider
482bdaf7e8SRuslan Ermilov.if !target(__<bsd.init.mk>__)
492bdaf7e8SRuslan Ermilov.error bsd.man.mk cannot be included directly.
502bdaf7e8SRuslan Ermilov.endif
512bdaf7e8SRuslan Ermilov
52c7e6cb9eSEmmanuel Vadot.if ${MK_MANSPLITPKG} == "no"
53dc6d22c9SBaptiste DaroussinMINSTALL?=	${INSTALL} ${TAG_ARGS} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
54c7e6cb9eSEmmanuel Vadot.else
55c7e6cb9eSEmmanuel VadotMINSTALL?=	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},man} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
56c7e6cb9eSEmmanuel Vadot.endif
57afe61c15SRodney W. Grimes
585191ded8SPaul TrainaCATDIR=		${MANDIR:H:S/$/\/cat/}
595191ded8SPaul TrainaCATEXT=		.cat
600df7827eSBaptiste DaroussinMANDOC_CMD?=	mandoc -Tascii
615191ded8SPaul Traina
62f7ea12a0SWolfram SchneiderMCOMPRESS_CMD?=	${COMPRESS_CMD}
63f7ea12a0SWolfram SchneiderMCOMPRESS_EXT?=	${COMPRESS_EXT}
64afe61c15SRodney W. Grimes
658b4f1f91SBrooks DavisSECTIONS=	1 2 3 4 5 6 7 8 9
6609fa52f8SRuslan Ermilov.SUFFIXES:	${SECTIONS:S/^/./g}
67862d3deaSRuslan Ermilov
68dc6d22c9SBaptiste Daroussin
69862d3deaSRuslan Ermilov# Backwards compatibility.
7009fa52f8SRuslan Ermilov.if !defined(MAN)
715b83a06cSRuslan Ermilov.for __sect in ${SECTIONS}
725b83a06cSRuslan Ermilov.if defined(MAN${__sect}) && !empty(MAN${__sect})
735b83a06cSRuslan ErmilovMAN+=	${MAN${__sect}}
74eb896871SBruce Evans.endif
75eb896871SBruce Evans.endfor
7609fa52f8SRuslan Ermilov.endif
77eb896871SBruce Evans
78f1702f87SBryan Dreweryall-man:
79e8f9a073SBruce Evans
800abe2561SWarner Losh.if ${MK_MANCOMPRESS} == "no"
81e8f9a073SBruce Evans
82eb0085f4SPeter Wemm# Make special arrangements to filter to a temporary file at build time
830abe2561SWarner Losh# for MK_MANCOMPRESS == no.
84eb0085f4SPeter Wemm.if defined(MANFILTER)
85eb0085f4SPeter WemmFILTEXTENSION=		.filt
86eb0085f4SPeter Wemm.else
87eb0085f4SPeter WemmFILTEXTENSION=
88eb0085f4SPeter Wemm.endif
89eb0085f4SPeter Wemm
90e8f9a073SBruce EvansZEXT=
91e8f9a073SBruce Evans
92d5dcd8e6SPeter Wemm.if defined(MANFILTER)
93862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
94862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
95862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
965b83a06cSRuslan Ermilov.for __page in ${MAN}
975b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${FILTEXTENSION}/g}
98f1702f87SBryan Dreweryall-man: ${__target}
995b83a06cSRuslan Ermilov${__target}: ${__page}
1005e7d3affSPeter Wemm	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
101d5dcd8e6SPeter Wemm.endfor
1025d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1035b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
104f1702f87SBryan Dreweryall-man: ${__target}
1055852ae2dSBryan Drewery${__target}: ${__page}
1060df7827eSBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
107d5dcd8e6SPeter Wemm.endfor
108d5dcd8e6SPeter Wemm.endif
109d5dcd8e6SPeter Wemm.endfor
110c22afe52SBryan Drewery.endif	# !empty(MAN)
111c22afe52SBryan Drewery.else	# !defined(MANFILTER)
112862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
113862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
1145d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1155b83a06cSRuslan Ermilov.for __page in ${MAN}
1165b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}/g}
117f1702f87SBryan Dreweryall-man: ${__target}
1185852ae2dSBryan Drewery${__target}: ${__page}
1190df7827eSBaptiste Daroussin	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
1205191ded8SPaul Traina.endfor
1215191ded8SPaul Traina.endfor
1228f08b6b2SRuslan Ermilov.else
123f1702f87SBryan Dreweryall-man: ${MAN}
1245191ded8SPaul Traina.endif
1255191ded8SPaul Traina.endif
126c22afe52SBryan Drewery.endif	# defined(MANFILTER)
127d5dcd8e6SPeter Wemm
128c22afe52SBryan Drewery.else	# ${MK_MANCOMPRESS} == "yes"
129e8f9a073SBruce Evans
130f7ea12a0SWolfram SchneiderZEXT=		${MCOMPRESS_EXT}
131e8f9a073SBruce Evans
132862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
133862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
134862d3deaSRuslan ErmilovCLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
1355b83a06cSRuslan Ermilov.for __page in ${MAN}
1365b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${MCOMPRESS_EXT}/}
137f1702f87SBryan Dreweryall-man: ${__target}
1385852ae2dSBryan Drewery${__target}: ${__page}
1395e7d3affSPeter Wemm.if defined(MANFILTER)
140f7ea12a0SWolfram Schneider	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
141d5dcd8e6SPeter Wemm.else
142f7ea12a0SWolfram Schneider	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
143d5dcd8e6SPeter Wemm.endif
144e8f9a073SBruce Evans.endfor
1455d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1465b83a06cSRuslan Ermilov.for __target in ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
147f1702f87SBryan Dreweryall-man: ${__target}
1485852ae2dSBryan Drewery${__target}: ${__page}
1495191ded8SPaul Traina.if defined(MANFILTER)
1500df7827eSBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
1515191ded8SPaul Traina.else
1520df7827eSBaptiste Daroussin	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
1535191ded8SPaul Traina.endif
1545191ded8SPaul Traina.endfor
1555191ded8SPaul Traina.endif
156e8f9a073SBruce Evans.endfor
157e8f9a073SBruce Evans.endif
158e8f9a073SBruce Evans
159c22afe52SBryan Drewery.endif	# ${MK_MANCOMPRESS} == "no"
1603585b293SGarrett Wollman
1615f3a77a5SBryan Drewery.if !defined(NO_MLINKS) && defined(MLINKS) && !empty(MLINKS)
1625f3a77a5SBryan Drewery.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
1635f3a77a5SBryan Drewery_MANLINKS+=	${MANDIR}${_osect}${MANSUBDIR}/${_oname} \
1645f3a77a5SBryan Drewery		${MANDIR}${_dsect}${MANSUBDIR}/${_dname}
1655f3a77a5SBryan Drewery.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
1665f3a77a5SBryan Drewery_MANLINKS+=	${CATDIR}${_osect}${MANSUBDIR}/${_oname} \
1675f3a77a5SBryan Drewery		${CATDIR}${_dsect}${MANSUBDIR}/${_dname}
1685f3a77a5SBryan Drewery.endif
1695f3a77a5SBryan Drewery.endfor
1705f3a77a5SBryan Drewery.endif
1715f3a77a5SBryan Drewery
1724d08b569SSimon J. Gerraty.if defined(MAN) && !empty(MAN)
1734d08b569SSimon J. Gerraty.if ${MK_STAGING_MAN} == "yes"
1744d08b569SSimon J. GerratySTAGE_TARGETS+= stage_files
1754d08b569SSimon J. Gerraty_mansets:= ${MAN:E:O:u:M*[1-9]:@s@man$s@}
1764d08b569SSimon J. GerratySTAGE_SETS+= ${_mansets}
1774d08b569SSimon J. Gerraty.for _page in ${MAN}
1784d08b569SSimon J. Gerratystage_files.man${_page:T:E}: ${_page}
1794d08b569SSimon J. Gerraty.if target(${_page}${MCOMPRESS_EXT})
1804d08b569SSimon J. Gerratystage_files.man${_page:T:E}: ${_page}${MCOMPRESS_EXT}
1814d08b569SSimon J. Gerraty.endif
1824d08b569SSimon J. GerratySTAGE_DIR.man${_page:T:E}?= ${STAGE_OBJTOP}${MANDIR}${_page:T:E}${MANSUBDIR}
1834d08b569SSimon J. Gerraty.endfor
1844d08b569SSimon J. Gerraty.if !defined(NO_MLINKS) && !empty(MLINKS)
1854d08b569SSimon J. GerratySTAGE_SETS+= mlinks
1864d08b569SSimon J. GerratySTAGE_TARGETS+= stage_links
1874d08b569SSimon J. GerratySTAGE_LINKS.mlinks:= ${MLINKS:M*.[1-9]:@f@${f:S,^,${MANDIR}${f:E}${MANSUBDIR}/,}@}
1884d08b569SSimon J. Gerratystage_links.mlinks: ${_mansets:@s@stage_files.$s@}
1894d08b569SSimon J. Gerraty.endif
1904d08b569SSimon J. Gerraty.endif
1914d08b569SSimon J. Gerraty.endif
1924d08b569SSimon J. Gerraty
193f1702f87SBryan Drewerymaninstall:
194862d3deaSRuslan Ermilov.if defined(MAN) && !empty(MAN)
195f1702f87SBryan Drewerymaninstall: ${MAN}
1960abe2561SWarner Losh.if ${MK_MANCOMPRESS} == "no"
197eb0085f4SPeter Wemm.if defined(MANFILTER)
1985b83a06cSRuslan Ermilov.for __page in ${MAN}
1995b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${FILTEXTENSION}/g} \
2005b83a06cSRuslan Ermilov		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/${__page}
2015d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2025b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
2035b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page}
2045191ded8SPaul Traina.endif
205eb0085f4SPeter Wemm.endfor
206c22afe52SBryan Drewery.else	# !defined(MANFILTER)
207c22afe52SBryan Drewery	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
208c22afe52SBryan Drewery	while : ; do \
209c22afe52SBryan Drewery		case $$# in \
210c22afe52SBryan Drewery			0) break;; \
211c22afe52SBryan Drewery			1) echo "warn: missing extension: $$1"; break;; \
212c22afe52SBryan Drewery		esac; \
213c22afe52SBryan Drewery		page=$$1; shift; sect=$$1; shift; \
214c22afe52SBryan Drewery		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
215c22afe52SBryan Drewery		${ECHO} ${MINSTALL} $${page} $${d}; \
216c22afe52SBryan Drewery		${MINSTALL} $${page} $${d}; \
217c22afe52SBryan Drewery	done
2185d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2195b83a06cSRuslan Ermilov.for __page in ${MAN}
2205b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}/} \
2215b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T}
2225191ded8SPaul Traina.endfor
2235191ded8SPaul Traina.endif
224c22afe52SBryan Drewery.endif	# defined(MANFILTER)
225c22afe52SBryan Drewery.else	# ${MK_MANCOMPRESS} == "yes"
2265b83a06cSRuslan Ermilov.for __page in ${MAN}
2275b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${MCOMPRESS_EXT}/g} \
22861c20fc7SBryan Drewery		${DESTDIR}${MANDIR}${__page:E}${MANSUBDIR}/
2295d08f311SBruce Evans.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
2305b83a06cSRuslan Ermilov	${MINSTALL} ${__page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
2315b83a06cSRuslan Ermilov		${DESTDIR}${CATDIR}${__page:E}${MANSUBDIR}/${__page:T:S/$/${MCOMPRESS_EXT}/}
232973f098aSGarrett Wollman.endif
233973f098aSGarrett Wollman.endfor
234c22afe52SBryan Drewery.endif	# ${MK_MANCOMPRESS} == "no"
235862d3deaSRuslan Ermilov.endif
2365f3a77a5SBryan Drewery.for l t in ${_MANLINKS}
237*d2a824c2SWarner Losh# On MacOS, assume case folding FS, and don't install links from foo.x to FOO.x.
238*d2a824c2SWarner Losh.if ${.MAKE.OS} != "Darwin" || ${l:tu} != ${t:tu}
239c7e6cb9eSEmmanuel Vadot.if ${MK_MANSPLITPKG} == "no"
2405f3a77a5SBryan Drewery	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
241fa8c921eSBrooks Davis	    ${INSTALL_MANLINK} ${TAG_ARGS} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
242c7e6cb9eSEmmanuel Vadot.else
243c7e6cb9eSEmmanuel Vadot	rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}; \
244c7e6cb9eSEmmanuel Vadot	    ${INSTALL_MANLINK} ${TAG_ARGS:D${TAG_ARGS},man} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
245c7e6cb9eSEmmanuel Vadot.endif
246*d2a824c2SWarner Losh.endif
247a82117a6SBaptiste Daroussin.endfor
24859e44d72SRuslan Ermilov
24959e44d72SRuslan Ermilovmanlint:
25059e44d72SRuslan Ermilov.if defined(MAN) && !empty(MAN)
2515b83a06cSRuslan Ermilov.for __page in ${MAN}
2525b83a06cSRuslan Ermilovmanlint: ${__page}lint
2535b83a06cSRuslan Ermilov${__page}lint: ${__page}
25459e44d72SRuslan Ermilov.if defined(MANFILTER)
2552f335df9SBaptiste Daroussin	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
25659e44d72SRuslan Ermilov.else
2572f335df9SBaptiste Daroussin	${MANDOC_CMD} -Tlint ${.ALLSRC}
25859e44d72SRuslan Ermilov.endif
25959e44d72SRuslan Ermilov.endfor
26059e44d72SRuslan Ermilov.endif
261