2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-14 00:32:11 +00:00
Files
build/boostbook.jam
Douglas Gregor 56e18cfcc2 boostbook.jam:
- Added XML catalog support (finally!). The DocBook XSL stylesheet and DTD
    directories can be specified via "using boostbook : xsl-dir : dtd-dir ; "
    in any BBv2 configuration file, or via command line parameters/environment
    variants DOCBOOK_XSL_DIR and DOCBOOK_DTD_DIR, respectively.

user-config.jam:
  - Add "using boostbook" example


[SVN r17983]
2003-03-19 00:16:38 +00:00

358 lines
11 KiB
Plaintext

# Copyright (C) 2003 Doug Gregor. Permission to copy, use, modify,
# sell and distribute this software is granted provided this
# copyright notice appears in all copies. This software is provided
# "as is" without express or implied warranty, and with no claim as
# to its suitability for any purpose.
# This module defines rules to handle generation of documentation
# from BoostBook sources.
import class : class new ;
import common ;
import targets ;
import feature ;
import generators ;
import property ;
import property-set ;
import regex ;
import scanner ;
feature.feature xsl:param : : free ;
feature.feature format : html onehtml man pdf ps docbook fo
: incidental implicit composite ;
type.register XML : xml ;
type.register DOCBOOK : docbook ;
type.register HTML : html ;
type.register FO : fo ;
type.register PDF : pdf ;
type.register PS : ps ;
type.register XSLT : xsl ;
type.register HTMLDIR ;
type.register MANPAGES ;
# Generates handle -> * rules a bit strangely, so don't try to use them for now
#generators.register-standard boostbook.xslt : XML XSLT : * ;
generators.register-standard boostbook.boostbook-to-docbook : XML : DOCBOOK ;
generators.register-standard boostbook.docbook-to-onehtml : DOCBOOK : HTML ;
generators.register-standard boostbook.docbook-to-htmldir : DOCBOOK : HTMLDIR ;
generators.register-standard boostbook.docbook-to-manpages : DOCBOOK : MANPAGES ;
generators.register-standard boostbook.docbook-to-fo : DOCBOOK : FO ;
generators.register-standard boostbook.fo-to-print : FO : PDF ;
generators.register-standard boostbook.fo-to-print : FO : PS ;
# Initialize BoostBook support. The docbook-xsl-dir parameter refers
# to the DocBook XSL stylesheet directory and the docbook-dtd-dir
# parameter refers to the DocBook DTD directory. If not provided, the
# parameters are derived from DOCBOOK_XL_DIR and DOCBOOK_DTD_DIR,
# respectively, although no definition of these variables is required
# because we can just download the stylesheets/DTD on-the-fly (or
# there may be another, local catalog to fall back on)
rule init ( docbook-xsl-dir ? : docbook-dtd-dir ? )
{
if ! $(docbook-xsl-dir)
{
docbook-xsl-dir = [ modules.peek : DOCBOOK_XSL_DIR ] ;
}
if ! $(docbook-dtd-dir)
{
docbook-dtd-dir = [ modules.peek : DOCBOOK_DTD_DIR ] ;
}
if ! $(.initialized)
{
$(.initialized) = true ;
.docbook-xsl-dir = $(docbook-xsl-dir) ;
.docbook-dtd-dir = $(docbook-dtd-dir) ;
}
}
rule xslt ( target : source stylesheet : properties * )
{
local flags ;
for local param in [ feature.get-values <xsl:param> : $(properties) ]
{
local namevalue = [ regex.split $(param) "=" ] ;
flags += --stringparam $(namevalue[1]) $(namevalue[2]) ;
}
STYLESHEET on $(target) = $(stylesheet) ;
FLAGS on $(target) = $(flags) ;
xslt-xsltproc $(target) : $(source) ;
}
rule xslt-dir ( target : source stylesheet : properties * : dirname )
{
local flags ;
for local param in [ feature.get-values <xsl:param> : $(properties) ]
{
local namevalue = [ regex.split $(param) "=" ] ;
flags += --stringparam $(namevalue[1]) $(namevalue[2]) ;
}
STYLESHEET on $(target) = $(stylesheet) ;
FLAGS on $(target) = $(flags) ;
DIRECTORY on $(target) = $(dirname) ;
xslt-xsltproc-dir $(target) : $(source) ;
}
rule boostbook-to-docbook ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
xslt $(target) : $(source) "$(dir)/tools/boostbook/xsl/docbook.xsl" : $(properties) ;
}
rule docbook-to-onehtml ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
xslt $(target) : $(source) "$(dir)/tools/boostbook/xsl/html-single.xsl" : $(properties) ;
}
rule docbook-to-htmldir ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
xslt-dir $(target) : $(source) "$(dir)/tools/boostbook/xsl/html.xsl" : $(properties) : html ;
}
rule docbook-to-manpages ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
xslt-dir $(target) : $(source) "$(dir)/tools/boostbook/xsl/manpages.xsl" : $(properties) : man ;
}
rule docbook-to-fo ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
xslt $(target) : $(source) "$(dir)/tools/boostbook/xsl/fo.xsl" : $(properties) ;
}
rule fo-to-print ( target : source : properties * )
{
local dir = [ modules.peek : BOOST_ROOT ] ;
JAVA_HOME on $(target) = [ modules.peek : JAVA_HOME ] ;
FOP_DIR on $(target) = [ modules.peek : FOP_DIR ] ;
fop $(target) : $(source) ;
}
actions fop
{
JAVA_HOME=$(JAVA_HOME) $(FOP_DIR)/fop.sh $(>) $(<)
}
rule xml-catalog-action ( target : property-set ? : catalog-entries * )
{
action.__init__ $(target) : : generate-xml-catalog : $(property-set) ;
self.docbook-xsl-dir =
[ feature.get-values <docbook-xsl> : $(catalog-entries) ] ;
self.docbook-dtd-dir =
[ feature.get-values <docbook-dtd> : $(catalog-entries) ] ;
rule actualize ( )
{
if ! $(self.actualized)
{
self.actualized = true ;
local actual = [ $(self.targets[1]).actualize ] ;
local text = "<?xml version=\\\"1.0\\\"?>" ;
local boost-root = [ modules.peek : BOOST_ROOT ] ;
local rewrites ;
# BoostBook DTD catalog entry
rewrites += "<rewriteURI uriStartString=\\\"http://www.boost.org/tools/boostbook/dtd/\\\" rewritePrefix=\\\"$(boost-root)/tools/boostbook/dtd/\\\"/>" ;
if ! $(self.docbook-xsl-dir)
{
ECHO "BoostBook warning: no DocBook XSL directory specified." ;
ECHO " If you have the DocBook XSL stylesheets installed, please " ;
ECHO " set DOCBOOK_XSL_DIR to the stylesheet directory on either " ;
ECHO " the command line (via -sDOCBOOK_XSL_DIR=...) or in a " ;
ECHO " Boost.Jam configuration file. The DocBook XSL stylesheets " ;
ECHO " are available here: http://docbook.sourceforge.net/ " ;
ECHO " Stylesheets will be downloaded on-the-fly (very slow!) " ;
}
else
{
rewrites += "<rewriteURI uriStartString=\\\"http://docbook.sourceforge.net/release/xsl/current/\\\" rewritePrefix=\\\"$(self.docbook-xsl-dir)/\\\"/>" ;
}
if ! $(self.docbook-dtd-dir)
{
ECHO "BoostBook warning: no DocBook DTD directory specified." ;
ECHO " If you have the DocBook DTD installed, please set " ;
ECHO " DOCBOOK_DTD_DIR to the DTD directory on either " ;
ECHO " the command line (via -sDOCBOOK_DTD_DIR=...) or in a " ;
ECHO " Boost.Jam configuration file. The DocBook DTD is available " ;
ECHO " here: http://www.oasis-open.org/docbook/xml/4.2/index.shtml" ;
ECHO " The DTD will be downloaded on-the-fly (very slow!) " ;
}
else
{
rewrites += "<rewriteURI uriStartString=\\\"http://www.oasis-open.org/docbook/xml/4.2/\\\" rewritePrefix=\\\"$(self.docbook-dtd-dir)/\\\"/>" ;
}
REWRITES on $(actual) = $(rewrites) ;
ALWAYS $(actual) ;
boostbook.write-xml-catalog $(actual) ;
}
}
}
class xml-catalog-action : action ;
actions quietly write-xml-catalog
{
echo "<?xml version=\"1.0\"?>" > $(<) ;
echo "<!DOCTYPE catalog " >> $(<) ;
echo " PUBLIC \"-//OASIS/DTD Entity Resolution XML Catalog V1.0//EN\"" >> $(<) ;
echo " \"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd\">" >> $(<) ;
echo "<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">" >> $(<) ;
echo "$(REWRITES)" >> $(<) ;
echo "</catalog>" >> $(<) ;
}
rule boostbook-target-class ( name : project : sources * : requirements *
: default-build * : catalog-entries * )
{
basic-target.__init__ $(name) : $(project) : $(sources) : $(requirements)
: $(default-build) ;
self.catalog-entries = $(catalog-entries) ;
rule construct ( source-targets * : property-set )
{
# Not working :(
local path = [ project.attribute $(self.project) location ] ;
local catalog = [ new file-target catalog : XML : $(self.project) ] ;
$(catalog).action [ new xml-catalog-action $(catalog) : $(property-set)
: $(self.catalog-entries) ] ;
$(catalog).set-path $(path) ;
catalog = [ virtual-target.register $(catalog) ] ;
local properties = [ $(property-set).raw ] ;
local format = [ feature.get-values <format> : $(properties) ] ;
local targets = $(catalog) ;
local type = none ;
local manifest ;
switch $(format)
{
case html :
{
type = HTMLDIR ;
manifest = HTML.manifest ;
}
case onehtml : type = HTML ;
case man :
{
type = MANPAGES ;
manifest = man.manifest ;
}
case docbook : type = DOCBOOK ;
case fo : type = FO ;
case pdf : type = PDF ;
case ps : type = PS ;
}
if $(manifest)
{
for local i in $(source-targets)
{
local base-target = [ generators.construct $(self.project)
: DOCBOOK : $(property-set) : $(i) ] ;
$(base-target).depends $(catalog) ;
local target = [ generators.construct $(self.project) $(manifest)
: $(type) : $(property-set) : $(base-target) ] ;
$(target).set-path $(format) ;
targets += $(target) ;
}
}
else {
for local i in $(source-targets)
{
local target = [ generators.construct $(self.project)
: $(type) : $(property-set) : $(i) ] ;
$(target).depends $(catalog) ;
targets += $(target) ;
}
}
return $(targets) ;
}
}
class boostbook-target-class : basic-target ;
rule boostbook ( target-name : source : requirements * : default-build * )
{
local project = [ CALLER_MODULE ] ;
targets.main-target-alternative
[ new boostbook-target-class $(target-name) : $(project) : $(source)
: [ targets.main-target-requirements $(requirements) : $(project) ]
: [ targets.main-target-default-build $(default-build) : $(project) ]
: <docbook-xsl>$(.docbook-xsl-dir) <docbook-dtd>$(.docbook-dtd-dir)
] ;
}
actions xslt-xsltproc
{
XML_CATALOG_FILES=catalog.xml xsltproc $(FLAGS) --xinclude -o $(<) $(STYLESHEET) $(>)
}
actions xslt-xsltproc-dir
{
XML_CATALOG_FILES=catalog.xml xsltproc $(FLAGS) --xinclude -o $(DIRECTORY)/ $(STYLESHEET) $(>)
}
#############################################################################
# XML Catalog Generation
#############################################################################
# XInclude scanner. Mostly stolen from c-scanner :)
# Note that this assumes an "xi" prefix for XIncludes. This isn't always the
# case for XML documents, but we'll assume it's true for anything we encounter.
rule xinclude-scanner ( includes * )
{
scanner.__init__ ;
rule pattern ( )
{
return "xi:include[ ]*href=\"([^\"]*)\"" ;
}
rule process ( target : matches * )
{
local target_path = [ path.native [ path.parent [ path.make
[ virtual-target.binding $(target) ] ] ] ] ;
for local i in $(matches)
{
local i2 = [ SEARCH_FOR_TARGET $(i) : $(target_path) ] ;
INCLUDES $(target) : $(i2) ;
}
BINDRULE on $(matches) = virtual-target.remember-binding ;
for local j in $(matches)
{
scanner.install $(__name__) : $(j) : $(target) ;
}
}
}
class xinclude-scanner : scanner ;
scanner.register xinclude-scanner ;
type.set-scanner XML : xinclude-scanner ;