1# $Id: man.mk,v 1.26 2023/12/30 02:10:38 sjg Exp $ 2 3.if !target(__${.PARSEFILE}__) 4__${.PARSEFILE}__: .NOTMAIN 5 6OPTIONS_DEFAULT_NO += CMT2DOC 7 8.include <init.mk> 9.include <options.mk> 10 11# unlike bsd.man.mk we handle 3 approaches 12# 1. install unformated nroff (default) 13# 2. install formatted pages 14# 3. install formatted pages but with extension of .0 15# sadly we cannot rely on a shell that supports ${foo#...} and ${foo%...} 16# so we have to use sed(1). 17 18# set MANTARGET=cat for formatted pages 19MANTARGET ?= man 20# set this to .0 for same behavior as bsd.man.mk 21MCATEXT ?= 22 23NROFF ?= nroff 24MANDIR ?= /usr/share/man 25MANDOC ?= man 26 27MAN_SUFFIXES?= .1 .2 .3 .4 .5 .6 .7 .8 .9 28.SUFFIXES: ${MAN_SUFFIXES} 29.if ${MANTARGET} == "cat" 30.SUFFIXES: ${MAN_SUFFIXES:S,.,.cat,} 31.endif 32 33${MAN_SUFFIXES:@s@$s${s:S,.,.cat,}@}: 34 @echo "${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}" 35 @${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}.new && \ 36 mv ${.TARGET:T}.new ${.TARGET:T} 37 38 39.if !empty(MANOWN) 40MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP} 41MAN_CHOWN ?= chown 42.else 43MAN_CHOWN = : 44.endif 45 46MINSTALL = ${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE} 47 48.if defined(MAN) && !empty(MAN) 49 50.if ${MANTARGET} == "cat" 51MANALL ?= ${MAN:T:@p@${p:R}.cat${p:E}@} 52.else 53MANALL ?= ${MAN} 54.endif 55 56.if ${MK_CMT2DOC} == "yes" 57# use cmt2doc.py to extract manpages from source 58CMT2DOC?= cmt2doc.py 59CMT2DOC_OPTS?= ${CMT2DOC_ORGOPT} -pmS${.TARGET:E} 60CMT2DOC_SUFFIXES+= .c .h .sh .pl .py 61 62.SUFFIXES: ${CMT2DOC_SUFFIXES} 63 64${CMT2DOC_SUFFIXES:@s@${MAN_SUFFIXES:@m@$s$m@}@}: 65 @echo "${CMT2DOC} ${.IMPSRC} > ${.TARGET:T}" 66 @${CMT2DOC} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T}.new && \ 67 mv ${.TARGET:T}.new ${.TARGET:T} 68 69.endif 70 71# none of this is relevant unless doing maninstall 72.if make(*install) 73_mandir = ${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'` 74.if ${MANTARGET} == "cat" 75_mfromdir ?= . 76.if ${MCATEXT} == "" 77_minstpage = `echo $$page | sed 's/\.cat/./'` 78.else 79_minstpage = `echo $$page | sed 's/\.cat.*//'`${MCATEXT} 80.endif 81.endif 82.if target(${MAN:[1]}) 83_mfromdir ?= . 84.endif 85_mfromdir ?= ${.CURDIR} 86_minstpage ?= $${page} 87.endif 88 89.if defined(MANZ) 90# chown and chmod are done afterward automatically 91MCOMPRESS_CMD ?= gzip -cf 92MCOMPRESS_EXT ?= .gz 93 94_MANZ_USE: .USE 95 @${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET} 96 97.for _page in ${MANALL} 98${_page:T}${MCOMPRESS_EXT}: ${_page} _MANZ_USE 99.endfor 100.endif 101 102.if ${MK_STAGING_MAN} == "yes" 103_mansets := ${MAN:E:O:u:M*[1-9]:@s@man$s@} 104.if ${MANTARGET} == "cat" 105STAGE_AS_SETS += ${_mansets} 106_stage_man = stage_as 107.else 108STAGE_SETS += ${_mansets} 109_stage_man = stage_files 110.endif 111STAGE_TARGETS += ${_stage_man} 112.for _page _as in ${MANALL:@x@$x ${x:T:S/.cat/./}@} 113${_stage_man}.man${_as:E}: ${_page} 114.if target(${_page:T}${MCOMPRESS_EXT}) 115${_man_stage}.man${_as:E}: ${_page:T}${MCOMPRESS_EXT} 116.endif 117STAGE_DIR.man${_as:E} ?= ${STAGE_OBJTOP}${MANDIR}/${MANTARGET}${_as:E}${MANSUBDIR} 118.if ${MANTARGET} == "cat" 119STAGE_AS_${_page} = ${_as} 120.endif 121.endfor 122.if !defined(NO_MLINKS) && !empty(MLINKS) 123STAGE_SETS += mlinks 124STAGE_TARGETS += stage_links 125STAGE_LINKS.mlinks := ${MLINKS:M*.[1-9]:@f@${f:S,^,${MANDIR}/${MANTARGET}${f:E}${MANSUBDIR}/,}@} 126stage_links.mlinks: ${_mansets:@s@stage_files.$s@} 127.endif 128.endif 129 130.endif 131 132maninstall: 133.if defined(MANALL) && !empty(MANALL) 134 @for page in ${MANALL:T}; do \ 135 test -s ${_mfromdir}/$$page || continue; \ 136 dir=${_mandir}; \ 137 test -d $$dir || ${INSTALL} -d ${MAN_INSTALL_OWN} -m 775 $$dir; \ 138 instpage=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \ 139 if [ X"${MCOMPRESS}" = X ]; then \ 140 echo ${MINSTALL} ${_mfromdir}/$$page $$instpage; \ 141 ${MINSTALL} ${_mfromdir}/$$page $$instpage; \ 142 else \ 143 rm -f $$instpage; \ 144 echo ${MCOMPRESS} ${_mfromdir}/$$page \> $$instpage; \ 145 ${MCOMPRESS} ${_mfromdir}/$$page > $$instpage; \ 146 ${MAN_CHOWN} ${MANOWN}:${MANGRP} $$instpage; \ 147 chmod ${MANMODE} $$instpage; \ 148 fi \ 149 done 150.if defined(MLINKS) && !empty(MLINKS) 151 @set ${MLINKS}; \ 152 while test $$# -ge 2; do \ 153 page=$$1; \ 154 shift; \ 155 dir=${_mandir}; \ 156 l=${_minstpage}${MCOMPRESSSUFFIX}; \ 157 page=$$1; \ 158 shift; \ 159 dir=${_mandir}; \ 160 t=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \ 161 echo $$t -\> $$l; \ 162 rm -f $$t; \ 163 ln -s $$l $$t; \ 164 done 165.endif 166.endif 167 168.if defined(MANALL) && !empty(MANALL) 169manall: ${MANALL} 170all: manall 171.endif 172 173.if defined(CLEANMAN) && !empty(CLEANMAN) 174cleandir: cleanman 175cleanman: 176 rm -f ${CLEANMAN} 177.endif 178.endif 179