xref: /freebsd/contrib/bmake/mk/man.mk (revision d1a0d267b78b542fbd7e6553af2493760f49bfa8)
1# $Id: man.mk,v 1.20 2012/12/13 01:51:01 sjg Exp $
2
3.if !target(__${.PARSEFILE}__)
4__${.PARSEFILE}__:
5
6.include <init.mk>
7
8# unlike bsd.man.mk we handle 3 approaches
9# 1. install unformated nroff (default)
10# 2. install formatted pages
11# 3. install formatted pages but with extension of .0
12# sadly we cannot rely on a shell that supports ${foo#...} and ${foo%...}
13# so we have to use sed(1).
14
15# set MANTARGET=cat for formatted pages
16MANTARGET?=	man
17# set this to .0 for same behavior as bsd.man.mk
18MCATEXT?=
19
20NROFF?=		nroff
21MANDIR?=	/usr/share/man
22MANDOC?= man
23
24.SUFFIXES: .1 .2 .3 .4 .5 .6 .7 .8 .9 .cat1 .cat2 .cat3 .cat4 .cat5 .cat6 \
25	.cat7 .cat8 .cat9
26
27.9.cat9 .8.cat8 .7.cat7 .6.cat6 .5.cat5 .4.cat4 .3.cat3 .2.cat2 .1.cat1:
28	@echo "${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T}"
29	@${NROFF} -${MANDOC} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false )
30
31.if defined(MAN) && !empty(MAN)
32
33# we use cmt2doc.pl to extract manpages from source
34# this is triggered by the setting of EXTRACT_MAN or MAN being set but
35# not existsing.
36
37.if !exists(${MAN:[1]}) && !target(${MAN:[1]})
38.if defined(EXTRACT_MAN) && ${EXTRACT_MAN} == "no"
39MAN=
40.else
41.if exists(/usr/local/share/bin/cmt2doc.pl)
42CMT2DOC?= cmt2doc.pl
43CMT2DOC_OPTS?=  ${CMT2DOC_ORGOPT} -pmS${.TARGET:E}
44.endif
45.ifdef CMT2DOC
46.c.8 .c.5 .c.3 .c.4 .c.1 \
47	.cc.8 .cc.5 .cc.3 .cc.4 .cc.1 \
48	.h.8 .h.5 .h.3 .h.4 .h.1 \
49	.sh.8 .sh.5 .sh.3 .sh.4 .sh.1 \
50	.pl.8 .pl.5 .pl.3 .pl.4 .pl.1:
51	@echo "${CMT2DOC} ${.IMPSRC} > ${.TARGET:T}"
52	@${CMT2DOC} ${CMT2DOC_OPTS} ${.IMPSRC} > ${.TARGET:T} || ( rm -f ${.TARGET:T} ; false )
53.else
54MAN=
55.endif
56.endif
57.endif
58
59_mandir=${DESTDIR}${MANDIR}/${MANTARGET}`echo $$page | sed -e 's/.*\.cat/./' -e 's/.*\.//'`
60.if ${MANTARGET} == "cat"
61_mfromdir?=.
62MANALL=	${MAN:S/.1$/.cat1/g:S/.2$/.cat2/g:S/.3$/.cat3/g:S/.4$/.cat4/g:S/.5$/.cat5/g:S/.6$/.cat6/g:S/.7$/.cat7/g:S/.8$/.cat8/g:S/.9$/.cat9/g}
63.if ${MCATEXT} == ""
64_minstpage=`echo $$page | sed 's/\.cat/./'`
65.else
66_minstpage=`echo $$page | sed 's/\.cat.*//'`${MCATEXT}
67.endif
68.endif
69.if target(${MAN:[1]})
70_mfromdir?=.
71.endif
72_mfromdir?=${.CURDIR}
73MANALL?= ${MAN}
74_minstpage?=$${page}
75.endif
76
77.if !empty(MANOWN)
78MAN_INSTALL_OWN ?= -o ${MANOWN} -g ${MANGRP}
79MAN_CHOWN ?= chown
80.else
81MAN_CHOWN = :
82.endif
83
84MINSTALL=	${INSTALL} ${COPY} ${MAN_INSTALL_OWN} -m ${MANMODE}
85.if defined(MANZ)
86# chown and chmod are done afterward automatically
87MCOMPRESS=	gzip -cf
88MCOMPRESSSUFFIX= .gz
89.endif
90
91maninstall:
92.if defined(MANALL) && !empty(MANALL)
93	@for page in ${MANALL:T}; do \
94		test -s ${_mfromdir}/$$page || continue; \
95		dir=${_mandir}; \
96		test -d $$dir || ${INSTALL} -d ${MAN_INSTALL_OWN} -m 775 $$dir; \
97		instpage=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \
98		if [ X"${MCOMPRESS}" = X ]; then \
99			echo ${MINSTALL} ${_mfromdir}/$$page $$instpage; \
100			${MINSTALL} ${_mfromdir}/$$page $$instpage; \
101		else \
102			rm -f $$instpage; \
103			echo ${MCOMPRESS} ${_mfromdir}/$$page \> $$instpage; \
104			${MCOMPRESS} ${_mfromdir}/$$page > $$instpage; \
105			${MAN_CHOWN} ${MANOWN}:${MANGRP} $$instpage; \
106			chmod ${MANMODE} $$instpage; \
107		fi \
108	done
109.if defined(MLINKS) && !empty(MLINKS)
110	@set ${MLINKS}; \
111	while test $$# -ge 2; do \
112		page=$$1; \
113		shift; \
114		dir=${_mandir}; \
115		l=${_minstpage}${MCOMPRESSSUFFIX}; \
116		page=$$1; \
117		shift; \
118		dir=${_mandir}; \
119		t=$${dir}${MANSUBDIR}/${_minstpage}${MCOMPRESSSUFFIX}; \
120		echo $$t -\> $$l; \
121		rm -f $$t; \
122		ln -s $$l $$t; \
123	done
124.endif
125.endif
126
127.if defined(MANALL) && !empty(MANALL)
128manall: ${MANALL}
129all: manall
130.endif
131
132.if defined(CLEANMAN) && !empty(CLEANMAN)
133cleandir: cleanman
134cleanman:
135	rm -f ${CLEANMAN}
136.endif
137.endif
138