summaryrefslogtreecommitdiff
path: root/share/mk/bsd.doc.mk
blob: ef3e49f255d31494d8ed3171aec8cc624579fb80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#	$NetBSD: bsd.doc.mk,v 1.68 2015/08/04 08:36:14 dholland Exp $
#	@(#)bsd.doc.mk	8.1 (Berkeley) 8/14/93

.include <bsd.init.mk>

# The makefile should set these:
#   SECTION		one of usd, smm, or psd (lower-case)
#   ARTICLE		name of this document
#   SRCS		roff source files
#   DEPSRCS		additional roff source files implicitly included
#   MACROS		name(s) of roff macro packages, including the -m
#   ROFF_PIC		set to "yes" to use pic(1)
#   ROFF_EQN		set to "yes" to use eqn(1)
#   ROFF_TBL		set to "yes" to use tbl(1)
#   ROFF_REFER		set to "yes" to use refer(1)
#   EXTRAHTMLFILES	additional files emitted as part of HTML build
#
#   PAGES		unknown (XXX)
#   EXTRA		extra files to install (XXX)
#
# If there are multiple docs to be generated, set these:
#   SUBARTICLES=	name1 name2 ...
#   SRCS.name1=		roff source files
#   SRCS.name2=		more roff source files
#   SRCS.  :  =		  :
#   DEPSRCS.name1=	additional included roff source files
#   DEPSRCS.name2=	more additional included roff source files
#   DEPSRCS.  :  =	  :
#
# I'm hoping that MACROS and ROFF_* can be uniform across all
# subarticles.


# Old bsd.doc.mk files tend to invoke tbl and other preprocessors
# directly; they should be changed to set ROFF_* instead.
#
# Also they set e.g. DIR=usd/72.mydocument; this should be changed
# to SECTION=usd and ARTICLE=mydocument. The article numbers are
# no longer present in the file system and do not need to be known
# at build time.
#

# 20130908 dholland: Make sure all makefiles have been converted to the
# new scheme.
.if !defined(SECTION)
.error "bsd.doc.mk: SECTION must be defined"
.endif
.if target(paper.ps)
.error "bsd.doc.mk: target(paper.ps) is true -- this is not allowed"
.endif

# 20130908 dholland: right now we cannot generate pdf from roff sources,
# so build compressed postscript instead. XXX. (and: yech)
TOOL_ROFF_PDF?=false "No roff pdf support"
PRINTABLE=ps.gz
#PRINTABLE=ps
#PRINTABLE=pdf

# If there aren't subarticles, we generate one doc that has the same
# name as the top-level article.
SUBARTICLES?=${ARTICLE}
SRCS.${ARTICLE}?=${SRCS}
DEPSRCS.${ARTICLE}?=${DEPSRCS}

##### Build

.for SA in ${SUBARTICLES}
.if ${MKDOC} != "no"
realall: ${SA}.txt
realall: ${SA}.${PRINTABLE}
.if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
realall: ${SA}.html
.endif
.endif
.endfor # SUBARTICLES

.if defined(ROFF_PIC) && ${ROFF_PIC} != "no"
ROFFFLAGS+=-p
.endif
.if defined(ROFF_EQN) && ${ROFF_EQN} != "no"
ROFFFLAGS+=-e
.endif
.if defined(ROFF_TBL) && ${ROFF_TBL} != "no"
ROFFFLAGS+=-t
.endif
.if defined(ROFF_REFER) && ${ROFF_REFER} != "no"
ROFFFLAGS+=-R
.endif
ROFFFLAGS+=-I${.CURDIR}

.for SA in ${SUBARTICLES}

#
# Find the sources.
#
# We can't use .IMPSRC in the rules because they aren't suffix rules
# (they could be for some docs, but not others) and we can't use
# .ALLSRC because that includes DEPSRCS.
#
# As far as I know, the only ways to get the path discovered via .PATH
# are those two magic variables or the P modifier.
#
# For some reason the P modifier finds the path to a variable name,
# not the path to a word in a variable.
#

.for S in ${SRCS.${SA}}
SRCS2.${SA}+=${${S}:P}
.endfor
.for S in ${DEPSRCS.${SA}}
DEPSRCS2.${SA}+=${${S}:P}
.endfor

#
# Note: we use TOOL_ROFF_DOCASCII because TOOL_ROFF_ASCII invokes
# the nroff wrapper instead of groff directly, and that doesn't
# understand -I.
#
# We use TOOL_ROFF_DOCHTML because TOOL_ROFF_HTML uses -mdoc2html,
# which is great if it works but doesn't work with at least some of
# the non-mdoc docs. (e.g. the curses one) TOOL_ROFF_DOCHTML uses
# groff -Thtml, which produces fairly blah output but works with these
# docs. It might end up being necessary to choose one or the other on
# a per-document basis... sigh.
#

${SA}.txt: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
	${_MKTARGET_FORMAT}
	${TOOL_ROFF_DOCASCII} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
		> ${.TARGET}

${SA}.ps: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
	${_MKTARGET_FORMAT}
	${TOOL_ROFF_PS} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
		| ${TOOL_SED} -e '/^%%CreationDate:/d' \
		> ${.TARGET}

${SA}.pdf: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
	${_MKTARGET_FORMAT}
	${TOOL_ROFF_PDF} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
		> ${.TARGET}

${SA}.html: ${SRCS2.${SA}} ${DEPSRCS2.${SA}}
	${_MKTARGET_FORMAT}
	${TOOL_ROFF_DOCHTML} ${ROFFFLAGS} ${MACROS} ${PAGES} ${SRCS2.${SA}} \
		-P -I -P ${SA} \
		> ${.TARGET}

${SA}.ps.gz: ${SA}.ps
	${TOOL_GZIP} -9 -c -n ${.ALLSRC} > ${.TARGET}

.endfor # SUBARTICLES

##### Install

DOCINST:=
.for SA in ${SUBARTICLES}
DOCINST+=${SA}.txt ${SA}.${PRINTABLE}
.if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
DOCINST+=${SA}.html
.endif
.endfor
.if ${MKHTML} != "no" && ${MKGROFFHTMLDOC} != "no"
DOCINST+=${EXTRAHTMLFILES}
.endif

.if ${MKDOC} != "no"
docinstall:
.for D in ${DOCINST}
	${_MKTARGET_INSTALL}
	${INSTALL_FILE} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} ${D} \
		${DESTDIR}${DOCDIR}/${SECTION}/${ARTICLE}/${D}
.endfor
.else
docinstall: ;
.endif

.PHONY: docinstall
realinstall: docinstall

##### Clean

cleandoc:
.for SA in ${SUBARTICLES}
	rm -f ${SA}.txt ${SA}.ps ${SA}.ps.gz ${SA}.html
.endfor
	rm -f ${EXTRAHTMLFILES} [eE]rrs mklog ${CLEANFILES}

.PHONY: cleandoc
clean: cleandoc

##### Extra custom rules

.if !target(print)
print: ;
.PHONY: print
.for SA in ${SUBARTICLES}
print: print.${SA}
.PHONY: print.{SA}
print.${SA}: ${SA}.ps
	lpr -P${PRINTER} ${.ALLSRC}
.endfor
.endif

spell: ;
.PHONY: spell
.for SA in ${SUBARTICLES}
spell: spell.${SA}
.PHONY: spell.{SA}
spell.${SA}: ${SRCS2} ${DEPSRCS2}
	spell ${SRCS2} | sort | comm -23 - spell.ok > paper.spell
.endfor

##### Pull in related .mk logic

.include <bsd.obj.mk>
.include <bsd.sys.mk>

${TARGETS}:	# ensure existence