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, target):
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 not os.path.isabs(file):
90 f, tail = os.path.split(f)
94 file = apply(os.path.join, a, {})
99 s = Scanner(name = 'sgml', function = scansgml, skeys = ['.sgml', '.mod'])
100 env = env.Copy(SCANNERS = [s])
104 # Always create a version.sgml file containing the version information
105 # for this run. Ignore it for dependency purposes so we don't
106 # rebuild all the docs every time just because the date changes.
108 date, ver, rev = env.Dictionary('DATE', 'VERSION', 'REVISION')
109 verfile = str(File("version.sgml"))
114 open(verfile, "w").write("""<!--
115 THIS IS AN AUTOMATICALLY-GENERATED FILE. DO NOT EDIT.
117 <!ENTITY builddate "%s">
118 <!ENTITY buildversion "%s">
119 <!ENTITY buildrevision "%s">
120 """ % (date, ver, rev))
123 # Each document will live in its own subdirectory. List them here
124 # as hash keys, with a hash of the info to control its build.
128 'htmlindex' : 'book1.html',
134 'htmlindex' : 't1.html',
139 'graphics' : [ 'arch', 'builder', 'job-task', 'node', 'scanner', 'sig' ],
142 'htmlindex' : 'book1.html',
151 # We have to tell Cons to QuickScan the top-level SGML files which
152 # get included by the document SGML files in the subdirectories.
160 # For each document, build the document itself in HTML, Postscript,
163 for doc in docs.keys():
164 main = os.path.join(doc, 'main.sgml')
167 htmldir = os.path.join('HTML', 'scons-%s' % doc)
168 htmlindex = os.path.join(htmldir, docs[doc]['htmlindex'])
169 html = os.path.join('HTML', 'scons-%s.html' % doc)
170 ps = os.path.join('PS', 'scons-%s.ps' % doc)
171 pdf = os.path.join('PDF', 'scons-%s.pdf' % doc)
172 text = os.path.join('TEXT', 'scons-%s.txt' % doc)
174 if docs[doc].get('html') and jade:
176 "rm -f ${TARGET.dir}/*.html",
177 "jw -b html -o ${TARGET.dir} $SOURCES",
178 "mv -v ${TARGET.dir}/index.html $TARGET || true",
181 cmds.append("tidy -m -q $TARGET || true")
182 env.Command(htmlindex, main, cmds)
185 "rm -f ${TARGET.dir}/main.html",
186 "jw -u -b html -o ${TARGET.dir} $SOURCES",
187 "mv -v ${TARGET.dir}/main.html $TARGET || true",
190 cmds.append("tidy -m -q $TARGET || true")
191 env.Command(html, main, cmds)
193 env.Ignore([html, htmlindex], "version.sgml")
195 tar_deps.extend([html, htmlindex])
196 tar_list = string.join([tar_list, html, htmldir], " ")
199 for g in docs[doc].get('graphics', []):
200 fig = os.path.join(doc, '%s.fig' % g)
201 jpg = os.path.join(htmldir, '%s.jpg' % g)
202 env.Command(jpg, fig,
203 "%s -L jpeg -q 100 $SOURCES $TARGET" % fig2dev)
206 if docs[doc].get('ps') and jadetex:
207 env.Command(ps, main, [
208 "rm -f ${TARGET.dir}/%s" % out,
209 "jw -b ps -o ${TARGET.dir} $SOURCES",
210 "mv ${TARGET.dir}/main.ps $TARGET",
211 "rm -f ${TARGET.dir}/%s" % out,
214 env.Ignore(ps, "version.sgml")
217 tar_list = tar_list + " " + ps
220 for g in docs[doc].get('graphics', []):
221 fig = os.path.join(doc, '%s.fig' % g)
222 eps = os.path.join('PS', '%s.eps' % g)
223 env.Command(eps, fig, "%s -L eps $SOURCES $TARGET" % fig2dev)
226 if docs[doc].get('pdf') and pdfjadetex:
227 env.Command(pdf, main, [
228 "rm -f ${TARGET.dir}/%s" % out,
229 "jw -b pdf -o ${TARGET.dir} $SOURCES",
230 "mv ${TARGET.dir}/main.pdf $TARGET",
231 "rm -f ${TARGET.dir}/out",
234 env.Ignore(pdf, "version.sgml")
237 tar_list = tar_list + " " + pdf
239 if docs[doc].get('text') and jade and lynx:
240 env.Command(text, html, "lynx -dump ${SOURCE.abspath} > $TARGET")
242 env.Ignore(text, "version.sgml")
244 tar_deps.append(text)
245 tar_list = tar_list + " " + text
248 # Man page(s), in good ol' troff format.
250 scons_1 = os.path.join('man', 'scons.1')
253 ps = os.path.join('PS', 'scons-man.ps')
254 text = os.path.join('TEXT', 'scons-man.txt')
256 env.Command(ps, scons_1, "groff -man -Tps $SOURCES > $TARGET")
258 env.Command(text, scons_1, "groff -man -Tascii $SOURCES > $TARGET")
260 tar_deps.extend([ps, text])
261 tar_list = string.join([tar_list, ps, text], " ")
264 html = os.path.join('HTML' , 'scons-man.html')
266 cmds = [ "man2html $SOURCES > $TARGET" ]
268 cmds.append("tidy -m -q $TARGET || true")
269 env.Command(html, scons_1, cmds)
271 tar_deps.append(html)
272 tar_list = tar_list + " " + html
275 # Now actually create the tar file of the documentation,
276 # for easy distribution to the web site.
279 env.Command(doc_tar_gz, tar_deps,
280 "tar cf${TAR_HFLAG} - -C build/doc %s | gzip > $TARGET" % tar_list)