summaryrefslogtreecommitdiffstats
path: root/doc/SConscript
blob: 229cf25cc2a7d699c08bbd2d8174e7d54ad19b93 (plain)
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
#
# SConscript file for building SCons documentation.
#
# THIS IS NOT READY YET.  DO NOT TRY TO BUILD SCons WITH ITSELF YET.
#

#
# Copyright (c) 2001, 2002 Steven Knight
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

import os.path
import re
import string

Import('env', 'whereis')

#
#
#
doc_tar_gz = os.path.join('#build',
                          'dist',
                          'scons-doc-%s.tar.gz' % env.Dictionary('VERSION'))

#
# We'll only try to build text files (for some documents)
# if lynx is available to do the dump.
#
fig2dev = whereis('fig2dev')
groff = whereis('groff')
lynx = whereis('lynx')
man2html = whereis('man2html')
jade = whereis('jade')
jadetex = whereis('jadetex')
pdfjadetex = whereis('pdfjadetex')
jw = whereis('jw')
tidy = whereis('tidy')

tar_deps = []
tar_list = ""

entity_re = re.compile(r'<!entity\s+(?:%\s+)?(?:\S+)\s+SYSTEM\s+"([^"]*)">', re.I)
format_re = re.compile(r'<(?:graphic|imagedata)\s+fileref="([^"]*)"(?:\s+format="([^"]*)")?')

#
# Find internal dependencies in .sgml files:
#
#   <!entity bground SYSTEM "bground.sgml">
#   <graphic fileref="file.jpg">
#   <imagedata fileref="file.jpg">
#
# This only finds one per line, and assumes that anything
# defined as a SYSTEM entity is, in fact, a file included
# somewhere in the document.
#
def scansgml(node, env, target):
    includes = []

    contents = node.get_contents()

    includes.extend(entity_re.findall(contents))

    matches = format_re.findall(contents)
    for m in matches:
        file, format = m
        if format and file[-len(format):] != format:
            file = file + format
        if not os.path.isabs(file):
            a = []
            f = file
            while 1:
                f, tail = os.path.split(f)
                if tail == 'doc':
                    break
                a = [tail] + a
            file = apply(os.path.join, a, {})
        includes.append(file)

    return includes

s = Scanner(name = 'sgml', function = scansgml, skeys = ['.sgml', '.mod'])
env = env.Copy(SCANNERS = [s])

