1 # Copyright 2003, 2004, 2005 Dave Abrahams
2 # Copyright 2003, 2004, 2005 Douglas Gregor
3 # Copyright 2005, 2006, 2007 Rene Rivera
4 # Copyright 2003, 2004, 2005 Vladimir Prus
5 # Distributed under the Boost Software License, Version 1.0.
6 # (See accompanying file LICENSE_1_0.txt or copy at
7 # http://www.boost.org/LICENSE_1_0.txt)
9 # This module defines rules to handle generation of documentation from BoostBook
12 # The type of output is controlled by the <format> feature which can have the
14 # * html: Generates html documentation. This is the default.
15 # * xhtml: Generates xhtml documentation.
16 # * htmlhelp: Generates html help output.
17 # * onehtml: Generates a single html page.
18 # * man: Generates man pages.
19 # * pdf: Generates pdf documentation.
20 # * ps: Generates postscript output.
21 # * docbook: Generates docbook XML.
22 # * fo: Generates XSL formating objects.
23 # * tests: Extracts test cases from the boostbook XML.
25 # <format> is an implicit feature, so for example, typing pdf on the command
26 # line is a short-cut for format=pdf.
29 import "class" : new ;
46 import virtual-target ;
49 # Make this module into a project.
50 project.initialize $(__name__) ;
53 .debug-configuration = [ MATCH ^(--debug-configuration)$ : [ modules.peek : ARGV
56 feature.feature format
57 : html xhtml htmlhelp onehtml man pdf ps docbook fo tests none
58 : implicit composite propagated ;
60 type.register DTDXML : dtdxml ;
61 type.register XML : xml ;
62 type.register BOOSTBOOK : boostbook : XML ;
63 type.register DOCBOOK : docbook : XML ;
64 type.register FO : fo : XML ;
65 type.register PDF : pdf ;
66 type.register PS : ps ;
67 type.register XSLT : xsl : XML ;
68 type.register HTMLDIR ;
69 type.register XHTMLDIR ;
70 type.register HTMLHELP ;
71 type.register MANPAGES ;
72 type.register TESTS : tests ;
75 # Initialize BoostBook support.
78 docbook-xsl-dir ? # The DocBook XSL stylesheet directory. If not provided,
79 # we use DOCBOOK_XSL_DIR from the environment (if
80 # available) or look in standard locations. Otherwise,
81 # we let the XML processor load the stylesheets
84 : docbook-dtd-dir ? # The DocBook DTD directory. If not provided, we use
85 # DOCBOOK_DTD_DIR From the environment (if available) or
86 # look in standard locations. Otherwise, we let the XML
87 # processor load the DTD remotely.
89 : boostbook-dir ? # The BoostBook directory with the DTD and XSL subdirs.
96 check-boostbook-dir $(boostbook-dir) ;
97 find-tools $(docbook-xsl-dir) : $(docbook-dtd-dir) : $(boostbook-dir) ;
99 # Register generators only if we were called via "using boostbook ;"
100 local reg-gen = generators.register-standard ;
101 $(reg-gen) boostbook.dtdxml-to-boostbook : DTDXML : XML ;
102 $(reg-gen) boostbook.boostbook-to-docbook : XML : DOCBOOK ;
103 $(reg-gen) boostbook.boostbook-to-tests : XML : TESTS ;
104 $(reg-gen) boostbook.docbook-to-onehtml : DOCBOOK : HTML ;
105 $(reg-gen) boostbook.docbook-to-htmldir : DOCBOOK : HTMLDIR ;
106 $(reg-gen) boostbook.docbook-to-xhtmldir : DOCBOOK : XHTMLDIR ;
107 $(reg-gen) boostbook.docbook-to-htmlhelp : DOCBOOK : HTMLHELP ;
108 $(reg-gen) boostbook.docbook-to-manpages : DOCBOOK : MANPAGES ;
109 $(reg-gen) boostbook.docbook-to-fo : DOCBOOK : FO ;
111 # The same about Jamfile main target rules.
112 IMPORT $(__name__) : boostbook : : boostbook ;
116 if $(docbook-xsl-dir)
119 .docbook-xsl-dir = [ path.make $(docbook-xsl-dir) ] ;
120 check-docbook-xsl-dir ;
122 if $(docbook-dtd-dir)
125 .docbook-dtd-dir = [ path.make $(docbook-dtd-dir) ] ;
126 check-docbook-dtd-dir ;
131 check-boostbook-dir $(boostbook-dir) ;
132 local boostbook-xsl-dir = [ path.glob $(boostbook-dir) : xsl ] ;
133 local boostbook-dtd-dir = [ path.glob $(boostbook-dir) : dtd ] ;
134 .boostbook-xsl-dir = $(boostbook-xsl-dir[1]) ;
135 .boostbook-dtd-dir = $(boostbook-dtd-dir[1]) ;
136 check-boostbook-xsl-dir ;
137 check-boostbook-dtd-dir ;
143 local rule lock-config ( )
148 errors.user-error BoostBook has not been configured. ;
150 if ! $(.config-locked)
152 .config-locked = true ;
156 print-error $(.error-message) ;
162 local rule modify-config ( )
167 errors.user-error BoostBook configuration cannot be changed after it has
172 rule print-error ( location message * )
174 ECHO error: at $(location) ;
175 ECHO error: $(message) ;
179 rule make-error ( message * )
182 return [ errors.nearest-user-location ] $(message) ;
186 rule find-boost-in-registry ( keys * )
189 for local R in $(keys)
191 local installed-boost = [ W32_GETREG
192 "HKEY_LOCAL_MACHINE\\SOFTWARE\\$(R)" : "InstallRoot" ] ;
193 if $(installed-boost)
195 boost-root += [ path.make $(installed-boost) ] ;
198 return $(boost-root) ;
202 rule check-docbook-xsl-dir ( )
204 if $(.docbook-xsl-dir)
206 if ! [ path.glob $(.docbook-xsl-dir) : common/common.xsl ]
208 .error-message = [ make-error BoostBook: could not find docbook XSL stylesheets
209 in: [ path.native $(.docbook-xsl-dir) ] ] ;
211 else if $(.debug-configuration)
213 ECHO notice: BoostBook: found docbook XSL stylesheets in: [
214 path.native $(.docbook-xsl-dir) ] ;
220 rule check-docbook-dtd-dir ( )
222 if $(.docbook-dtd-dir)
224 if ! [ path.glob $(.docbook-dtd-dir) : docbookx.dtd ]
226 .error-message = [ make-error BoostBook: could not find docbook DTD in: [
227 path.native $(.docbook-dtd-dir) ] ] ;
229 else if $(.debug-configuration)
231 ECHO notice: BoostBook: found docbook DTD in: [ path.native
232 $(.docbook-dtd-dir) ] ;
238 rule check-boostbook-xsl-dir ( )
240 if ! $(.boostbook-xsl-dir)
242 .error-message = [ make-error BoostBook: could not find boostbook XSL stylesheets. ] ;
244 else if ! [ path.glob $(.boostbook-xsl-dir) : docbook.xsl ]
246 .error-message = [ make-error BoostBook: could not find docbook XSL stylesheets in:
247 [ path.native $(.boostbook-xsl-dir) ] ] ;
249 else if $(.debug-configuration)
251 ECHO notice: BoostBook: found boostbook XSL stylesheets in: [
252 path.native $(.boostbook-xsl-dir) ] ;
257 rule check-boostbook-dtd-dir ( )
259 if ! $(.boostbook-dtd-dir)
261 .error-message = [ make-error BoostBook: could not find boostbook DTD. ] ;
263 else if ! [ path.glob $(.boostbook-dtd-dir) : boostbook.dtd ]
265 .error-message = [ make-error BoostBook: could not find boostbook DTD in: [
266 path.native $(.boostbook-dtd-dir) ] ] ;
268 else if $(.debug-configuration)
270 ECHO notice: BoostBook: found boostbook DTD in: [ path.native
271 $(.boostbook-dtd-dir) ] ;
276 rule check-boostbook-dir ( boostbook-dir ? )
278 if $(boostbook-dir) && ! [ path.glob $(boostbook-dir) : xsl ]
280 .error-message = [ make-error BoostBook: could not find boostbook in: [ path.native
281 $(boostbook-dir) ] ] ;
286 rule find-tools ( docbook-xsl-dir ? : docbook-dtd-dir ? : boostbook-dir ? )
288 docbook-xsl-dir ?= [ modules.peek : DOCBOOK_XSL_DIR ] ;
289 docbook-dtd-dir ?= [ modules.peek : DOCBOOK_DTD_DIR ] ;
290 boostbook-dir ?= [ modules.peek : BOOSTBOOK_DIR ] ;
292 # Look for the boostbook stylesheets relative to BOOST_ROOT and Boost.Build.
293 local boost-build-root = [ path.make [ build-system.location ] ] ;
294 local boostbook-search-dirs = [ path.join $(boost-build-root) .. .. ] ;
296 local boost-root = [ modules.peek : BOOST_ROOT ] ;
299 boostbook-search-dirs += [ path.join [ path.make $(boost-root) ] tools ]
302 boostbook-dir ?= [ path.glob $(boostbook-search-dirs) : boostbook* ] ;
304 # Try to find the tools in platform specific locations.
307 # If installed by the Boost installer.
310 local boost-installer-versions = snapshot cvs 1.33.0 ;
311 local boost-consulting-installer-versions = 1.33.1 1.34.0 1.34.1 ;
312 local boostpro-installer-versions =
313 1.35.0 1.36.0 1.37.0 1.38.0 1.39.0 1.40.0 1.41.0 1.42.0
314 1.43.0 1.44.0 1.45.0 1.46.0 1.47.0 1.48.0 1.49.0 1.50.0 ;
316 local old-installer-root = [ find-boost-in-registry
317 Boost.org\\$(boost-installer-versions) ] ;
319 # Make sure that the most recent version is searched for first.
320 boost-root += [ sequence.reverse [ find-boost-in-registry
321 Boost-Consulting.com\\$(boost-consulting-installer-versions)
322 boostpro.com\\$(boostpro-installer-versions) ] ] ;
324 # Plausible locations.
325 local root = [ PWD ] ;
326 while $(root) != $(root:D) { root = $(root:D) ; }
327 root = [ path.make $(root) ] ;
329 local docbook-search-dirs ;
330 for local p in $(boost-root)
332 search-dirs += [ path.join $(p) tools ] ;
334 for local p in $(old-installer-root)
336 search-dirs += [ path.join $(p) share ] ;
337 docbook-search-dirs += [ path.join $(p) share ] ;
339 search-dirs += [ path.join $(root) Boost tools ] ;
340 search-dirs += [ path.join $(root) Boost share ] ;
341 docbook-search-dirs += [ path.join $(root) Boost share ] ;
343 docbook-xsl-dir ?= [ path.glob $(docbook-search-dirs) : docbook-xsl* ] ;
344 docbook-dtd-dir ?= [ path.glob $(docbook-search-dirs) : docbook-xml* ] ;
345 boostbook-dir ?= [ path.glob $(search-dirs) : boostbook* ] ;
349 # Plausible locations.
351 local share = /usr/local/share /usr/share /opt/share /opt/local/share ;
352 local dtd-versions = 4.2 ;
354 docbook-xsl-dir ?= [ path.glob $(share) : docbook-xsl* ] ;
355 docbook-xsl-dir ?= [ path.glob $(share)/sgml/docbook : xsl-stylesheets ]
357 docbook-xsl-dir ?= [ path.glob $(share)/xsl : docbook* ] ;
359 docbook-dtd-dir ?= [ path.glob $(share) : docbook-xml* ] ;
360 docbook-dtd-dir ?= [ path.glob $(share)/sgml/docbook :
361 xml-dtd-$(dtd-versions)* ] ;
362 docbook-dtd-dir ?= [ path.glob $(share)/xml/docbook : $(dtd-versions) ]
365 boostbook-dir ?= [ path.glob $(share) : boostbook* ] ;
368 docbook-xsl-dir ?= [ path.glob /usr/share/xml/docbook/stylesheet :
370 docbook-dtd-dir ?= [ path.glob /usr/share/xml/docbook/schema/dtd :
374 docbook-xsl-dir ?= [ path.glob /usr/share/xml/docbook/stylesheet/nwalsh
378 if $(docbook-xsl-dir)
380 .docbook-xsl-dir = [ path.make $(docbook-xsl-dir[1]) ] ;
382 if $(docbook-dtd-dir)
384 .docbook-dtd-dir = [ path.make $(docbook-dtd-dir[1]) ] ;
387 if $(.debug-configuration)
389 ECHO notice: Boost.Book: searching XSL/DTD "in" ;
390 ECHO notice: [ sequence.transform path.native : $(boostbook-dir) ] ;
392 local boostbook-xsl-dir ;
393 for local dir in $(boostbook-dir)
395 boostbook-xsl-dir += [ path.glob $(dir) : xsl ] ;
397 local boostbook-dtd-dir ;
398 for local dir in $(boostbook-dir)
400 boostbook-dtd-dir += [ path.glob $(dir) : dtd ] ;
402 .boostbook-xsl-dir = $(boostbook-xsl-dir[1]) ;
403 .boostbook-dtd-dir = $(boostbook-dtd-dir[1]) ;
405 check-docbook-xsl-dir ;
406 check-docbook-dtd-dir ;
407 check-boostbook-xsl-dir ;
408 check-boostbook-dtd-dir ;
415 return $(.boostbook-xsl-dir) ;
422 return $(.boostbook-dtd-dir) ;
429 return $(.docbook-xsl-dir) ;
436 return $(.docbook-dtd-dir) ;
440 rule dtdxml-to-boostbook ( target : source : properties * )
443 xsltproc.xslt $(target) : $(source)
444 "$(.boostbook-xsl-dir)/dtd/dtd2boostbook.xsl" : $(properties) ;
448 rule boostbook-to-docbook ( target : source : properties * )
451 local stylesheet = [ path.native $(.boostbook-xsl-dir)/docbook.xsl ] ;
452 xsltproc.xslt $(target) : $(source) $(stylesheet) : $(properties) ;
456 rule docbook-to-onehtml ( target : source : properties * )
459 local stylesheet = [ path.native $(.boostbook-xsl-dir)/html-single.xsl ] ;
460 xsltproc.xslt $(target) : $(source) $(stylesheet) : $(properties) ;
464 rule docbook-to-htmldir ( target : source : properties * )
467 local stylesheet = [ path.native $(.boostbook-xsl-dir)/html.xsl ] ;
468 xsltproc.xslt-dir $(target) : $(source) $(stylesheet) : $(properties) : html
473 rule docbook-to-xhtmldir ( target : source : properties * )
476 local stylesheet = [ path.native $(.boostbook-xsl-dir)/xhtml.xsl ] ;
477 xsltproc.xslt-dir $(target) : $(source) $(stylesheet) : $(properties) :
482 rule docbook-to-htmlhelp ( target : source : properties * )
485 local stylesheet = [ path.native $(.boostbook-xsl-dir)/html-help.xsl ] ;
486 xsltproc.xslt-dir $(target) : $(source) $(stylesheet) : $(properties) :
491 rule docbook-to-manpages ( target : source : properties * )
494 local stylesheet = [ path.native $(.boostbook-xsl-dir)/manpages.xsl ] ;
495 xsltproc.xslt-dir $(target) : $(source) $(stylesheet) : $(properties) : man
500 rule docbook-to-fo ( target : source : properties * )
503 local stylesheet = [ path.native $(.boostbook-xsl-dir)/fo.xsl ] ;
504 xsltproc.xslt $(target) : $(source) $(stylesheet) : $(properties) ;
508 rule format-catalog-path ( path )
510 local result = $(path) ;
511 if [ xsltproc.is-cygwin ]
515 drive = [ MATCH ^/(.):(.*)$ : $(path) ] ;
516 result = /cygdrive/$(drive[1])$(drive[2]) ;
521 if [ os.name ] = CYGWIN
523 local native-path = [ path.native $(path) ] ;
524 result = [ path.make $(native-path:W) ] ;
527 return [ regex.replace $(result) " " "%20" ] ;
531 rule generate-xml-catalog ( target : sources * : properties * )
533 print.output $(target) ;
535 # BoostBook DTD catalog entry.
536 local boostbook-dtd-dir = [ boostbook.dtd-dir ] ;
537 if $(boostbook-dtd-dir)
539 boostbook-dtd-dir = [ format-catalog-path $(boostbook-dtd-dir) ] ;
543 "<?xml version=\"1.0\"?>"
545 " PUBLIC \"-//OASIS/DTD Entity Resolution XML Catalog V1.0//EN\""
546 " \"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd\">"
547 "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">"
548 " <rewriteURI uriStartString=\"http://www.boost.org/tools/boostbook/dtd/\" rewritePrefix=\"file://$(boostbook-dtd-dir)/\"/>"
551 local docbook-xsl-dir = [ boostbook.docbook-xsl-dir ] ;
552 if ! $(docbook-xsl-dir)
554 ECHO "BoostBook warning: no DocBook XSL directory specified." ;
555 ECHO " If you have the DocBook XSL stylesheets installed, please " ;
556 ECHO " set DOCBOOK_XSL_DIR to the stylesheet directory on either " ;
557 ECHO " the command line (via -sDOCBOOK_XSL_DIR=...) or in a " ;
558 ECHO " Boost.Jam configuration file. The DocBook XSL stylesheets " ;
559 ECHO " are available here: http://docbook.sourceforge.net/ " ;
560 ECHO " Stylesheets will be downloaded on-the-fly (very slow!) " ;
564 docbook-xsl-dir = [ format-catalog-path $(docbook-xsl-dir) ] ;
565 print.text " <rewriteURI uriStartString=\"http://docbook.sourceforge.net/release/xsl/current/\" rewritePrefix=\"file://$(docbook-xsl-dir)/\"/>" ;
568 local docbook-dtd-dir = [ boostbook.docbook-dtd-dir ] ;
569 if ! $(docbook-dtd-dir)
571 ECHO "BoostBook warning: no DocBook DTD directory specified." ;
572 ECHO " If you have the DocBook DTD installed, please set " ;
573 ECHO " DOCBOOK_DTD_DIR to the DTD directory on either " ;
574 ECHO " the command line (via -sDOCBOOK_DTD_DIR=...) or in a " ;
575 ECHO " Boost.Jam configuration file. The DocBook DTD is available " ;
576 ECHO " here: http://www.oasis-open.org/docbook/xml/4.2/index.shtml" ;
577 ECHO " The DTD will be downloaded on-the-fly (very slow!) " ;
581 docbook-dtd-dir = [ format-catalog-path $(docbook-dtd-dir) ] ;
582 print.text " <rewriteURI uriStartString=\"http://www.oasis-open.org/docbook/xml/4.2/\" rewritePrefix=\"file://$(docbook-dtd-dir)/\"/>" ;
585 print.text "</catalog>" ;
589 # Returns information about the global XML catalog target, creating it lazily if
590 # needed. To get the global catalog generated only once we do not create it in
591 # every project that requests it but instead only create it based on the first
592 # project requesting it and then reuse it from there for any later requests.
594 # To get 'as close as possible' to having the global catalog stored in the same
595 # location independent of which folder our build was run from, we assign its
596 # target to the given project's base Jamroot project. This works correctly as
597 # long as we know the passed project is not standalone or one of Boost Build's
598 # configuration module projects, as those to not have a Jamroot project in their
599 # parent chain. Note also that we can still get our targets generated in
600 # different folders in case when one build project references a target from
601 # another build project with its own separate Jamroot.
603 # FIXME: Ideally the catalog target should be created as part of the boostbook
604 # project and stored in some central location for all used standalone pojects,
605 # shared between all builds made on that system. This however would require much
606 # more though to add the necessary changes to Boost Build's internal design.
608 local rule xml-catalog ( project )
612 local project-module = [ $(project).project-module ] ;
613 local root-module = [ project.get-jamroot-module $(project-module) ] ;
617 if [ project.is-config-module $(project-module) ]
619 errors.user-error boostbook targets can not be declared in Boost
620 Build's configuration modules. ;
624 errors.user-error boostbook targets can not be declared in
625 standalone projects. : use a Jamfile/Jamroot project
629 local root-project = [ project.target $(root-module) ] ;
631 .xml-catalog = [ virtual-target.register [ new file-target
632 boostbook_catalog : XML : $(root-project) : [ new action :
633 boostbook.generate-xml-catalog ] ] ] ;
634 .xml-catalog-file = [ $(.xml-catalog).path ] [ $(.xml-catalog).name ] ;
635 .xml-catalog-file = $(.xml-catalog-file:J=/) ;
637 return $(.xml-catalog) $(.xml-catalog-file) ;
641 class boostbook-target-class : basic-target
644 import property-set ;
645 import virtual-target ;
648 rule construct ( name : sources * : property-set )
650 # Generate the catalog, but only once.
651 IMPORT boostbook : xml-catalog : $(__name__) : boostbook.xml-catalog ;
652 local global-catalog = [ boostbook.xml-catalog [ project ] ] ;
653 local catalog = $(global-catalog[1]) ;
654 local catalog-file = $(global-catalog[2]) ;
657 # Add the catalog to the property set.
658 property-set = [ $(property-set).add-raw <catalog>$(catalog-file) ] ;
662 local format = [ $(property-set).get <format> ] ;
665 case html : type = HTMLDIR ; manifest = HTML.manifest ;
666 case xhtml : type = XHTMLDIR ; manifest = HTML.manifest ;
667 case htmlhelp : type = HTMLHELP ; manifest = HTML.manifest ;
668 case onehtml : type = HTML ;
669 case man : type = MANPAGES ; manifest = man.manifest ;
670 case docbook : type = DOCBOOK ;
671 case fo : type = FO ;
672 case pdf : type = PDF ;
673 case ps : type = PS ;
674 case tests : type = TESTS ;
680 # Sources --> DOCBOOK.
681 local docbook-target = [ generators.construct [ project ] : DOCBOOK
682 : $(property-set) : $(sources) ] ;
683 docbook-target = $(docbook-target[2]) ;
684 $(docbook-target).depends $(catalog) ;
687 target = [ generators.construct [ project ] $(name)_$(manifest) :
688 $(type) : [ $(property-set).add-raw
689 <xsl:param>manifest=$(name)_$(manifest) ] : $(docbook-target) ]
691 target = $(target[2]) ;
692 local name = [ $(property-set).get <name> ] ;
694 if ! [ path.is-rooted $(name) ]
696 local p = [ project ] ;
697 name = [ path.join [ $(p).location ] $(name) ] ;
699 $(target).set-path $(name) ;
704 target = [ generators.construct [ project ] : $(type) :
705 $(property-set) : $(sources) ] ;
706 target = $(target[2]) ;
710 errors.error Cannot build documentation type '$(format)'. ;
713 $(target).depends $(catalog) ;
715 return [ property-set.empty ] $(target) ;
720 # Declare a boostbook target.
722 rule boostbook ( target-name : sources * : requirements * : default-build * )
724 return [ targets.create-metatarget boostbook-target-class :
725 [ project.current ] : $(target-name) : $(sources) : $(requirements) :
730 rule boostbook-to-tests ( target : source : properties * )
733 local boost_root = [ modules.peek : BOOST_ROOT ] ;
734 local native-path = [ path.native [ path.join $(.boostbook-xsl-dir) testing
736 local stylesheet = $(native-path:S=.xsl) ;
737 xsltproc.xslt $(target) : $(source) $(stylesheet) : $(properties)
738 <xsl:param>boost.root=$(boost_root) ;
742 #############################################################################
743 # Dependency scanners
744 #############################################################################
745 # XInclude scanner. Mostly stolen from c-scanner. :)
746 # Note that this assumes an "xi" prefix for XIncludes. This is not always the
747 # case for XML documents, but we assume it is true for anything we encounter.
749 class xinclude-scanner : scanner
753 rule __init__ ( includes * )
756 self.includes = $(includes) ;
761 return "xi:include[ ]*href=\"([^\"]*)\"" ;
764 rule process ( target : matches * : binding )
766 local target_path = [ NORMALIZE_PATH $(binding:D) ] ;
769 INCLUDES $(target) : $(matches) ;
770 SEARCH on $(matches) = $(target_path) $(self.includes:G=) ;
772 scanner.propagate $(__name__) : $(matches) : $(target) ;
776 scanner.register xinclude-scanner : xsl:path ;
777 type.set-scanner XML : xinclude-scanner ;