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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
# 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" : new ;
import common ;
import errors ;
import targets ;
import feature ;
import generators ;
import print ;
import property ;
import project ;
import property-set ;
import regex ;
import scanner ;
import sequence ;
import make ;
import type ;
import modules path project ;
import build-system ;
import xsltproc : xslt xslt-dir ;
feature.feature format : html onehtml man pdf ps docbook fo tests
: incidental implicit composite ;
type.register DTDXML : dtdxml ;
type.register XML : xml ;
type.register BOOSTBOOK : boostbook : XML ;
type.register DOCBOOK : docbook : XML ;
type.register FO : fo : XML ;
type.register PDF : pdf ;
type.register PS : ps ;
type.register XSLT : xsl : XML ;
type.register HTMLDIR ;
type.register MANPAGES ;
type.register TESTS : tests ;
# Artificial target type, used to require invocation of top-level
# BoostBook generator.
type.register BOOSTBOOK_MAIN ;
# Initialize BoostBook support. The parameters are:
# docbook-xsl-dir: The DocBook XSL stylesheet directory. If not provided,
# we use DOCBOOK_XSL_DIR from the environment (if available). Otherwise,
# we let the XML processor load the stylesheets remotely.
#
# docbook-dtd-dir: The DocBook DTD directory. If not provided, we use
# DOCBOOK_DTD_DIR From the environment (if available). Otherwise, we let
# the XML processor load the DTD remotely.
#
# boost-book-dir: The BoostBook directory with the DTD and XSL subdirs.
#
rule init ( docbook-xsl-dir ? : docbook-dtd-dir ? : boostbook-dir ? )
{
docbook-xsl-dir ?= [ modules.peek : DOCBOOK_XSL_DIR ] ;
docbook-dtd-dir ?= [ modules.peek : DOCBOOK_DTD_DIR ] ;
if ! $(.initialized)
{
.initialized = true ;
if $(docbook-xsl-dir)
{
.docbook-xsl-dir = [ path.make $(docbook-xsl-dir) ] ;
}
if $(docbook-dtd-dir)
{
.docbook-dtd-dir = [ path.make $(docbook-dtd-dir) ] ;
}
local boost-root = [ modules.peek : BOOST_ROOT ] ;
if $(boost-root)
{
boost-root = [ path.make $(boost-root) ] ;
}
local boost-build-root = [ build-system.location ] ;
local search-dirs = $(boostbook-dir) [ path.join $(boost-root) tools boostbook ]
$(boost-build-root)/../../boostbook ;
if --debug-configuration in [ modules.peek : ARGV ]
{
ECHO "notice: Boost.Book: searching XSLS/DTD in" ;
ECHO "notice:" [ sequence.transform path.native : $(search-dirs) ] ;
}
local boostbook-xsl-dir ;
for local dir in $(search-dirs) {
boostbook-xsl-dir += [ path.glob $(dir) : xsl ] ;
}
local boostbook-dtd-dir ;
for local dir in $(search-dirs) {
boostbook-dtd-dir += [ path.glob $(dir) : dtd ] ;
}
.boostbook-xsl-dir = $(boostbook-xsl-dir[1]) ;
.boostbook-dtd-dir = $(boostbook-dtd-dir[1]) ;
if ! $(.boostbook-xsl-dir) || ! $(.boostbook-dtd-dir)
{
errors.warning
couldn't find BoostBook xsl or dtd directories;
: please set \"BOOST_ROOT\" variable to the root directory of
your boost installation. Searched in:
: $(search-dirs:J="
") ;
}
# Add trailing slash since some other code
# uses :B modifier to add last element, and fails
# without trailing slash. The code really should be fixed,
# but not now.
.boostbook-xsl-dir = $(.boostbook-xsl-dir)/ ;
.boostbook-dtd-dir = $(.boostbook-dtd-dir)/ ;
# Register generators only if we've were called via "using boostbook ; "
generators.register-standard boostbook.dtdxml-to-boostbook : DTDXML : XML ;
generators.register-standard boostbook.boostbook-to-docbook : XML : DOCBOOK ;
generators.register-standard boostbook.boostbook-to-tests : XML : TESTS ;
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 ;
# The same about Jamfile main target rules.
IMPORT $(__name__) : boostbook : : boostbook ;
}
}
rule xsl-dir
{
return $(.boostbook-xsl-dir) ;
}
rule dtd-dir
{
return $(.boostbook-dtd-dir) ;
}
rule docbook-xsl-dir
{
return $(.docbook-xsl-dir) ;
}
rule docbook-dtd-dir
{
return $(.docbook-dtd-dir) ;
}
rule dtdxml-to-boostbook ( target : source : properties * )
{
xslt $(target) : $(source) "$(.boostbook-xsl-dir)/dtd/dtd2boostbook.xsl"
: $(properties) ;
}
rule boostbook-to-docbook ( target : source : properties * )
{
local native-path = [ path.native $(.boostbook-xsl-dir) ] ;
local stylesheet = $(native-path:B=docbook:S=.xsl) ;
xslt $(target) : $(source) $(stylesheet) : $(properties) ;
}
rule docbook-to-onehtml ( target : source : properties * )
{
local native-path = [ path.native $(.boostbook-xsl-dir) ] ;
local stylesheet = $(native-path:B=html-single:S=.xsl) ;
xslt $(target) : $(source) $(stylesheet) : $(properties) ;
}
rule docbook-to-htmldir ( target : source : properties * )
{
local native-path = [ path.native $(.boostbook-xsl-dir) ] ;
local stylesheet = $(native-path:B=html:S=.xsl) ;
xslt-dir $(target) : $(source) $(stylesheet) : $(properties) : html ;
}
rule docbook-to-manpages ( target : source : properties * )
{
local native-path = [ path.native $(.boostbook-xsl-dir) ] ;
local stylesheet = $(native-path:B=manpages:S=.xsl) ;
xslt-dir $(target) : $(source) $(stylesheet) : $(properties) : man ;
}
rule docbook-to-fo ( target : source : properties * )
{
local native-path = [ path.native $(.boostbook-xsl-dir) ] ;
local stylesheet = $(native-path:B=fo:S=.xsl) ;
xslt $(target) : $(source) $(stylesheet) : $(properties) ;
}
rule generate-xml-catalog ( target : sources * : properties * )
{
print.output $(target) ;
# BoostBook DTD catalog entry
local boostbook-dtd-dir = [ boostbook.dtd-dir ] ;
print.text
"<?xml version=\"1.0\"?>"
"<!DOCTYPE catalog "
" PUBLIC \"-//OASIS/DTD Entity Resolution XML Catalog V1.0//EN\""
" \"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd\">"
"<catalog xmlns=\"urn:oasis:names:tc:entity:xmlns:xml:catalog\">"
" <rewriteURI uriStartString=\"http://www.boost.org/tools/boostbook/dtd/\" rewritePrefix=\"file://$(boostbook-dtd-dir)/\"/>"
: true ;
local docbook-xsl-dir = [ boostbook.docbook-xsl-dir ] ;
if ! $(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
{
print.text " <rewriteURI uriStartString=\"http://docbook.sourceforge.net/release/xsl/current/\" rewritePrefix=\"file://$(docbook-xsl-dir)/\"/>" ;
}
local docbook-dtd-dir = [ boostbook.docbook-dtd-dir ] ;
if ! $(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
{
print.text " <rewriteURI uriStartString=\"http://www.oasis-open.org/docbook/xml/4.2/\" rewritePrefix=\"file://$(docbook-dtd-dir)/\"/>" ;
}
print.text "</catalog>" ;
}
class boostbook-generator : generator
{
import feature ;
import virtual-target ;
import generators ;
rule __init__ ( * : * )
{
generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
}
rule run ( project name ? : property-set : sources * : multiple ? )
{
# Generate the catalog
local catalog = [ new file-target catalog
: XML
: $(project)
: [ new action
: boostbook.generate-xml-catalog
: $(property-set) ] ] ;
# catalog = [ virtual-target.register $(catalog) ] ;
# Add the catalog to the property set
local catalog-path = [ $(catalog).path ] ;
catalog-path = "$(catalog-path)/" ;
local catalog-file = $(catalog-path:G=<catalog>:B=catalog:S=.xml) ;
property-set = [ $(property-set).add-raw $(catalog-file) ] ;
# local targets = $(catalog) ;
local type = none ;
local manifest ;
local format = [ $(property-set).get <format> ] ;
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 ;
case tests : type = TESTS ;
}
if $(manifest)
{
# Create DOCBOOK file from BOOSTBOOK sources.
local base-target = [ generators.construct $(project)
: DOCBOOK : $(property-set) : $(sources) ] ;
base-target = $(base-target[2]) ;
$(base-target).depends $(catalog) ;
# Generate HTML/PDF/PS from DOCBOOK.
local target = [ generators.construct $(project) $(manifest)
: $(type) : $(property-set) : $(base-target) ] ;
local name = [ $(property-set).get <name> ] ;
name ?= $(format) ;
$(target[2]).set-path $(name) ;
$(target[2]).depends $(catalog) ;
targets += $(target[2]) ;
}
else {
local target = [ generators.construct $(project)
: $(type) : $(property-set) : $(sources) ] ;
if ! $(target)
{
errors.error "Cannot build documentation type '$(format)'" ;
}
else
{
$(target[2]).depends $(catalog) ;
targets += $(target[2]) ;
}
}
return $(targets) ;
}
}
generators.register [ new boostbook-generator boostbook.main : : BOOSTBOOK_MAIN ] ;
rule boostbook ( target-name : sources * : requirements * : default-build * )
{
local project = [ project.current ] ;
targets.main-target-alternative
[ new typed-target $(target-name) : $(project) : BOOSTBOOK_MAIN
: [ targets.main-target-sources $(sources) : $(target-name) ]
: [ targets.main-target-requirements $(requirements) : $(project) ]
: [ targets.main-target-default-build $(default-build) : $(project) ]
] ;
}
#############################################################################
# Dependency scanners
#############################################################################
# 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.
class xinclude-scanner : scanner
{
import virtual-target ;
import path ;
import scanner ;
rule __init__ ( includes * )
{
scanner.__init__ ;
self.includes = $(includes) ;
}
rule pattern ( )
{
return "xi:include[ ]*href=\"([^\"]*)\"" ;
}
rule process ( target : matches * : binding )
{
local target_path = [ NORMALIZE_PATH $(binding:D) ] ;
NOCARE $(matches) ;
INCLUDES $(target) : $(matches) ;
SEARCH on $(matches) = $(target_path) $(self.includes:G=) ;
scanner.propagate $(__name__) : $(matches) : $(target) ;
}
}
scanner.register xinclude-scanner : xsl:path ;
type.set-scanner XML : xinclude-scanner ;
#############################################################################
# Testsuite handling
#############################################################################
rule boostbook-to-tests ( target : source : properties * )
{
local boost_root = [ modules.peek : BOOST_ROOT ] ;
local native-path =
[ path.native [ path.join $(.boostbook-xsl-dir) testing Jamfile ] ] ;
local stylesheet = $(native-path:S=.xsl) ;
xslt $(target) : $(source) $(stylesheet)
: $(properties) <xsl:param>boost.root=$(boost_root)
;
}
|