1 # Copyright 2003, 2004 Douglas Gregor
2 # Copyright 2003, 2004, 2005 Vladimir Prus
3 # Copyright 2006 Rene Rivera
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or copy at
6 # http://www.boost.org/LICENSE_1_0.txt)
8 # This module defines rules to handle generation of various outputs from source
9 # files documented with doxygen comments. The supported transformations are:
11 # * Source -> Doxygen XML -> BoostBook XML
12 # * Source -> Doxygen HTML
14 # The type of transformation is selected based on the target requested. For
15 # BoostBook XML, the default, specifying a target with an ".xml" suffix, or an
16 # empty suffix, will produce a <target>.xml and <target>.boostbook. For Doxygen
17 # HTML specifying a target with an ".html" suffix will produce a directory
18 # <target> with the Doxygen html files, and a <target>.html file redirecting to
23 import "class" : new ;
41 import virtual-target ;
44 # Use to specify extra configuration paramters. These get translated into a
45 # doxyfile which configures the building of the docs.
46 feature.feature "doxygen:param" : : free ;
48 # Specify the "<xsl:param>boost.doxygen.header.prefix" XSLT option.
49 feature.feature prefix : : free ;
51 # Specify the "<xsl:param>boost.doxygen.reftitle" XSLT option.
52 feature.feature reftitle : : free ;
54 # Which processor to use for various translations from Doxygen.
55 feature.feature doxygen.processor : xsltproc doxproc : propagated implicit ;
57 # To generate, or not, index sections.
58 feature.feature doxygen.doxproc.index : no yes : propagated incidental ;
60 # The ID for the resulting BoostBook reference section.
61 feature.feature doxygen.doxproc.id : : free ;
63 # The title for the resulting BoostBook reference section.
64 feature.feature doxygen.doxproc.title : : free ;
66 # Location for images when generating XML
67 feature.feature "doxygen:xml-imagedir" : : free ;
69 # Indicates whether the entire directory should be deleted
70 feature.feature doxygen.rmdir : off on : optional incidental ;
72 # Doxygen configuration input file.
73 type.register DOXYFILE : doxyfile ;
75 # Doxygen XML multi-file output.
76 type.register DOXYGEN_XML_MULTIFILE : xml-dir : XML ;
78 # Doxygen XML coallesed output.
79 type.register DOXYGEN_XML : doxygen : XML ;
81 # Doxygen HTML multifile directory.
82 type.register DOXYGEN_HTML_MULTIFILE : html-dir : HTML ;
84 # Redirection HTML file to HTML multifile directory.
85 type.register DOXYGEN_HTML : : HTML ;
87 type.register DOXYGEN_XML_IMAGES : doxygen-xml-images ;
90 # Initialize the Doxygen module. Parameters are:
91 # name: the name of the 'doxygen' executable. If not specified, the name
92 # 'doxygen' will be used
100 .doxproc = [ modules.binding $(__name__) ] ;
101 .doxproc = $(.doxproc:D)/doxproc.py ;
103 generators.register-composing doxygen.headers-to-doxyfile
104 : H HPP CPP MARKDOWN : DOXYFILE ;
105 generators.register-standard doxygen.run
106 : DOXYFILE : DOXYGEN_XML_MULTIFILE ;
107 generators.register-standard doxygen.xml-dir-to-boostbook
108 : DOXYGEN_XML_MULTIFILE : BOOSTBOOK : <doxygen.processor>doxproc ;
109 generators.register-xslt doxygen.xml-to-boostbook
110 : DOXYGEN_XML : BOOSTBOOK : <doxygen.processor>xsltproc ;
111 generators.register-xslt doxygen.collect
112 : DOXYGEN_XML_MULTIFILE : DOXYGEN_XML ;
113 generators.register-standard doxygen.run
114 : DOXYFILE : DOXYGEN_HTML_MULTIFILE ;
115 generators.register-standard doxygen.html-redirect
116 : DOXYGEN_HTML_MULTIFILE : DOXYGEN_HTML ;
117 generators.register-standard doxygen.copy-latex-pngs
118 : DOXYGEN_HTML : DOXYGEN_XML_IMAGES ;
120 IMPORT $(__name__) : doxygen : : doxygen ;
137 local rule freeze-config ( )
142 errors.user-error doxygen must be initialized before it can be used. ;
144 if ! $(.config-frozen)
146 .config-frozen = true ;
155 local rule modify-config ( )
160 errors.user-error "Cannot change doxygen after it has been used." ;
165 local rule check-doxygen ( )
167 if --debug-configuration in [ modules.peek : ARGV ]
169 ECHO "notice:" using doxygen ":" $(.doxygen) ;
174 local ProgramFiles = [ modules.peek : ProgramFiles ] ;
177 extra-paths = "$(ProgramFiles:J= )" ;
181 extra-paths = "C:\\Program Files" ;
184 .doxygen = [ common.get-invocation-command doxygen : doxygen : $(.doxygen) :
196 local rule .is-cygwin ( )
200 local file = [ path.make [ modules.binding $(__name__) ] ] ;
201 local dir = [ path.native [ path.join [ path.parent $(file) ] doxygen ]
203 local command = cd \"$(dir)\" "&&" \"$(.doxygen)\"
204 windows-paths-check.doxyfile 2>&1 ;
205 command = $(command:J=" ") ;
206 result = [ SHELL $(command) ] ;
207 if [ MATCH "(Parsing file /)" : $(result) ]
215 # Runs Doxygen on the given Doxygen configuration file (the source) to generate
216 # the Doxygen files. The output is dumped according to the settings in the
217 # Doxygen configuration file, not according to the target! Because of this, we
218 # essentially "touch" the target file, in effect making it look like we have
219 # really written something useful to it. Anyone that uses this action must deal
220 # with this behavior.
222 actions doxygen-action
224 $(RM) "$(*.XML)" & "$(NAME:E=doxygen)" "$(>)" && echo "Stamped" > "$(<)"
228 # Runs the Python doxproc XML processor.
232 python "$(DOXPROC)" "--xmldir=$(>)" "--output=$(<)" "$(OPTIONS)" "--id=$(ID)" "--title=$(TITLE)"
236 rule translate-path ( path )
241 if [ os.name ] = CYGWIN
256 match = [ MATCH "^(.):(.*)" : $(path) ] ;
259 return /cygdrive/$(match[1])$(match[2]:T) ;
278 toolset.uses-features doxygen.headers-to-doxyfile : "<doxygen:param>" ;
280 # Generates a doxygen configuration file (doxyfile) given a set of C++ sources
281 # and a property list that may contain <doxygen:param> features.
283 rule headers-to-doxyfile ( target : sources * : properties * )
285 local text = "# Generated by Boost.Build version 2" ;
289 # Translate <doxygen:param> into command line flags.
290 for local param in [ feature.get-values <doxygen:param> : $(properties) ]
292 local namevalue = [ MATCH "([^=]*)=(.*)" : $(param) ] ;
293 if $(namevalue[1]) = OUTPUT_DIRECTORY
295 output-dir = [ translate-path [ utility.unquote $(namevalue[2]) ] ]
297 text += "OUTPUT_DIRECTORY = \"$(output-dir)\"" ;
301 text += "$(namevalue[1]) = $(namevalue[2])" ;
307 output-dir = [ translate-path [ on $(target) return $(LOCATE) ] ] ;
308 text += "OUTPUT_DIRECTORY = \"$(output-dir)\"" ;
312 for local header in $(sources:G=)
314 header = [ translate-path $(header) ] ;
315 headers += \"$(header)\" ;
318 # Doxygen generates LaTex by default. So disable it unconditionally, or at
319 # least until someone needs, and hence writes support for, LaTex output.
320 text += "GENERATE_LATEX = NO" ;
321 text += "INPUT = $(headers:J= )" ;
322 print.output $(target) plain ;
323 print.text $(text) : true ;
326 toolset.uses-features doxygen.run : <doxygen.rmdir> "<doxygen:param>" ;
328 # Run Doxygen. See doxygen-action for a description of the strange properties of
331 rule run ( target : source : properties * )
334 if <doxygen.rmdir>on in $(properties)
336 local output-dir = [ path.make [ MATCH
337 "<doxygen:param>OUTPUT_DIRECTORY=\"?([^\"]*)" : $(properties) ] ] ;
338 local html-dir = [ path.make [ MATCH <doxygen:param>HTML_OUTPUT=(.*) :
340 if $(output-dir) && $(html-dir) &&
341 [ path.glob $(output-dir) : $(html-dir) ]
343 HTMLDIR on $(target) = [ path.native [ path.join $(output-dir)
345 rm-htmldir $(target) ;
348 doxygen-action $(target) : $(source) ;
349 NAME on $(target) = $(.doxygen) ;
350 RM on $(target) = [ modules.peek common : RM ] ;
351 *.XML on $(target) = [ path.native [ path.join [ path.make [ on $(target)
352 return $(LOCATE) ] ] $(target:B:S=) *.xml ] ] ;
358 RMDIR = rmdir /s /q ;
365 actions quietly rm-htmldir
371 # The rules below require BoostBook stylesheets, so we need some code to check
372 # that the boostbook module has actualy been initialized.
374 rule check-boostbook ( )
376 if ! [ modules.peek boostbook : .initialized ]
380 : The boostbook module is not initialized you have attempted to use
381 : the 'doxygen' toolset, which requires BoostBook, but never
382 : initialized BoostBook.
383 : "Hint:" add 'using boostbook \;' to your user-config.jam. ;
388 # Collect the set of Doxygen XML files into a single XML source file that can be
389 # handled by an XSLT processor. The source is completely ignored (see
390 # doxygen-action), because this action picks up the Doxygen XML index file xml/
391 # index.xml. This is because we can not teach Doxygen to act like a NORMAL
392 # program and take a "-o output.xml" argument (grrrr). The target of the
393 # collection will be a single Doxygen XML file.
395 rule collect ( target : source : properties * )
398 local collect-xsl-dir
399 = [ path.native [ path.join [ boostbook.xsl-dir ] doxygen collect ] ] ;
401 = [ path.make [ on $(source) return $(LOCATE) ] ] ;
403 = [ path.root [ path.join $(source-path) $(source:B) ] [ path.pwd ] ] ;
405 = [ path.native $(collect-path) ] ;
407 = [ path.native [ path.join $(collect-path) index.xml ] ] ;
408 xsltproc.xslt $(target) : $(real-source) $(collect-xsl-dir:S=.xsl)
409 : <xsl:param>doxygen.xml.path=$(native-path) ;
412 toolset.uses-features doxygen.xml-to-boostbook : <prefix> <reftitle> ;
414 # Translate Doxygen XML into BoostBook.
416 rule xml-to-boostbook ( target : source : properties * )
419 local xsl-dir = [ boostbook.xsl-dir ] ;
420 local d2b-xsl = [ path.native [ path.join [ boostbook.xsl-dir ] doxygen
421 doxygen2boostbook.xsl ] ] ;
423 local xslt-properties = $(properties) ;
424 for local prefix in [ feature.get-values <prefix> : $(properties) ]
426 xslt-properties += "<xsl:param>boost.doxygen.header.prefix=$(prefix)" ;
428 for local title in [ feature.get-values <reftitle> : $(properties) ]
430 xslt-properties += "<xsl:param>boost.doxygen.reftitle=$(title)" ;
433 xsltproc.xslt $(target) : $(source) $(d2b-xsl) : $(xslt-properties) ;
437 toolset.flags doxygen.xml-dir-to-boostbook OPTIONS <doxygen.doxproc.index>yes :
439 toolset.flags doxygen.xml-dir-to-boostbook ID <doxygen.doxproc.id> ;
440 toolset.flags doxygen.xml-dir-to-boostbook TITLE <doxygen.doxproc.title> ;
443 rule xml-dir-to-boostbook ( target : source : properties * )
445 DOXPROC on $(target) = $(.doxproc) ;
446 LOCATE on $(source:S=) = [ on $(source) return $(LOCATE) ] ;
447 doxygen.doxproc $(target) : $(source:S=) ;
451 # Generate the HTML redirect to HTML dir index.html file.
453 rule html-redirect ( target : source : properties * )
455 local uri = "$(target:B)/index.html" ;
456 print.output $(target) plain ;
458 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
459 \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
460 <html xmlns=\"http://www.w3.org/1999/xhtml\">
462 <meta http-equiv=\"refresh\" content=\"0; URL=$(uri)\" />
468 Automatic redirection failed, please go to <a href=
469 \"$(uri)\">$(uri)</a>.
476 rule copy-latex-pngs ( target : source : requirements * )
478 local directory = [ path.native [ feature.get-values <doxygen:xml-imagedir>
479 : $(requirements) ] ] ;
480 local location = [ on $(target) return $(LOCATE) ] ;
482 local pdf-location = [ path.native [ path.join [ path.make $(location) ]
483 [ path.make $(directory) ] ] ] ;
484 local html-location = [ path.native [ path.join . html [ path.make
487 common.MkDir $(pdf-location) ;
488 common.MkDir $(html-location) ;
490 DEPENDS $(target) : $(pdf-location) $(html-location) ;
494 CP on $(target) = copy /y ;
495 FROM on $(target) = \\*.png ;
496 TOHTML on $(target) = .\\html\\$(directory) ;
497 TOPDF on $(target) = \\$(directory) ;
501 CP on $(target) = cp ;
502 FROM on $(target) = /*.png ;
503 TOHTML on $(target) = ./html/$(directory) ;
504 TOPDF on $(target) = $(target:D)/$(directory) ;
508 actions copy-latex-pngs
510 $(CP) $(>:S=)$(FROM) $(TOHTML)
511 $(CP) $(>:S=)$(FROM) $(<:D)$(TOPDF)
512 echo "Stamped" > "$(<)"
516 # Building latex images for doxygen XML depends on latex, dvips, and gs being in
517 # your PATH. This is true for most Unix installs, but not on Win32, where you
518 # will need to install MkTex and Ghostscript and add these tools to your path.
530 if [ os.name ] = "NT"
534 gswin32c -version >$(<)
546 local rule check-tools-targets ( project )
548 if ! $(.check-tools-targets)
550 # Find the root project.
552 # This is a best effort attempt to avoid using different locations for
553 # storing *.check files depending on which project imported the doxygen
554 # toolset first. The files are stored in a location related to the
555 # project's root project. Note that this location may change depending
556 # on the folder the build was run from in case the build uses multiple
557 # related projects with their own Jamroot separate modules.
558 local project-module = [ $(project).project-module ] ;
559 local root-module = [ project.get-jamroot-module $(project-module) ] ;
563 if [ project.is-config-module $(project-module) ]
565 errors.user-error doxygen targets can not be declared in Boost
566 Build's configuration modules. ;
570 errors.user-error doxygen targets can not be declared in
571 standalone projects. : use a Jamfile/Jamroot project
575 local root-project = [ project.target $(root-module) ] ;
578 [ new file-target latex.check : : $(root-project) : [ new action :
579 doxygen.check-latex ] ]
580 [ new file-target dvips.check : : $(root-project) : [ new action :
581 doxygen.check-dvips ] ]
582 [ new file-target gs.check : : $(root-project) : [ new action :
583 doxygen.check-gs ] ] ;
585 for local target in $(targets)
587 .check-tools-targets += [ virtual-target.register $(target) ] ;
590 return $(.check-tools-targets) ;
594 project.initialize $(__name__) ;
597 class doxygen-check-tools-target-class : basic-target
599 rule construct ( name : sources * : property-set )
601 IMPORT doxygen : check-tools-targets : $(__name__) :
602 doxygen.check-tools-targets ;
603 return [ property-set.empty ] [ doxygen.check-tools-targets [ project ]
609 # Declares a metatarget for collecting version information on different external
610 # tools used in this module.
612 rule check-tools ( target )
615 targets.create-metatarget doxygen-check-tools-target-class :
616 [ project.current ] : $(target) ;
620 # User-level rule to generate HTML files or BoostBook XML from a set of headers
623 rule doxygen ( target : sources + : requirements * : default-build * :
624 usage-requirements * )
626 param.handle-named-params
627 sources requirements default-build usage-requirements ;
628 requirements += <format>none ;
630 local project = [ project.current ] ;
632 if $(target:S) = .html
634 # Build an HTML directory from the sources.
635 local html-location = [ feature.get-values <location> : $(requirements)
638 if [ $(project).get build-dir ]
640 # Explicitly specified build dir. Add html at the end.
641 output-dir = [ path.join [ $(project).build-dir ]
642 $(html-location:E=html) ] ;
646 # Trim 'bin' from implicit build dir, for no other reason than
647 # backward compatibility.
648 output-dir = [ path.join [ path.parent [ $(project).build-dir ] ]
649 $(html-location:E=html) ] ;
651 output-dir = [ path.root $(output-dir) [ path.pwd ] ] ;
652 local output-dir-native = [ path.native $(output-dir) ] ;
653 requirements = [ property.change $(requirements) : <location> ] ;
655 # The doxygen configuration file.
656 targets.create-typed-target DOXYFILE : $(project) : $(target:S=.tag)
659 <doxygen:param>GENERATE_HTML=YES
660 <doxygen:param>GENERATE_XML=NO
661 <doxygen:param>"OUTPUT_DIRECTORY=\"$(output-dir-native)\""
662 <doxygen:param>HTML_OUTPUT=$(target:B)
664 $(project).mark-target-as-explicit $(target:S=.tag) ;
666 # The html directory to generate by running doxygen.
667 targets.create-typed-target DOXYGEN_HTML_MULTIFILE : $(project)
668 : $(target:S=.dir) # Name.
669 : $(target:S=.tag) # Sources.
671 <doxygen:param>"OUTPUT_DIRECTORY=\"$(output-dir-native)\""
672 <doxygen:param>HTML_OUTPUT=$(target:B)
674 $(project).mark-target-as-explicit $(target:S=.dir) ;
676 # The redirect html file into the generated html.
677 targets.create-typed-target DOXYGEN_HTML : $(project) : $(target)
678 : $(target:S=.dir) # Sources.
679 : $(requirements) <location>$(output-dir)
684 # Build a BoostBook XML file from the sources.
685 local location-xml = [ feature.get-values <location> : $(requirements) ]
687 requirements = [ property.change $(requirements) : <location> ] ;
688 local target-xml = $(target:B=$(target:B)-xml) ;
690 # Check whether we need to build images.
691 local images-location = [ feature.get-values <doxygen:xml-imagedir> :
693 if $(images-location)
695 # Prepare a metatarget for collecting used external tool version
696 # information. We use only one such metatarget as they always
697 # produce the same files and we do not want to deal with multiple
698 # metatargets having matching names, causing 'ambiguous variants'
702 # FIXME: Since we have the check-tools target object reference,
703 # see how we can use that instead of having to construct a valid
704 # target reference string for use in <dependency> property
706 local project-id = --doxygen.check-tools-project-- ;
707 local target-id = --doxygen.check-tools-- ;
708 local pm = [ $(project).project-module ] ;
709 project.register-id $(project-id) : $(pm) ;
710 check-tools $(target-id) ;
711 .check-tools = /$(project-id)//$(target-id) ;
714 doxygen $(target).doxygen-xml-images.html : $(sources) :
717 <doxygen:param>QUIET=YES
718 <doxygen:param>WARNINGS=NO
719 <doxygen:param>WARN_IF_UNDOCUMENTED=NO
720 <dependency>$(.check-tools) ;
721 $(project).mark-target-as-explicit $(target).doxygen-xml-images.html
724 targets.create-typed-target DOXYGEN_XML_IMAGES : $(project)
725 : $(target).doxygen-xml-images # Name.
726 : $(target).doxygen-xml-images.html # Sources.
729 $(project).mark-target-as-explicit $(target).doxygen-xml-images ;
731 if ! [ MATCH (/)$ : $(images-location) ]
733 images-location = $(images-location)/ ;
737 <dependency>$(target).doxygen-xml-images
738 <xsl:param>boost.doxygen.formuladir=$(images-location) ;
741 # The doxygen configuration file.
742 targets.create-typed-target DOXYFILE : $(project) : $(target-xml:S=.tag)
745 <doxygen:param>GENERATE_HTML=NO
746 <doxygen:param>GENERATE_XML=YES
747 <doxygen:param>XML_OUTPUT=$(target-xml)
749 $(project).mark-target-as-explicit $(target-xml:S=.tag) ;
751 # The Doxygen XML directory for the processed source files.
752 targets.create-typed-target DOXYGEN_XML_MULTIFILE : $(project)
753 : $(target-xml:S=.dir) # Name.
754 : $(target-xml:S=.tag) # Sources.
757 $(project).mark-target-as-explicit $(target-xml:S=.dir) ;
759 # The resulting BoostBook file is generated by the processor tool. The
760 # tool can be either the xsltproc plus accompanying XSL scripts. Or it
761 # can be the python doxproc.py script.
762 targets.create-typed-target BOOSTBOOK : $(project) : $(target-xml)
763 : $(target-xml:S=.dir) # Sources.
766 $(project).mark-target-as-explicit $(target-xml) ;
768 stage $(target:S=.xml) # Name.
769 : $(target-xml) # Sources.
771 <location>$(location-xml:E=.)
772 <name>$(target:S=.xml)
774 $(project).mark-target-as-explicit $(target:S=.xml) ;
776 # TODO: See why this alias target is used here instead of simply naming
777 # the previous stage target $(target) and having it specify the alias
778 # target's usage requirements directly.
779 alias $(target) : : $(requirements) : $(default-build) :
780 $(usage-requirements) <dependency>$(target:S=.xml) ;