Skip to content

Commit 94dfa4c

Browse files
committed
Add support for building documentation.
1 parent 5c723e9 commit 94dfa4c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2115
-8
lines changed

SConstruct

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ vars = Variables('bin.SCons/config.py', ARGUMENTS)
3636
config.add_options(vars)
3737
arch = ARGUMENTS.get('arch', platform.machine())
3838
env = Environment(toolpath=['config/tools'],
39-
tools=['default', 'libs', 'tests'],
39+
tools=['default', 'libs', 'tests', 'doc'],
4040
variables=vars,
4141
TARGET_ARCH=arch)
4242

@@ -80,3 +80,7 @@ for e in config.variants(env):
8080
test_env.BoostUseLib('python')
8181
e.SConscript('test/SConscript', variant_dir=variant_dir + '/test',
8282
exports = { 'env' : test_env })
83+
84+
if 'doc' in COMMAND_LINE_TARGETS:
85+
env.SConscript('doc/SConscript', variant_dir='bin.SCons/doc',
86+
exports = { 'env' : e.Clone(BOOST_LIB = 'python') })

config/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def add_options(vars):
2525
vars.Add('LIBS', converter=lambda v:v.split())
2626
vars.Add('PYTHON')
2727
vars.Add('PYTHONLIBS')
28+
vars.Add('boostbook_prefix')
2829

2930
ui.add_variable(vars, ("arch", "target architeture", platform.machine()))
3031
ui.add_variable(vars, ("toolchain", "toolchain to use", 'gcc'))

config/boost.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ def add_options(vars):
1616
help="prefix for Boost libraries; should have 'include' and 'lib' subdirectories, 'boost' and 'stage\\lib' subdirectories on Windows")
1717
ui.add_option("--boost-include", dest="boost_include", type="string", nargs=1, action="store",
1818
metavar="DIR", help="location of Boost header files")
19-
19+
ui.add_option("--boostbook-prefix", dest="boostbook_prefix", type="string",
20+
nargs=1, action="store",
21+
metavar="DIR", default="/usr/share/boostbook",
22+
help="prefix for BoostBook stylesheets")
2023

2124
def check(context):
2225

@@ -26,6 +29,7 @@ def check(context):
2629

2730
boost_prefix = context.env.GetOption('boost_prefix')
2831
boost_include = context.env.GetOption('boost_include')
32+
boostbook_prefix = context.env.GetOption('boostbook_prefix')
2933
incpath=None
3034
if boost_include:
3135
incpath=boost_include
@@ -36,5 +40,6 @@ def check(context):
3640
if not context.TryCompile(boost_source_file, '.cpp'):
3741
context.Result(0)
3842
return False
43+
context.env.AppendUnique(boostbook_prefix=boostbook_prefix)
3944
context.Result(1)
4045
return True