if jw:
    #
    # Always create a version.sgml file containing the version information
    # for this run.  Ignore it for dependency purposes so we don't
    # rebuild all the docs every time just because the date changes.
    #
    date, ver, rev = env.Dictionary('DATE', 'VERSION', 'REVISION')
    verfile = str(File("version.sgml"))
    try:
        os.unlink(verfile)
    except:
        pass
    open(verfile, "w").write("""<!--
THIS IS AN AUTOMATICALLY-GENERATED FILE.  DO NOT EDIT.
-->
<!ENTITY builddate "%s">
<!ENTITY buildversion "%s">
<!ENTITY buildrevision "%s">
""" % (date, ver, rev))

    #
    # Each document will live in its own subdirectory.  List them here
    # as hash keys, with a hash of the info to control its build.
    #
    docs = {
        'design' : {
                'htmlindex' : 'book1.html',
                'ps'        : 1,
                'pdf'       : 1,
                'text'      : 0,
        },
        'python10' : {
                'htmlindex' : 't1.html',
                'html'      : 1,
                'ps'        : 1,
                'pdf'       : 0,
                'text'      : 0,
                'graphics'  : [ 'arch', 'builder', 'job-task', 'node', 'scanner', 'sig' ],
        },
        'user' : {
                'htmlindex' : 'book1.html',
                'html'      : 1,
                'ps'        : 1,
                'pdf'       : 1,
                'text'      : 0,
        },
    }

    #
    # We have to tell Cons to QuickScan the top-level SGML files which
    # get included by the document SGML files in the subdirectories.
    #
    included_sgml = [
        'scons.mod',
        'copyright.sgml',
    ]

    #
    # For each document, build the document itself in HTML, Postscript,
    # and PDF formats.
    #
    for doc in docs.keys():
        main = os.path.join(doc, 'main.sgml')
        out = 'main.out'

        htmldir = os.path.join('HTML', 'scons-%s' % doc)
        htmlindex = os.path.join(htmldir, docs[doc]['htmlindex'])
        html = os.path.join('HTML', 'scons-%s.html' % doc)
        ps = os.path.join('PS', 'scons-%s.ps' % doc)
        pdf = os.path.join('PDF', 'scons-%s.pdf' % doc)
        text = os.path.join('TEXT', 'scons-%s.txt' % doc)

        if docs[doc].get('html') and jade:
            cmds = [
                "rm -f ${TARGET.dir}/*.html",
                "jw -b html -o ${TARGET.dir} $SOURCES",
                "mv -v ${TARGET.dir}/index.html $TARGET || true",
            ]
            if tidy:
                cmds.append("tidy -m -q $TARGET || true")
            env.Command(htmlindex, main, cmds)

            cmds = [
                "rm -f ${TARGET.dir}/main.html",
                "jw -u -b html -o ${TARGET.dir} $SOURCES",
                "mv -v ${TARGET.dir}/main.html $TARGET || true",
            ]
            if tidy:
                cmds.append("tidy -m -q $TARGET || true")
            env.Command(html, main, cmds)

            env.Ignore([html, htmlindex], "version.sgml")

            tar_deps.extend([html, htmlindex])
            tar_list = string.join([tar_list, html, htmldir], " ")

            if fig2dev:
                for g in docs[doc].get('graphics', []):
                    fig = os.path.join(doc, '%s.fig' % g)
                    jpg = os.path.join(htmldir, '%s.jpg' % g)
                    env.Command(jpg, fig,
                                "%s -L jpeg -q 100 $SOURCES $TARGET" % fig2dev)
                    env.Depends(ps, jpg)

        if docs[doc].get('ps') and jadetex:
            env.Command(ps, main, [
                "rm -f ${TARGET.dir}/%s" % out,
                "jw -b ps -o ${TARGET.dir} $SOURCES",
                "mv ${TARGET.dir}/main.ps $TARGET",
                "rm -f ${TARGET.dir}/%s" % out,
            ])

            env.Ignore(ps, "version.sgml")

            tar_deps.append(ps)
            tar_list = tar_list + " " + ps

            if fig2dev:
                for g in docs[doc].get('graphics', []):
                    fig = os.path.join(doc, '%s.fig' % g)
                    eps = os.path.join('PS', '%s.eps' % g)
                    env.Command(eps, fig, "%s -L eps $SOURCES $TARGET" % fig2dev)
                    env.Depends(ps, eps)

        if docs[doc].get('pdf') and pdfjadetex:
            env.Command(pdf, main, [
                "rm -f ${TARGET.dir}/%s" % out,
                "jw -b pdf -o ${TARGET.dir} $SOURCES",
                "mv ${TARGET.dir}/main.pdf $TARGET",
                "rm -f ${TARGET.dir}/out",
            ])

            env.Ignore(pdf, "version.sgml")

            tar_deps.append(pdf)
            tar_list = tar_list + " " + pdf

        if docs[doc].get('text') and jade and lynx:
            env.Command(text, html, "lynx -dump ${SOURCE.abspath} > $TARGET")

            env.Ignore(text, "version.sgml")

            tar_deps.append(text)
            tar_list = tar_list + " " + text

#
# Man page(s), in good ol' troff format.
#
scons_1 = os.path.join('man', 'scons.1')

if groff:
    ps = os.path.join('PS', 'scons-man.ps')
    text = os.path.join('TEXT', 'scons-man.txt')

    env.Command(ps, scons_1, "groff -man -Tps $SOURCES > $TARGET")

    env.Command(text, scons_1, "groff -man -Tascii $SOURCES > $TARGET")

    tar_deps.extend([ps, text])
    tar_list = string.join([tar_list, ps, text], " ")

if man2html:
    html = os.path.join('HTML' , 'scons-man.html')

    cmds = [ "man2html $SOURCES > $TARGET" ]
    if tidy:
        cmds.append("tidy -m -q $TARGET || true")
    env.Command(html, scons_1, cmds)

    tar_deps.append(html)
    tar_list = tar_list + " " + html

#
# Now actually create the tar file of the documentation,
# for easy distribution to the web site.
#
if tar_deps:
    env.Command(doc_tar_gz, tar_deps,
                "tar cf${TAR_HFLAG} - -C build/doc %s | gzip > $TARGET" % tar_list)