xref: /dragonfly/share/mk/bsd.man.mk (revision e682b62b)
1# $FreeBSD: src/share/mk/bsd.man.mk,v 1.31.2.11 2002/12/19 13:48:33 ru Exp $
2#
3# The include file <bsd.man.mk> handles installing manual pages and
4# their links.
5#
6#
7# +++ variables +++
8#
9# DESTDIR	Change the tree where the man pages gets installed. [not set]
10#
11# MANDIR	Base path for manual installation. [${SHAREDIR}/man/man]
12#
13# MANOWN	Manual owner. [${SHAREOWN}]
14#
15# MANGRP	Manual group. [${SHAREGRP}]
16#
17# MANMODE	Manual mode. [${NOBINMODE}]
18#
19# MANSUBDIR	Subdirectory under the manual page section, i.e. "/i386"
20#		or "/tahoe" for machine specific manual pages.
21#
22# MAN		The manual pages to be installed. For sections see
23#		variable ${SECTIONS}
24#
25# MCOMPRESS_CMD	Program to compress man pages. Output is to
26#		stdout. [${COMPRESS_CMD}]
27#
28# MLINKS	List of manual page links (using a suffix). The
29#		linked-to file must come first, the linked file
30#		second, and there may be multiple pairs. The files
31#		are hard-linked.
32#
33# NOMANCOMPRESS	If you do not want unformatted manual pages to be
34#		compressed when they are installed. [not set]
35#
36# NOMLINKS	If you do not want install manual page links. [not set]
37#
38# MANFILTER	command to pipe the raw man page through before compressing
39#		or installing.  Can be used to do sed substitution.
40#
41# MANBUILDCAT	create preformatted manual pages in addition to normal
42#		pages. [not set]
43#
44# MANDOC_CMD	command and flags to create preformatted pages
45# MROFF_CMD	groff command for manlint and mandiff
46#
47# +++ targets +++
48#
49#	maninstall:
50#		Install the manual pages and their links.
51#
52
53.if !target(__<bsd.init.mk>__)
54.error bsd.man.mk cannot be included directly.
55.endif
56
57_MANINSTALLFLAGS:= ${MANINSTALLFLAGS}
58
59MINSTALL?=	${INSTALL} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE} \
60		${_MANINSTALLFLAGS}
61
62CATDIR=		${MANDIR:H:S/$/\/cat/}
63CATEXT=		.cat
64MANDOC_CMD?=	mandoc -Tascii
65MROFF_CMD?=	groff -Tascii -mtty-char -man -t
66
67MCOMPRESS_CMD?=	${COMPRESS_CMD}
68MCOMPRESS_EXT?=	${COMPRESS_EXT}
69
70SECTIONS=	1 2 3 4 5 6 7 8 9
71.SUFFIXES:	${SECTIONS:S/^/./g}
72
73# Backwards compatibility.
74.if !defined(MAN)
75.for sect in ${SECTIONS}
76.if defined(MAN${sect}) && !empty(MAN${sect})
77MAN+=	${MAN${sect}}
78.endif
79.endfor
80.endif
81
82_manpages:
83all-man: _manpages
84
85.if defined(NOMANCOMPRESS)
86
87# Make special arrangements to filter to a temporary file at build time
88# for NOMANCOMPRESS.
89.if defined(MANFILTER)
90FILTEXTENSION=		.filt
91.else
92FILTEXTENSION=
93.endif
94
95ZEXT=
96
97.if defined(MANFILTER)
98.if defined(MAN) && !empty(MAN)
99CLEANFILES+=	${MAN:T:S/$/${FILTEXTENSION}/g}
100CLEANFILES+=	${MAN:T:S/$/${CATEXT}${FILTEXTENSION}/g}
101.for page in ${MAN}
102.for target in ${page:T:S/$/${FILTEXTENSION}/g}
103_manpages: ${target}
104${target}: ${page}
105	${MANFILTER} < ${.ALLSRC} > ${.TARGET}
106.endfor
107.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
108.for target in ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g}
109_manpages: ${target}
110${target}: ${page}
111	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} > ${.TARGET}
112.endfor
113.endif
114.endfor
115.endif
116.else
117.if defined(MAN) && !empty(MAN)
118CLEANFILES+=	${MAN:T:S/$/${CATEXT}/g}
119.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
120.for page in ${MAN}
121.for target in ${page:T:S/$/${CATEXT}/g}
122_manpages: ${target}
123${target}: ${page}
124	${MANDOC_CMD} ${.ALLSRC} > ${.TARGET}
125.endfor
126.endfor
127.else
128_manpages: ${MAN}
129.endif
130.endif
131.endif
132
133.else
134
135ZEXT=		${MCOMPRESS_EXT}
136
137.if defined(MAN) && !empty(MAN)
138CLEANFILES+=	${MAN:T:S/$/${MCOMPRESS_EXT}/g}
139CLEANFILES+=	${MAN:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g}
140.for page in ${MAN}
141.for target in ${page:T:S/$/${MCOMPRESS_EXT}/}
142_manpages: ${target}
143${target}: ${page}
144.if defined(MANFILTER)
145	${MANFILTER} < ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
146.else
147	${MCOMPRESS_CMD} ${.ALLSRC} > ${.TARGET}
148.endif
149.endfor
150.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
151.for target in ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/}
152_manpages: ${target}
153${target}: ${page}
154.if defined(MANFILTER)
155	${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} | ${MCOMPRESS_CMD} > ${.TARGET}
156.else
157	${MANDOC_CMD} ${.ALLSRC} | ${MCOMPRESS_CMD} > ${.TARGET}
158.endif
159.endfor
160.endif
161.endfor
162.endif
163
164.endif
165
166.if !defined(NOMLINKS) && defined(MLINKS) && !empty(MLINKS)
167.for _oname _osect _dname _dsect in ${MLINKS:C/\.([^.]*)$/.\1 \1/}
168_MANLINKS+=	${MANDIR}${_osect}${MANSUBDIR}/${_oname} \
169		${MANDIR}${_dsect}${MANSUBDIR}/${_dname}
170.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
171_MANLINKS+=	${CATDIR}${_osect}${MANSUBDIR}/${_oname} \
172		${CATDIR}${_dsect}${MANSUBDIR}/${_dname}
173.endif
174.endfor
175.endif
176
177maninstall: _maninstall
178_maninstall:
179.if defined(MAN) && !empty(MAN)
180_maninstall: ${MAN}
181.if defined(NOMANCOMPRESS)
182.if defined(MANFILTER)
183.for page in ${MAN}
184	${MINSTALL} ${page:T:S/$/${FILTEXTENSION}/g} \
185		${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}/${page}
186.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
187	${MINSTALL} ${page:T:S/$/${CATEXT}${FILTEXTENSION}/g} \
188		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page}
189.endif
190.endfor
191.else	# !defined(MANFILTER)
192	@set ${.ALLSRC:C/\.([^.]*)$/.\1 \1/}; \
193	while : ; do \
194		case $$# in \
195			0) break;; \
196			1) echo "warn: missing extension: $$1"; break;; \
197		esac; \
198		page=$$1; shift; sect=$$1; shift; \
199		d=${DESTDIR}${MANDIR}$${sect}${MANSUBDIR}; \
200		${ECHO} ${MINSTALL} $${page} $${d}; \
201		${MINSTALL} $${page} $${d}; \
202	done
203.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
204.for page in ${MAN}
205	${MINSTALL} ${page:T:S/$/${CATEXT}/} \
206		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T}
207.endfor
208.endif
209.endif	# defined(MANFILTER)
210.else	# !defined(NOMANCOMPRESS)
211.for page in ${MAN}
212	${MINSTALL} ${page:T:S/$/${MCOMPRESS_EXT}/g} \
213		${DESTDIR}${MANDIR}${page:E}${MANSUBDIR}
214.if defined(MANBUILDCAT) && !empty(MANBUILDCAT)
215	${MINSTALL} ${page:T:S/$/${CATEXT}${MCOMPRESS_EXT}/g} \
216		${DESTDIR}${CATDIR}${page:E}${MANSUBDIR}/${page:T:S/$/${MCOMPRESS_EXT}/}
217.endif
218.endfor
219.endif	# defined(NOMANCOMPRESS)
220.endif
221.for l t in ${_MANLINKS}
222	@rm -f ${DESTDIR}${t} ${DESTDIR}${t}${MCOMPRESS_EXT}
223	${LN} ${DESTDIR}${l}${ZEXT} ${DESTDIR}${t}${ZEXT}
224.endfor
225
226manlint:
227#mandiff:
228.if defined(MAN) && !empty(MAN)
229.for page in ${MAN}
230manlint: ${page}lint
231#mandiff: ${page}diff
232${page}lint: ${page}
233.if defined(MANFILTER)
234#	@${MANFILTER} < ${.ALLSRC} | ${MROFF_CMD} -ww -z
235	@-${MANFILTER} < ${.ALLSRC} | ${MANDOC_CMD} -Tlint
236.else
237#	@${MROFF_CMD} -ww -z ${.ALLSRC}
238	@-${MANDOC_CMD} -Tlint ${.ALLSRC}
239.endif
240#${page}.out.groff: ${page}
241#	@-${MROFF_CMD} ${.ALLSRC} 2>&1 > ${.TARGET}
242#${page}.out.mandoc: ${page}
243#	@-${MANDOC_CMD} -Werror ${.ALLSRC} 2>&1 > ${.TARGET}
244#${page}diff: ${page}.out.groff ${page}.out.mandoc
245#	@-diff -au ${.ALLSRC}
246#	@rm ${.ALLSRC}
247.endfor
248.endif
249