xref: /freebsd/share/mk/bsd.man.mk (revision 3e0f6b97b257a96f7275e4442204263e44b16686)
1#	$FreeBSD$
2#
3# The include file <bsd.man.mk> handles installing manual pages and
4# their links. <bsd.man.mk> includes the file named "../Makefile.inc"
5# if it exists.
6#
7#
8# +++ variables +++
9#
10# DESTDIR	Change the tree where the man pages gets installed. [not set]
11#
12# MANDIR	Base path for manual installation. [${SHAREDIR}/man/man]
13#
14# MANOWN	Manual owner. [${SHAREOWN}]
15#
16# MANGRP	Manual group. [${SHAREGRP}]
17#
18# MANMODE	Manual mode. [${NOBINMODE}]
19#
20# MANSUBDIR	Subdirectory under the manual page section, i.e. "/i386"
21#		or "/tahoe" for machine specific manual pages.
22#
23# MAN${sect}	The manual pages to be installed. For sections see
24#		variable ${SECTIONS}
25#
26# _MANPAGES	List of all man pages to be installed.
27#		(``_MANPAGES=$MAN1 $MAN2 ... $MANn'')
28#
29# MCOMPRESS	Program to compress man pages. Output is to
30#		stdout. [gzip -c]
31#
32# MLINKS	List of manual page links (using a suffix). The
33#		linked-to file must come first, the linked file
34#		second, and there may be multiple pairs. The files
35#		are hard-linked.
36#
37# NOMANCOMPRESS	If you do not want unformatted manual pages to be
38#		compressed when they are installed. [not set]
39#
40# NOMLINKS	If you do not want install manual page links. [not set]
41#
42# MANFILTER	command to pipe the raw man page though before compressing
43#		or installing.  Can be used to do sed substitution.
44#
45# +++ targets +++
46#
47#	maninstall:
48#		Install the manual pages and their links.
49#
50
51
52.if exists(${.CURDIR}/../Makefile.inc)
53.include "${.CURDIR}/../Makefile.inc"
54.endif
55
56MANSRC?=	${.CURDIR}
57MINSTALL=	${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
58
59MCOMPRESS=	gzip -c
60ZEXTENSION=	.gz
61
62SECTIONS=	1 2 3 4 5 6 7 8 9 n
63
64.undef _MANPAGES
65.for sect in ${SECTIONS}
66.if defined(MAN${sect}) && !empty(MAN${sect})
67.SUFFIXES: .${sect}
68.PATH.${sect}: ${MANSRC}
69_MANPAGES+= ${MAN${sect}}
70.endif
71.endfor
72
73all-man: ${MANDEPEND}
74
75.if defined(NOMANCOMPRESS)
76
77COPY=		-c
78
79# Make special arrangements to filter to a temporary file at build time
80# for NOMANCOMPRESS.
81.if defined(MANFILTER)
82FILTEXTENSION=		.filt
83.else
84FILTEXTENSION=
85.endif
86
87ZEXT=
88
89.if defined(MANFILTER)
90.for sect in ${SECTIONS}
91.if defined(MAN${sect}) && !empty(MAN${sect})
92CLEANFILES+=	${MAN${sect}:T:S/$/${FILTEXTENSION}/g}
93.for page in ${MAN${sect}}
94.for target in ${page:T:S/$/${FILTEXTENSION}/g}
95all-man: ${target}
96${target}: ${page}
97	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
98.endfor
99.endfor
100.endif
101.endfor
102.endif
103
104.else
105
106ZEXT=		${ZEXTENSION}
107
108.for sect in ${SECTIONS}
109.if defined(MAN${sect}) && !empty(MAN${sect})
110CLEANFILES+=	${MAN${sect}:T:S/$/${ZEXTENSION}/g}
111.for page in ${MAN${sect}}
112.for target in ${page:T:S/$/${ZEXTENSION}/}
113all-man: ${target}
114${target}: ${page}
115.if defined(MANFILTER)
116	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS} > ${.TARGET}
117.else
118	${MCOMPRESS} ${.ALLSRC} > ${.TARGET}
119.endif
120.endfor
121.endfor
122.endif
123.endfor
124
125.endif
126
127maninstall::
128.for sect in ${SECTIONS}
129.if defined(MAN${sect}) && !empty(MAN${sect})
130maninstall:: ${MAN${sect}}
131.if defined(NOMANCOMPRESS)
132.if defined(MANFILTER)
133.for page in ${MAN${sect}}
134	${MINSTALL} ${page:T:S/$/${FILTEXTENSION}/g} ${DESTDIR}${MANDIR}${sect}${MANSUBDIR}/${page}
135.endfor
136.else
137	${MINSTALL} ${.ALLSRC} ${DESTDIR}${MANDIR}${sect}${MANSUBDIR}
138.endif
139.else
140	${MINSTALL} ${.ALLSRC:T:S/$/${ZEXTENSION}/g} \
141		${DESTDIR}${MANDIR}${sect}${MANSUBDIR}
142.endif
143.endif
144.endfor
145
146.if !defined(NOMLINKS) && defined(MLINKS) && !empty(MLINKS)
147	@set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
148	while : ; do \
149		case $$# in \
150			0) break;; \
151			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
152		esac; \
153		name=$$1; shift; sect=$$1; shift; \
154		l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
155		name=$$1; shift; sect=$$1; shift; \
156		t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
157		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
158		rm -f $${t} $${t}${ZEXTENSION}; \
159		ln $${l}${ZEXT} $${t}${ZEXT}; \
160	done
161.endif
162