2 # SConscript file for building SCons documentation.
4 # THIS IS NOT READY YET. DO NOT TRY TO BUILD SCons WITH ITSELF YET.
8 # Copyright (c) 2001, 2002 Steven Knight
10 # Permission is hereby granted, free of charge, to any person obtaining
11 # a copy of this software and associated documentation files (the
12 # "Software"), to deal in the Software without restriction, including
13 # without limitation the rights to use, copy, modify, merge, publish,
14 # distribute, sublicense, and/or sell copies of the Software, and to
15 # permit persons to whom the Software is furnished to do so, subject to
16 # the following conditions:
18 # The above copyright notice and this permission notice shall be included
19 # in all copies or substantial portions of the Software.
21 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
22 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
23 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 Import('env', 'whereis')
39 doc_tar_gz = os.path.join('#build',
41 'scons-doc-%s.tar.gz' % env.Dictionary('VERSION'))
44 # We'll only try to build text files (for some documents)
45 # if lynx is available to do the dump.
47 fig2dev = whereis('fig2dev')
48 groff = whereis('groff')
49 lynx = whereis('lynx')
50 man2html = whereis('man2html')
51 jade = whereis('jade')
52 jadetex = whereis('jadetex')
53 pdfjadetex = whereis('pdfjadetex')
55 tidy = whereis('tidy')
60 entity_re = re.compile(r'<!entity\s+(?:%\s+)?(?:\S+)\s+SYSTEM\s+"([^"]*)">', re.I)
61 format_re = re.compile(r'<(?:graphic|imagedata)\s+fileref="([^"]*)"(?:\s+format="([^"]*)")?')
64 # Find internal dependencies in .sgml files:
66 # <!entity bground SYSTEM "bground.sgml">
67 # <graphic fileref="file.jpg">
68 # <imagedata fileref="file.jpg">
70 # This only finds one per line, and assumes that anything
71 # defined as a SYSTEM entity is, in fact, a file included
72 # somewhere in the document.
74 def scansgml(node, env, argument = None):
77 contents = node.get_contents()
79 includes.extend(entity_re.findall(contents))
81 matches = format_re.findall(contents)
84 if format and file[-len(format):] != format:
86 if argument and not os.path.isabs(file):
87 file = os.path.join(argument, file)
94 # Always create a version.sgml file containing the version information
95 # for this run. Ignore it for dependency purposes so we don't
96 # rebuild all the docs every time just because the date changes.
98 date, ver, rev = env.Dictionary('DATE', 'VERSION', 'REVISION')
99 verfile = str(File("version.sgml"))
104 open(verfile, "w").write("""<!--
105 THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT.
107 <!ENTITY builddate "%s">
108 <!ENTITY buildversion "%s">
109 <!ENTITY buildrevision "%s">
110 """ % (date, ver, rev))
113 # Each document will live in its own subdirectory. List them here
114 # as hash keys, with a hash of the info to control its build.
118 'htmlindex' : 'book1.html',
122 'scan' : Scanner(name = 'design',
124 argument = 'design'),
127 'htmlindex' : 't1.html',
132 'graphics' : [ 'arch', 'builder', 'job-task', 'node', 'scanner', 'sig' ],
133 'scan' : Scanner(name = 'python10',
135 argument = 'python10'),
138 'htmlindex' : 'book1.html',
143 'scan' : Scanner(name = 'user',
150 # We have to tell Cons to QuickScan the top-level SGML files which
151 # get included by the document SGML files in the subdirectories.
158 s = Scanner(name = 'sgml', function = scansgml)
160 for sgml in included_sgml:
161 File(sgml).scanner_set(s)
164 # For each document, build the document itself in HTML, Postscript,
167 for doc in docs.keys():
168 main = os.path.join(doc, 'main.sgml')
171 htmldir = os.path.join('HTML', 'scons-%s' % doc)
172 htmlindex = os.path.join(htmldir, docs[doc]['htmlindex'])
173 html = os.path.join('HTML', 'scons-%s.html' % doc)
174 ps = os.path.join('PS', 'scons-%s.ps' % doc)
175 pdf = os.path.join('PDF', 'scons-%s.pdf' % doc)
176 text = os.path.join('TEXT', 'scons-%s.txt' % doc)
178 s = docs[doc].get('scan')
180 File(main).scanner_set(s)
182 if docs[doc].get('html') and jade:
184 "rm -f ${TARGET.dir}/*.html",
185 "jw -b html -o ${TARGET.dir} $SOURCES",
186 "mv -v ${TARGET.dir}/index.html $TARGET || true",
189 cmds.append("tidy -m -q $TARGET || true")
190 env.Command(htmlindex, main, cmds)
193 "rm -f ${TARGET.dir}/main.html",
194 "jw -u -b html -o ${TARGET.dir} $SOURCES",
195 "mv -v ${TARGET.dir}/main.html $TARGET || true",
198 cmds.append("tidy -m -q $TARGET || true")
199 env.Command(html, main, cmds)
201 env.Ignore([html, htmlindex], "version.sgml")
203 tar_deps.extend([html, htmlindex])
204 tar_list = string.join([tar_list, html, htmldir], " ")
207 for g in docs[doc].get('graphics', []):
208 fig = os.path.join(doc, '%s.fig' % g)
209 jpg = os.path.join(htmldir, '%s.jpg' % g)
210 env.Command(jpg, fig,
211 "%s -L jpeg -q 100 $SOURCES $TARGET" % fig2dev)
214 if docs[doc].get('ps') and jadetex:
215 env.Command(ps, main, [
216 "rm -f ${TARGET.dir}/%s" % out,
217 "jw -b ps -o ${TARGET.dir} $SOURCES",
218 "mv ${TARGET.dir}/main.ps $TARGET",
219 "rm -f ${TARGET.dir}/%s" % out,
222 env.Ignore(ps, "version.sgml")
225 tar_list = tar_list + " " + ps
228 for g in docs[doc].get('graphics', []):
229 fig = os.path.join(doc, '%s.fig' % g)
230 eps = os.path.join('PS', '%s.eps' % g)
231 env.Command(eps, fig, "%s -L eps $SOURCES $TARGET" % fig2dev)
234 if docs[doc].get('pdf') and pdfjadetex:
235 env.Command(pdf, main, [
236 "rm -f ${TARGET.dir}/%s" % out,
237 "jw -b pdf -o ${TARGET.dir} $SOURCES",
238 "mv ${TARGET.dir}/main.pdf $TARGET",
239 "rm -f ${TARGET.dir}/out",
242 env.Ignore(pdf, "version.sgml")
245 tar_list = tar_list + " " + pdf
247 if docs[doc].get('text') and jade and lynx:
248 env.Command(text, html, "lynx -dump ${SOURCE.abspath} > $TARGET")
250 env.Ignore(text, "version.sgml")
252 tar_deps.append(text)
253 tar_list = tar_list + " " + text
256 # Man page(s), in good ol' troff format.
258 scons_1 = os.path.join('man', 'scons.1')
261 ps = os.path.join('PS', 'scons-man.ps')
262 text = os.path.join('TEXT', 'scons-man.txt')
264 env.Command(ps, scons_1, "groff -man -Tps $SOURCES > $TARGET")
266 env.Command(text, scons_1, "groff -man -Tascii $SOURCES > $TARGET")
268 tar_deps.extend([ps, text])
269 tar_list = string.join([tar_list, ps, text], " ")
272 html = os.path.join('HTML' , 'scons-man.html')
274 cmds = [ "man2html $SOURCES > $TARGET" ]
276 cmds.append("tidy -m -q $TARGET || true")
277 env.Command(html, scons_1, cmds)
279 tar_deps.append(html)
280 tar_list = tar_list + " " + html
283 # Now actually create the tar file of the documentation,
284 # for easy distribution to the web site.
287 env.Command(doc_tar_gz, tar_deps,
288 "tar zc${TAR_HFLAG} -f $TARGET -C build/doc %s" % tar_list)