xref: /freebsd/share/mk/bsd.doc.mk (revision 198637a6869c703c2d01cd87e222c1dc3761c853)
1# The include file <bsd.doc.mk> handles installing BSD troff documents.
2#
3#
4# +++ variables +++
5#
6# DCOMPRESS_CMD	Program to compress troff documents.  Output is to stdout.
7#		[${COMPRESS_CMD}]
8#
9# DESTDIR	Change the tree where the documents get installed.  [not set]
10#
11# DOC		Document name.  [paper]
12#
13# EXTRA		Extra files (not SRCS) that make up the document.  [not set]
14#
15# LPR		Printer command.  [lpr]
16#
17# MACROS	Macro packages used to build the document.  [not set]
18#
19# WITHOUT_DOCCOMPRESS If you do not want formatted troff documents to be
20#		compressed when they are installed.  [not set]
21#
22# PRINTERDEVICE	Indicates which output formats will be generated
23#		(ascii, ps, html).  [ascii]
24#
25# SRCDIR	Directory where source files live.  [${.CURDIR}]
26#
27# SRCS		List of source files.  [not set]
28#
29# TRFLAGS	Additional flags to groff(1).  [not set]
30#
31# USE_EQN	If set, preprocess with eqn(1).  [not set]
32#
33# USE_PIC	If set, preprocess with pic(1).  [not set]
34#
35# USE_REFER	If set, preprocess with refer(1).  [not set]
36#
37# USE_SOELIM	If set, preprocess with soelim(1).  [not set]
38#
39# USE_TBL	If set, preprocess with tbl(1).  [not set]
40#
41# VOLUME	Volume the document belongs to.  [not set]
42
43.include <bsd.init.mk>
44
45PRINTERDEVICE?=	ascii
46
47BIB?=		bib
48GREMLIN?=	grn
49INDXBIB?=	indxbib
50PIC?=		pic
51REFER?=		refer
52.for _dev in ${PRINTERDEVICE:Mascii}
53ROFF.ascii?=	groff -Tascii -P-c ${TRFLAGS} -mtty-char ${MACROS} ${PAGES:C/^/-o/1}
54.endfor
55.for _dev in ${PRINTERDEVICE:Nascii}
56ROFF.${_dev}?=	groff -T${_dev} ${TRFLAGS} ${MACROS} ${PAGES:C/^/-o/1}
57.endfor
58SOELIM?=	soelim
59TBL?=		tbl
60
61DOC?=		paper
62LPR?=		lpr
63
64.if defined(USE_EQN)
65TRFLAGS+=	-e
66.endif
67.if defined(USE_PIC)
68TRFLAGS+=	-p
69.endif
70.if defined(USE_REFER)
71TRFLAGS+=	-R
72.endif
73.if defined(USE_SOELIM)
74TRFLAGS+=	-I${.CURDIR}
75.endif
76.if defined(USE_TBL)
77TRFLAGS+=	-t
78.endif
79
80.if defined(NO_ROOT)
81.if !defined(TAGS) || ! ${TAGS:Mpackage=*}
82TAGS+=		package=${PACKAGE:Uutilities}
83.endif
84TAG_ARGS=	-T ${TAGS:ts,:[*]}
85.endif
86
87DCOMPRESS_EXT?=	${COMPRESS_EXT}
88DCOMPRESS_CMD?=	${COMPRESS_CMD}
89.for _dev in ${PRINTERDEVICE:Mhtml}
90DFILE.html=	${DOC}.html
91.endfor
92.for _dev in ${PRINTERDEVICE:Nhtml}
93.if ${MK_DOCCOMPRESS} == "no"
94DFILE.${_dev}=	${DOC}.${_dev}
95.else
96DFILE.${_dev}=	${DOC}.${_dev}${DCOMPRESS_EXT}
97.endif
98.endfor
99
100UNROFF?=	unroff
101HTML_SPLIT?=	yes
102UNROFFFLAGS?=	-fhtml
103.if ${HTML_SPLIT} == "yes"
104UNROFFFLAGS+=	split=1
105.endif
106
107# Compatibility mode flag for groff.  Use this when formatting documents with
108# Berkeley me macros (orig_me(7)).
109COMPAT?=	-C
110
111.PATH: ${.CURDIR} ${SRCDIR}
112
113.if !defined(_SKIP_BUILD)
114.for _dev in ${PRINTERDEVICE}
115all: ${DFILE.${_dev}}
116.endfor
117.endif
118
119.if !target(print)
120.for _dev in ${PRINTERDEVICE}
121print: ${DFILE.${_dev}}
122.endfor
123print:
124.for _dev in ${PRINTERDEVICE}
125.if ${MK_DOCCOMPRESS} == "no"
126	${LPR} ${DFILE.${_dev}}
127.else
128	${DCOMPRESS_CMD} -d ${DFILE.${_dev}} | ${LPR}
129.endif
130.endfor
131.endif
132
133.for _dev in ${PRINTERDEVICE:Nascii:Nps:Nhtml}
134CLEANFILES+=	${DOC}.${_dev} ${DOC}.${_dev}${DCOMPRESS_EXT}
135.endfor
136CLEANFILES+=	${DOC}.ascii ${DOC}.ascii${DCOMPRESS_EXT} \
137		${DOC}.ps ${DOC}.ps${DCOMPRESS_EXT} \
138		${DOC}.html ${DOC}-*.html
139
140realinstall:
141.if ${PRINTERDEVICE:Mhtml}
142	cd ${SRCDIR}; \
143	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
144	    ${DOC}*.html ${DESTDIR}${BINDIR}/${VOLUME}/
145.endif
146.for _dev in ${PRINTERDEVICE:Nhtml}
147	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},docs} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
148	    ${DFILE.${_dev}} ${DESTDIR}${BINDIR}/${VOLUME}/
149.endfor
150
151spell: ${SRCS}
152	(cd ${.CURDIR}; spell ${SRCS} ) | sort | \
153		comm -23 - ${.CURDIR}/spell.ok > ${DOC}.spell
154
155BINDIR?=	/usr/share/doc
156BINMODE=	444
157
158SRCDIR?=	${.CURDIR}
159
160.if defined(EXTRA) && !empty(EXTRA)
161_stamp.extra: ${EXTRA}
162	touch ${.TARGET}
163.endif
164
165CLEANFILES+=	_stamp.extra
166.for _dev in ${PRINTERDEVICE:Nhtml}
167.if !target(${DFILE.${_dev}})
168.if target(_stamp.extra)
169${DFILE.${_dev}}: _stamp.extra
170.endif
171${DFILE.${_dev}}: ${SRCS}
172.if ${MK_DOCCOMPRESS} == "no"
173	${ROFF.${_dev}} ${.ALLSRC:N_stamp.extra} > ${.TARGET}
174.else
175	${ROFF.${_dev}} ${.ALLSRC:N_stamp.extra} | ${DCOMPRESS_CMD} > ${.TARGET}
176.endif
177.endif
178.endfor
179
180.for _dev in ${PRINTERDEVICE:Mhtml}
181.if !target(${DFILE.html})
182.if target(_stamp.extra)
183${DFILE.html}: _stamp.extra
184.endif
185${DFILE.html}: ${SRCS}
186.if defined(MACROS) && !empty(MACROS)
187	cd ${SRCDIR}; ${UNROFF} ${MACROS} ${UNROFFFLAGS} \
188	    document=${DOC} ${SRCS}
189.else # unroff(1) requires a macro package as an argument
190	cd ${SRCDIR}; ${UNROFF} -ms ${UNROFFFLAGS} \
191	    document=${DOC} ${SRCS}
192.endif
193.endif
194.endfor
195
196DISTRIBUTION?=	doc
197
198.include <bsd.obj.mk>
199