xref: /freebsd/share/mk/bsd.man.mk (revision e627b39baccd1ec9129690167cf5e6d860509655)
1#	$Id: bsd.man.mk,v 1.15 1996/08/26 10:55:32 peter Exp $
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# MANFILTER	command to pipe the raw man page though before compressing
41#		or installing.  Can be used to do sed substitution.
42#
43# +++ targets +++
44#
45#	maninstall:
46#		Install the manual pages and their links.
47#
48
49
50.if exists(${.CURDIR}/../Makefile.inc)
51.include "${.CURDIR}/../Makefile.inc"
52.endif
53
54MANSRC?=	${.CURDIR}
55MINSTALL=	${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
56
57MCOMPRESS=	gzip -c
58ZEXTENSION=	.gz
59
60SECTIONS=	1 2 3 3f 4 5 6 7 8 9 n
61
62.undef _MANPAGES
63.for sect in ${SECTIONS}
64.if defined(MAN${sect}) && !empty(MAN${sect})
65.SUFFIXES: .${sect}
66.PATH.${sect}: ${MANSRC}
67_MANPAGES+= ${MAN${sect}}
68.endif
69.endfor
70
71all-man: ${MANDEPEND}
72
73.if defined(NOMANCOMPRESS)
74
75COPY=		-c
76
77# Make special arrangements to filter to a temporary file at build time
78# for NOMANCOMPRESS.
79.if defined(MANFILTER)
80FILTEXTENSION=		.filt
81.else
82FILTEXTENSION=
83.endif
84
85ZEXT=
86
87.if defined(MANFILTER)
88.for sect in ${SECTIONS}
89.if defined(MAN${sect}) && !empty(MAN${sect})
90CLEANFILES+=	${MAN${sect}:T:S/$/${FILTEXTENSION}/g}
91.for page in ${MAN${sect}}
92.for target in ${page:T:S/$/${FILTEXTENSION}/g}
93all-man: ${target}
94${target}: ${page}
95	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
96.endfor
97.endfor
98.endif
99.endfor
100.endif
101
102.else
103
104ZEXT=		${ZEXTENSION}
105
106.for sect in ${SECTIONS}
107.if defined(MAN${sect}) && !empty(MAN${sect})
108CLEANFILES+=	${MAN${sect}:T:S/$/${ZEXTENSION}/g}
109.for page in ${MAN${sect}}
110.for target in ${page:T:S/$/${ZEXTENSION}/}
111all-man: ${target}
112${target}: ${page}
113.if defined(MANFILTER)
114	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS} > ${.TARGET}
115.else
116	${MCOMPRESS} ${.ALLSRC} > ${.TARGET}
117.endif
118.endfor
119.endfor
120.endif
121.endfor
122
123.endif
124
125maninstall::
126.for sect in ${SECTIONS}
127.if defined(MAN${sect}) && !empty(MAN${sect})
128maninstall:: ${MAN${sect}}
129.if defined(NOMANCOMPRESS)
130.if defined(MANFILTER)
131.for page in ${MAN${sect}}
132	${MINSTALL} ${page:T:S/$/${FILTEXTENSION}/g} ${DESTDIR}${MANDIR}${sect}${MANSUBDIR}/${page}
133.endfor
134.else
135	${MINSTALL} ${.ALLSRC} ${DESTDIR}${MANDIR}${sect}${MANSUBDIR}
136.endif
137.else
138	${MINSTALL} ${.ALLSRC:T:S/$/${ZEXTENSION}/g} \
139		${DESTDIR}${MANDIR}${sect}${MANSUBDIR}
140.endif
141.endif
142.endfor
143
144.if defined(MLINKS) && !empty(MLINKS)
145	@set `echo ${MLINKS} " " | sed 's/\.\([^.]*\) /.\1 \1 /g'`; \
146	while : ; do \
147		case $$# in \
148			0) break;; \
149			[123]) echo "warn: empty MLINK: $$1 $$2 $$3"; break;; \
150		esac; \
151		name=$$1; shift; sect=$$1; shift; \
152		l=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
153		name=$$1; shift; sect=$$1; shift; \
154		t=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}/$$name; \
155		${ECHO} $${t}${ZEXT} -\> $${l}${ZEXT}; \
156		rm -f $${t} $${t}${ZEXTENSION}; \
157		ln $${l}${ZEXT} $${t}${ZEXT}; \
158	done
159.endif
160