Update to doc to make it build using pkgsrc tools instead of FreeBSD ports.
[dragonfly.git] / share / mk / doc.html.mk
1 #
2 # $DragonFly: doc/share/mk/doc.html.mk,v 1.2 2006/08/06 20:58:06 justin Exp $
3 #
4 # This include file <doc.html.mk> handles building and installing of
5 # HTML documentation in the DragonFlyBSD Documentation Project.
6 #
7 # Documentation using DOCFORMAT=html is expected to be marked up
8 # according to the HTML DTD
9 #
10
11 # ------------------------------------------------------------------------
12 #
13 # Document-specific variables
14 #
15 #       DOC             This should be set to the name of the HTML
16 #                       marked-up file, without the .sgml or .docb suffix.
17 #                       
18 #                       It also determins the name of the output files -
19 #                       ${DOC}.html.
20 #
21 #       DOCBOOKSUFFIX   The suffix of your document, defaulting to .sgml
22 #
23 #       SRCS            The names of all the files that are needed to
24 #                       build this document - This is useful if any of
25 #                       them need to be generated.  Changing any file in
26 #                       SRCS causes the documents to be rebuilt.
27 #
28
29 # ------------------------------------------------------------------------
30 #
31 # Variables used by both users and documents:
32 #
33 #       TIDYFLAGS       Additional flags to pass to Tidy.  Typically
34 #                       used to set "-raw" flag to handle 8bit characters.
35 #
36 #       EXTRA_CATALOGS  Additional catalog files that should be used by
37 #                       any SGML processing applications.
38 #
39 #       NO_TIDY         If you do not want to use tidy, set this to "YES".
40 #
41 # Documents should use the += format to access these.
42 #
43
44 MASTERDOC?=     ${.CURDIR}/${DOC}.sgml
45
46 KNOWN_FORMATS=  html txt tar pdb
47
48 CSS_SHEET?=
49
50 HTMLCATALOG=    ${PREFIX}/share/sgml/html/catalog
51
52 IMAGES_LIB?=
53
54 .if ${MACHINE_ARCH} != "i386"
55 OPENJADE=       yes
56 .endif
57
58 .if defined(OPENJADE)
59 NSGMLS?=        ${PREFIX}/bin/onsgmls
60 SGMLNORM?=      ${PREFIX}/bin/osgmlnorm
61 .else
62 NSGMLS?=        ${PREFIX}/bin/nsgmls
63 SGMLNORM?=      ${PREFIX}/bin/sgmlnorm
64 .endif
65  
66 PKG_CREATE?=    /usr/sbin/pkg_create
67 TAR?=           /usr/bin/tar
68 XARGS?=         /usr/bin/xargs
69
70 # for now disable TIDY for compatibility reasons
71 NO_TIDY=        YES
72 TIDY?=          ${PREFIX}/bin/tidy
73 TIDYOPTS?=      -i -m -raw -preserve -f /dev/null -asxml ${TIDYFLAGS}
74 HTML2PDB?=      ${PREFIX}/bin/iSiloBSD
75 HTML2PDBOPTS?=  -y -d0 -Idef ${HTML2PDBFLAGS}
76
77 GZIP?=  -9
78 GZIP_CMD?=      gzip -qf ${GZIP}
79 BZIP2?= -9
80 BZIP2_CMD?=     bzip2 -qf ${BZIP2}
81 ZIP?=   -9
82 ZIP_CMD?=       ${PREFIX}/bin/zip -j ${ZIP}
83
84
85 # ------------------------------------------------------------------------
86 #
87
88 .if ${.OBJDIR} != ${.CURDIR}
89 LOCAL_CSS_SHEET=        ${.OBJDIR}/${CSS_SHEET:T}
90 CLEANFILES+=            ${LOCAL_CSS_SHEET}
91 .else
92 LOCAL_CSS_SHEET=        ${CSS_SHEET:T}
93 .endif
94
95 .for _curformat in ${FORMATS}
96 _cf=${_curformat}
97
98 # Create a 'bogus' doc for any format we support or not.  This is so
99 # that we can fake up a target for it later on, and this target can print
100 # the warning message about the unsupported format. 
101 _docs+= ${DOC}.${_curformat}
102 CLEANFILES+= ${DOC}.${_curformat}
103 CLEANFILES+= PLIST.${_curformat}
104
105 .if ${_cf} == "txt"
106 .if ${LOCAL_CSS_SHEET} != ${CSS_SHEET}
107 CLEANFILES+= ${LOCAL_CSS_SHEET}
108 .endif
109
110 .elif ${_cf} == "txt"
111 CLEANFILES+= ${DOC}.html
112
113 .elif ${_cf} == "pdb"
114 _docs+= ${.CURDIR:T}.pdb
115 CLEANFILES+= ${.CURDIR:T}.pdb
116
117 .endif
118 .endfor
119
120 #
121 # Build a list of install-${format}.${compress_format} targets to be
122 # by "make install". Also, add ${DOC}.${format}.${compress_format} to
123 # ${_docs} and ${CLEANFILES} so they get built/cleaned by "all" and
124 # "clean".
125 #
126
127 .if defined(INSTALL_COMPRESSED) && !empty(INSTALL_COMPRESSED)
128 .for _curformat in ${FORMATS}
129 _cf=${_curformat}
130 .for _curcomp in ${INSTALL_COMPRESSED}
131
132 .if ${_cf} != "html-split"
133 _curinst+= install-${_curformat}.${_curcomp}
134 _docs+= ${DOC}.${_curformat}.${_curcomp}
135 CLEANFILES+= ${DOC}.${_curformat}.${_curcomp}
136
137 .if  ${_cf} == "pdb"
138 _docs+= ${.CURDIR:T}.${_curformat}.${_curcomp}
139 CLEANFILES+= ${.CURDIR:T}.${_curformat}.${_curcomp}
140
141 .endif
142 .endif
143 .endfor
144 .endfor
145 .endif
146
147 .MAIN: all
148
149 all: ${_docs}
150
151 ${DOC}.html: ${SRCS} ${LOCAL_IMAGES_LIB} ${LOCAL_IMAGES_PNG} ${LOCAL_CSS_SHEET}
152         ${SGMLNORM} -c ${HTMLCATALOG} ${SRCS:S|^|${.CURDIR}/|} > ${.TARGET}
153 .if !defined(NO_TIDY)
154         -${TIDY} ${TIDYOPTS} ${.TARGET}
155 .endif
156
157 ${DOC}.txt: ${DOC}.html
158         ${HTML2TXT} ${HTML2TXTOPTS} ${.ALLSRC} > ${.TARGET}
159
160 ${DOC}.pdb: ${DOC}.html ${LOCAL_IMAGES_LIB} ${LOCAL_IMAGES_PNG}
161         ${HTML2PDB} ${HTML2PDBOPTS} ${DOC}.html ${.TARGET}
162
163 ${.CURDIR:T}.pdb: ${DOC}.pdb
164         ${LN} -f ${.ALLSRC} ${.TARGET}
165
166 .if defined(INSTALL_COMPRESSED) && !empty(INSTALL_COMPRESSED)
167 .for _curcomp in ${INSTALL_COMPRESSED}
168 ${.CURDIR:T}.pdb.${_curcomp}: ${DOC}.pdb.${_curcomp}
169         ${LN} -f ${.ALLSRC} ${.TARGET}
170 .endfor
171 .endif
172
173 ${DOC}.tar: ${SRCS} ${LOCAL_IMAGES} ${LOCAL_CSS_SHEET}
174         ${TAR} cf ${.TARGET} -C ${.CURDIR} ${SRCS} \
175                 -C ${.OBJDIR} ${IMAGES} ${CSS_SHEET:T}
176
177 #
178 # Build targets for any formats we've missed that we don't handle.
179 #
180 .for _curformat in ${ALL_FORMATS}
181 .if !target(${DOC}.${_curformat})
182 ${DOC}.${_curformat}:
183         @${ECHO_CMD} \"${_curformat}\" is not a valid output format for this document.
184 .endif
185 .endfor
186
187
188 # ------------------------------------------------------------------------
189 #
190 # Validation targets
191 #
192
193 #
194 # Lets you quickly check that the document conforms to the DTD without
195 # having to convert it to any other formats
196 #
197
198 lint validate:
199         ${NSGMLS} -s -c ${HTMLCATALOG} ${MASTERDOC}
200
201
202 # ------------------------------------------------------------------------
203 #
204 # Compress targets
205 #
206
207 #
208 # The list of compression extensions this Makefile knows about. If you
209 # add new compression schemes, add to this list (which is a list of
210 # extensions, hence bz2, *not* bzip2) and extend the _PROG_COMPRESS_*
211 # targets.
212 #
213
214 KNOWN_COMPRESS= gz bz2 zip
215
216 #
217 # You can't build suffix rules to do compression, since you can't
218 # wildcard the source suffix. So these are defined .USE, to be tacked on
219 # as dependencies of the compress-* targets.
220 #
221
222 _PROG_COMPRESS_gz: .USE
223         ${GZIP_CMD} < ${.ALLSRC} > ${.TARGET}
224
225 _PROG_COMPRESS_bz2: .USE
226         ${BZIP2_CMD} < ${.ALLSRC} > ${.TARGET}
227
228 _PROG_COMPRESS_zip: .USE
229         ${ZIP_CMD} ${.TARGET} ${.ALLSRC}
230
231 #
232 # Build a list of targets for each compression scheme and output format.
233 # Don't compress the html-split output format.
234 #
235 .for _curformat in ${KNOWN_FORMATS}
236 _cf=${_curformat}
237 .for _curcompress in ${KNOWN_COMPRESS}
238 ${DOC}.${_cf}.${_curcompress}: ${DOC}.${_cf} _PROG_COMPRESS_${_curcompress}
239 .endfor
240 .endfor
241
242 #
243 # Build targets for any formats we've missed that we don't handle.
244 #
245 .for _curformat in ${ALL_FORMATS}
246 .for _curcompress in ${KNOWN_COMPRESS}
247 .if !target(${DOC}.${_curformat}.${_curcompress})
248 ${DOC}.${_curformat}.${_curcompress}:
249         @${ECHO_CMD} \"${_curformat}.${_curcompress}\" is not a valid output format for this document.
250 .endif
251 .endfor
252 .endfor
253
254
255 # ------------------------------------------------------------------------
256 #
257 # Install targets
258 #
259 # Build install-* targets, one per allowed value in FORMATS.
260 #
261 # "beforeinstall" and "afterinstall" are hooks in to this process.
262 # Redefine them to do things before and after the files are installed,
263 # respectively.
264
265 #
266 # Build a list of install-format targets to be installed. These will be
267 # dependencies for the "realinstall" target.
268 #
269
270 .if !defined(INSTALL_ONLY_COMPRESSED) || empty(INSTALL_ONLY_COMPRESSED)
271 _curinst+= ${FORMATS:S/^/install-/g}
272 .endif
273
274 realinstall: ${_curinst}
275
276 .for _curformat in ${KNOWN_FORMATS}
277 _cf=${_curformat}
278 .if !target(install-${_cf})
279 install-${_curformat}: ${DOC}.${_curformat}
280         @[ -d ${DESTDIR} ] || ${MKDIR} -p ${DESTDIR}
281         ${INSTALL_DOCS} ${.ALLSRC} ${DESTDIR}
282 .if !empty(CSS_SHEET)
283         ${INSTALL_DOCS} ${CSS_SHEET} ${DESTDIR}
284 .endif
285 .for _curimage in ${IMAGES_LIB}
286         @[ -d ${DESTDIR}/${LOCAL_IMAGES_LIB_DIR}/${_curimage:H} ] || \
287                 ${MKDIR} -p ${DESTDIR}/${LOCAL_IMAGES_LIB_DIR}/${_curimage:H}
288         ${INSTALL_DOCS} ${LOCAL_IMAGES_LIB_DIR}/${_curimage} \
289                         ${DESTDIR}/${LOCAL_IMAGES_LIB_DIR}/${_curimage:H}
290 .endfor
291 # Install the images.  First, loop over all the image names that contain a
292 # directory separator, make the subdirectories, and install.  Then loop over
293 # the ones that don't contain a directory separator, and install them in the
294 # top level.
295 .for _curimage in ${IMAGES_PNG:M*/*:M*share*}
296         ${MKDIR} -p ${DESTDIR:H:H}/${_curimage:H:S|${IMAGES_EN_DIR}/||:S|${.CURDIR}||}
297         ${INSTALL_DOCS} ${_curimage} ${DESTDIR:H:H}/${_curimage:H:S|${IMAGES_EN_DIR}/||:S|${.CURDIR}||}
298 .endfor
299 .for _curimage in ${IMAGES_PNG:N*/*}
300         ${INSTALL_DOCS} ${.CURDIR}/${_curimage} ${DESTDIR}
301 .endfor
302 .if ${_cf} == "pdb"
303         ${LN} -f ${DESTDIR}/${.ALLSRC} ${DESTDIR}/${.CURDIR:T}.${_curformat}
304 .endif
305
306 .for _compressext in ${KNOWN_COMPRESS}
307 install-${_cf}.${_compressext}: ${DOC}.${_cf}.${_compressext}
308         @[ -d ${DESTDIR} ] || ${MKDIR} -p ${DESTDIR}
309         ${INSTALL_DOCS} ${.ALLSRC} ${DESTDIR}
310 .endfor
311 .endif
312 .endfor
313
314 #
315 # Build install- targets for any formats we've missed that we don't handle.
316 #
317
318 .for _curformat in ${ALL_FORMATS}
319 .if !target(install-${_curformat})
320 install-${_curformat}:
321         @${ECHO_CMD} \"${_curformat}\" is not a valid output format for this document.
322
323 .for _compressext in ${KNOWN_COMPRESS}
324 install-${_curformat}.${_compressext}:
325         @${ECHO_CMD} \"${_curformat}.${_compressext}\" is not a valid output format for this document.
326 .endfor
327 .endif
328 .endfor
329
330
331 # ------------------------------------------------------------------------
332 #
333 # Package building
334 #
335
336 #
337 # realpackage is what is called in each subdirectory when a package
338 # target is called, or, rather, package calls realpackage in each
339 # subdirectory as it goes.
340 #
341 # packagelist returns the list of targets that would be called during
342 # package building.
343 #
344
345 realpackage: ${FORMATS:S/^/package-/}
346 packagelist:
347         @${ECHO_CMD} ${FORMATS:S/^/package-/}
348
349 #
350 # Build a list of package targets for each output target.  Each package
351 # target depends on the corresponding install target running.
352 #
353
354 .for _curformat in ${KNOWN_FORMATS}
355 _cf=${_curformat}
356 PLIST.${_curformat}: ${DOC}.${_curformat}
357         @${ECHO_CMD} ${DOC}.${_curformat} > PLIST.${_curformat}
358 .if ${_cf} == "html" && \
359     (!empty(LOCAL_IMAGES_LIB) || !empty(IMAGES_PNG) || !empty(CSS_SHEET))
360         @${ECHO_CMD} ${LOCAL_IMAGES_LIB} ${IMAGES_PNG} ${CSS_SHEET} | \
361                 ${XARGS} -n1 >> PLIST.${_curformat}
362 .elif ${_cf} == "pdb"
363         @${ECHO_CMD} ${.CURDIR:T}.${_curformat} >> PLIST.${_curformat}
364 .endif
365
366 ${PACKAGES}/${.CURDIR:T}.${LANGCODE}.${_curformat}.tgz: PLIST.${_curformat}
367         @${PKG_CREATE} -v -f PLIST.${_curformat} -p ${DESTDIR} -s ${.OBJDIR} \
368                 -c -"FDP ${.CURDIR:T} ${_curformat} package" \
369                 -d -"FDP ${.CURDIR:T} ${_curformat} package" ${.TARGET}
370
371 package-${_curformat}: ${PACKAGES}/${.CURDIR:T}.${LANGCODE}.${_curformat}.tgz
372 .endfor
373
374 #
375 # Build install- targets for any formats we've missed that we don't handle.
376 #
377
378 .for _curformat in ${ALL_FORMATS}
379 .if !target(package-${_curformat})
380 package-${_curformat}:
381         @${ECHO_CMD} \"${_curformat}\" is not a valid output format for this document.
382 .endif
383 .endfor
384
385 .if ${LOCAL_CSS_SHEET} != ${CSS_SHEET}
386 ${LOCAL_CSS_SHEET}: ${CSS_SHEET}
387         ${CP} -p ${.ALLSRC} ${.TARGET}
388 .endif