config/tools/doc.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#
2+
# Copyright (c) 2016 Stefan Seefeld
3+
# All rights reserved.
4+
#
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)
8+
9+
from SCons.Script import AddOption, Flatten
10+
from SCons.Script import Builder
11+
from SCons.Action import Action
12+
from SCons.Defaults import Copy
13+
from SCons.Script import *
14+
from subprocess import check_output, STDOUT, CalledProcessError
15+
import sys
16+
import os
17+
18+
def QuickBook(env, target, source, dependencies=[]):
19+
"""Compile a QuickBook document to BoostBook."""
20+
21+
for d in dependencies:
22+
env.Depends(target, d)
23+
env.Command(target, source, 'quickbook --input-file=$SOURCE --output-file=$TARGET')
24+
25+
26+
def BoostBook(env, target, source, resources=[], args=[]):
27+
"""Compile a BoostBook document to DocBook."""
28+
29+
bb_prefix = env.GetOption('boostbook_prefix')
30+
stylesheet = bb_prefix + '/xsl/docbook.xsl'
31+
env.Command(target, source,
32+
'xsltproc {} -o $TARGET {} $SOURCE'.format(' '.join(args), stylesheet))
33+
34+
35+
def BoostHTML(env, target, source, resources=[], args=[]):
36+
"""Compile a DocBook document to HTML."""
37+
38+
bb_prefix = env.GetOption('boostbook_prefix')
39+
stylesheet = bb_prefix + '/xsl/html.xsl'
40+
env.Command(target, source,
41+
'xsltproc {} -o $TARGET/ {} $SOURCE'.format(' '.join(args), stylesheet))
42+
prefix=Dir('.').path
43+
for r in resources:
44+
r = File(r).path[len(prefix)+1:]
45+
env.Depends(target, target + r)
46+
env.Command(target + r, r, Copy('$TARGET', '$SOURCE'))
47+
48+
49+
def BoostRST(env, target, source, resources=[]):
50+
"""Compile an RST document to HTML."""
51+
52+
prefix=Dir('.').path
53+
for r in resources:
54+
r = File(r).path[len(prefix)+1:]
55+
env.Depends('html/' + r, r)
56+
env.Command('html/' + r, r, Copy('$TARGET', '$SOURCE'))
57+
env.Command(target, source,
58+
'rst2html --link-stylesheet --traceback --trim-footnote-reference-space --footnote-references=superscript --stylesheet=rst.css $SOURCE $TARGET')
59+
60+
61+
def exists(env):
62+
return True
63+
64+
65+
def generate(env):
66+
67+
env.AddMethod(QuickBook)
68+
env.AddMethod(BoostBook)
69+
env.AddMethod(BoostHTML)
70+
env.AddMethod(BoostRST)

doc/SConscript

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- python -*-
2+
#
3+
# Copyright (c) 2016 Stefan Seefeld
4+
# All rights reserved.
5+
#
6+
# Distributed under the Boost Software License, Version 1.0.
7+
# (See accompanying file LICENSE_1_0.txt or copy at
8+
# http://www.boost.org/LICENSE_1_0.txt)
9+
10+
Import('env')
11+
12+
env.QuickBook('python.bbk', 'python.qbk',
13+
['building.qbk',
14+
'configuration.qbk',
15+
'support.qbk',
16+
'faq.qbk',
17+
'glossary.qbk'])
18+
19+
env.QuickBook('tutorial.bbk', 'tutorial.qbk')
20+
env.QuickBook('reference.bbk', 'reference.qbk',
21+
Glob('reference/*.qbk'))
22+
23+
24+
env.BoostBook('python.dbk', 'python.bbk')
25+
env.BoostBook('tutorial.dbk', 'tutorial.bbk')
26+
env.BoostBook('reference.dbk', 'reference.bbk')
27+
28+
images = Glob('images/*.*') + Glob('images/callouts/*.*')
29+
30+
env.BoostHTML('html/', 'python.dbk',
31+
resources=['boostbook.css'] + images,
32+
args=['--stringparam', 'generate.toc', '"library nop; chapter toc; section toc;"',
33+
'--stringparam', 'html.stylesheet', 'boostbook.css',
34+
'--stringparam', 'boost.image.src', 'images/bpl.png',
35+
'--stringparam', 'boost.graphics.root', 'images/',
36+
'--stringparam', 'boost.defaults', 'none',
37+
'--param', 'toc.max.depth', '3',
38+
'--param', 'toc.section.depth' ,'2',
39+
'--param', 'chunk.section.depth', '1'])
40+
env.BoostHTML('html/tutorial/', 'tutorial.dbk',
41+
args=['--stringparam', 'html.stylesheet', '../boostbook.css',
42+
'--stringparam', 'boost.image.src', '../images/bpl.png',
43+
'--stringparam', 'boost.graphics.root', '../images/'])
44+
env.BoostHTML('html/reference/', 'reference.dbk',
45+
args=['--stringparam', 'html.stylesheet', '../boostbook.css',
46+
'--stringparam', 'boost.image.src', '../images/bpl.png',
47+
'--stringparam', 'boost.graphics.root', '../images/'])
48+
49+
env.BoostRST('html/article.html', 'article.rst', resources=['rst.css'])

0 commit comments

Comments
 (0)