Sync with cat.c from netbsd-8
[minix3.git] / share / mk / bsd.doc.mk
blobef3e49f255d31494d8ed3171aec8cc624579fb80
1 # $NetBSD: bsd.doc.mk,v 1.68 2015/08/04 08:36:14 dholland Exp $
2 # @(#)bsd.doc.mk 8.1 (Berkeley) 8/14/93
4 .include <bsd.init.mk>
6 # The makefile should set these:
7 # SECTION one of usd, smm, or psd (lower-case)
8 # ARTICLE name of this document
9 # SRCS roff source files
10 # DEPSRCS additional roff source files implicitly included
11 # MACROS name(s) of roff macro packages, including the -m
12 # ROFF_PIC set to "yes" to use pic(1)
13 # ROFF_EQN set to "yes" to use eqn(1)
14 # ROFF_TBL set to "yes" to use tbl(1)
15 # ROFF_REFER set to "yes" to use refer(1)
16 # EXTRAHTMLFILES additional files emitted as part of HTML build
18 # PAGES unknown (XXX)
19 # EXTRA extra files to install (XXX)
21 # If there are multiple docs to be generated, set these:
22 # SUBARTICLES= name1 name2 ...
23 # SRCS.name1= roff source files
24 # SRCS.name2= more roff source files
25 # SRCS. : = :
26 # DEPSRCS.name1= additional included roff source files
27 # DEPSRCS.name2= more additional included roff source files
28 # DEPSRCS. : = :
30 # I'm hoping that MACROS and ROFF_* can be uniform across all
31 # subarticles.
34 # Old bsd.doc.mk files tend to invoke tbl and other preprocessors
35 # directly; they should be changed to set ROFF_* instead.
37 # Also they set e.g. DIR=usd/72.mydocument; this should be changed
38 # to SECTION=usd and ARTICLE=mydocument. The article numbers are
39 # no longer present in the file system and do not need to be known
40 # at build time.
43 # 20130908 dholland: Make sure all makefiles have been converted to the
44 # new scheme.
45 .if !defined(SECTION)
46 .error "bsd.doc.mk: SECTION must be defined"
47 .endif
48 .if target(paper.ps)
49 .error "bsd.doc.mk: target(paper.ps) is true -- this is not allowed"
50 .endif
52 # 20130908 dholland: right now we cannot generate pdf from roff sources,
53 # so build compressed postscript instead. XXX. (and: yech)
54 TOOL_ROFF_PDF?=false "No roff pdf support"
55 PRINTABLE=ps.gz
56 #PRINTABLE=ps
57 #PRINTABLE=pdf
59 # If there aren't subarticles, we generate one doc that has the same
60 # name as the top-level article.
61 SUBARTICLES?=${ARTICLE}
62 SRCS.${ARTICLE}?=${SRCS}
63 DEPSRCS.${ARTICLE}?=${DEPSRCS}
65 ##### Build
67 .for SA in ${SUBARTICLES}
68 .if ${MKDOC} != "no"
69 realall: ${SA}.txt
70 realall: ${SA}.${PRINTABLE}
71 .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
72 realall: ${SA}.html
73 .endif
74 .endif
75 .endfor # SUBARTICLES
77 .if defined(ROFF_PIC) && ${ROFF_PIC} != "no"
78 ROFFFLAGS+=-p
79 .endif
80 .if defined(ROFF_EQN) && ${ROFF_EQN} != "no"
81 ROFFFLAGS+=-e
82 .endif
83 .if defined(ROFF_TBL) && ${ROFF_TBL} != "no"
84 ROFFFLAGS+=-t
85 .endif
86 .if defined(ROFF_REFER) && ${ROFF_REFER} != "no"
87 ROFFFLAGS+=-R
88 .endif
89 ROFFFLAGS+=-I${.CURDIR}
91 .for SA in ${SUBARTICLES}
94 # Find the sources.
96 # We can't use .IMPSRC in the rules because they aren't suffix rules
97 # (they could be for some docs, but not others) and we can't use
98 # .ALLSRC because that includes DEPSRCS.
100 # As far as I know, the only ways to get the path discovered via .PATH
101 # are those two magic variables or the P modifier.
103 # For some reason the P modifier finds the path to a variable name,
104 # not the path to a word in a variable.
107 .for S in ${SRCS.${SA}}
108 SRCS2.${SA}+=${${S}:P}
109 .endfor
110 .for S in ${DEPSRCS.${SA}}
111 DEPSRCS2.${SA}+=${${S}:P}
112 .endfor
115 # Note: we use TOOL_ROFF_DOCASCII because TOOL_ROFF_ASCII invokes
116 # the nroff wrapper instead of groff directly, and that doesn't
117 # understand -I.
119 # We use TOOL_ROFF_DOCHTML because TOOL_ROFF_HTML uses -mdoc2html,
120 # which is great if it works but doesn't work with at least some of
121 # the non-mdoc docs. (e.g. the curses one) TOOL_ROFF_DOCHTML uses
122 # groff -Thtml, which produces fairly blah output but works with these
123 # docs. It might end up being necessary to choose one or the other on
124 # a per-document basis... sigh.
127 ${SA}.txt: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
128 ${_MKTARGET_FORMAT}
129 ${TOOL_ROFF_DOCASCII} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
130 > ${.TARGET}
132 ${SA}.ps: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
133 ${_MKTARGET_FORMAT}
134 ${TOOL_ROFF_PS} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
135 | ${TOOL_SED} -e '/^%%CreationDate:/d' \
136 > ${.TARGET}
138 ${SA}.pdf: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
139 ${_MKTARGET_FORMAT}
140 ${TOOL_ROFF_PDF} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
141 > ${.TARGET}
143 ${SA}.html: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
144 ${_MKTARGET_FORMAT}
145 ${TOOL_ROFF_DOCHTML} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
146 -P -I -P ${SA} \
147 > ${.TARGET}
149 ${SA}.ps.gz: ${SA}.ps
150 ${TOOL_GZIP} -9 -c -n ${.ALLSRC} > ${.TARGET}
152 .endfor # SUBARTICLES
154 ##### Install
156 DOCINST:=
157 .for SA in ${SUBARTICLES}
158 DOCINST+=${SA}.txt ${SA}.${PRINTABLE}
159 .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
160 DOCINST+=${SA}.html
161 .endif
162 .endfor
163 .if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
164 DOCINST+=${EXTRAHTMLFILES}
165 .endif
167 .if ${MKDOC} != "no"
168 docinstall:
169 .for D in ${DOCINST}
170 ${_MKTARGET_INSTALL}
171 ${INSTALL_FILE} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} ${D} \
172 ${DESTDIR}${DOCDIR}/${SECTION}/${ARTICLE}/${D}
173 .endfor
174 .else
175 docinstall: ;
176 .endif
178 .PHONY: docinstall
179 realinstall: docinstall
181 ##### Clean
183 cleandoc:
184 .for SA in ${SUBARTICLES}
185 rm -f ${SA}.txt ${SA}.ps ${SA}.ps.gz ${SA}.html
186 .endfor
187 rm -f ${EXTRAHTMLFILES} [eE]rrs mklog ${CLEANFILES}
189 .PHONY: cleandoc
190 clean: cleandoc
192 ##### Extra custom rules
194 .if !target(print)
195 print: ;
196 .PHONY: print
197 .for SA in ${SUBARTICLES}
198 print: print.${SA}
199 .PHONY: print.{SA}
200 print.${SA}: ${SA}.ps
201 lpr -P${PRINTER} ${.ALLSRC}
202 .endfor
203 .endif
205 spell: ;
206 .PHONY: spell
207 .for SA in ${SUBARTICLES}
208 spell: spell.${SA}
209 .PHONY: spell.{SA}
210 spell.${SA}: ${SRCS2} ${DEPSRCS2}
211 spell ${SRCS2} | sort | comm -23 - spell.ok > paper.spell
212 .endfor
214 ##### Pull in related .mk logic
216 .include <bsd.obj.mk>
217 .include <bsd.sys.mk>
219 ${TARGETS}: # ensure existence