9fbf7d9f0c18a0da6ae43741c8eb5d740271e953
[senf.git] / doclib / SConscript
1 # -*- python -*-
2 #
3 # The documentation generation process is tightly integrated with the
4 # scons build framework:
5
6 # * SCons analyzes the Doxyfile's to find all the documentation
7 #   dependencies. This happens in the doxygen builder in
8 #   senfscons/Doxygen.py.
9 #
10 # * the doclib/doxy-header.html and/or doclib/doxy-footer.html files
11 #   are regenerated
12
13 # * If any documentation is out-of-date with respect to it's source
14 #   files, the documentation is regenerated.
15
16 # * To fix some link errors, the additional 'linklint' and 'fixlinks'
17 #   targets are used
18 #
19
20 # 1. Scanning the Doxyfile's
21
22 # The doxygen builder scans all documentation source files which have
23 # the text 'doxyfile' in any case in their name. It understands
24 # @INCLUDE directives and will find all the dependencies of the
25 # documentation:
26
27 # * All the source files as selected by INPUT, INPUT_PATTERN,
28 #   RECURSIVE and so on.
29
30 # * Any referenced tag-files
31
32 # * Documentation header and/or footer
33
34 # * The INPUT_FILTER program
35
36 # * Any included doxygen configuration files
37
38 #
39 # 2. Regenerating header and/or footer
40 #
41 # If needed, the doxy-header.html and/or doxy-footer.html file will be
42 # regenerated. The header and/or footer are generated from templates
43 # using a simple python based templating system called yaptu which is
44 # included in doclib/.
45 #
46
47 # 3. Calling doxygen
48
49 # The doxygen call itself is quite complex since there is some pre-
50 # and post-processing going on. We can separate this step into two
51 # steps
52 #
53 # * Building prerequisites (e.g. images)
54 #
55 # * The processing done by the Doxygen builder and doclib/doxygen.sh
56 #
57 #
58 # 3.1. Building prerequisites
59 #
60 # The prerequisites are images referenced by the documentation. These
61 # images are mostly generated using the Dia2Png builder.
62 #
63 #
64 # 3.2. The main doxygen build (Doxygen builder)
65 #
66 # The Doxygen builder will call the doxygen command to build the
67 # documentation. 
68 #
69 # The doxygen command is configured as 'doclib/doxygen.sh' which
70 # does some additional processing in addition to calling doxygen
71 # proper
72 #
73 # * it sets environment variables depending on command line arguments.
74 #   These variables are then used in the Doxyfile's
75 #
76 # * after doxygen is finished, 'installdox' is called to resolve 
77 #   tag file references.
78 #
79 # * the HTML documentation is post-processed using some sed, tidy, and
80 #   an XSLT template
81 #
82 # * a generated tag file is post-processed using an XSLT template
83 #
84 # (see doclib/doxygen.sh for more information). The Doxygen
85 # configuration is set up such, that
86 #
87 # * doxygen calls 'doclib/filter.pl' on each source file. This filter
88 #   will strip excess whitespace from the beginning of lines in
89 #   '\code' and '<pre>' blocks. Additionally it will expand all tabs,
90 #   tab width is 8 spaces (there should be no tabs in the source but
91 #   ...)
92
93 # * doxygen calls 'doclib/dot' to generate the 'dot' images.
94 #
95 # * 'doclib/dot' calls 'doclib/dot-munge.pl' on the .dot
96 #    files. dot-munge.pl changes the font and font-size and adds
97 #    line-breaks to long labels
98 #
99 # * 'doclib/dot' calls the real dot binary. If the resulting image is
100 #   more than 800 pixels wide, dot is called again, this time using
101 #   the oposite rank direction (top-bottom vs. left-right). The image
102 #   with the smaller width is selected and returned.
103 #
104 #
105 # 4. Fixing broken links
106 #
107 # After the documentation has been generated, additional calls first
108 # to the 'linklint' and then to the 'fixlinks' target will try to fix
109 # broken links generated by doxygen. First, 'linklint' will call the
110 # linklint tool to check for broken links in the documentation.
111 #
112 # 'fixlinks' is then called which calls 'doclib/fixlinks.py' which
113 # scans *all* html files, builds an index of all (unique) anchors and
114 # then fixes the url part of all links with correct anchor but bad
115 # file name.
116 #
117
118
119 Import('env')
120 import SENFSCons, datetime, os
121
122 ###########################################################################
123
124 import yaptu
125
126 def modules():
127     # Naja ... etwas rumgehackt aber was solls ...
128     global EXTRA_MODULES
129     mods = {}
130     pathbase = len(env.Dir('#').abspath)+1
131     for module in env.Alias('all_docs')[0].sources:
132         if module.name != 'html.stamp' : continue 
133         mods[module.dir.dir.dir.abspath] = [ module.dir.dir.dir.name,
134                                              module.dir.abspath[pathbase:],
135                                              0 ]
136         
137     rv = []
138     keys = mods.keys()
139     keys.sort()
140     for mod in keys:
141         i = 0
142         while i < len(rv):
143             if len(rv[i]) > pathbase and mod.startswith(rv[i] + '/'):
144                 level = mods[rv[i]][2] + 1
145                 i += 1
146                 while i < len(rv) and mods[rv[i]][2] >= level:
147                     i += 1
148                 rv[i:i] = [ mod ]
149                 mods[mod][2] = level
150                 break
151             i += 1
152         if i == len(rv):
153             rv.append(mod)
154
155     for mod in keys:
156         if mods[mod][2] == 0:
157             mods[mod][0] = 'lib' + mods[mod][0]
158
159     n = 0
160     for name,path in EXTRA_MODULES:
161         path = env.Dir(path).dir.dir.abspath
162         i = 0
163         while i < len(rv):
164             if rv[i] == path:
165                 mods[rv[i]][0] = name
166                 m = 1
167                 while i+m < len(rv) and mods[rv[i+m]][2] > mods[rv[i]][2]:
168                     m += 1
169                 rv[n:n] = rv[i:i+m]
170                 rv[i+m:i+2*m] = []
171                 i += m
172                 n += m
173             else:
174                 i += 1
175
176     return ( tuple(mods[mod]) for mod in rv )
177
178 def indices():
179     ix = len(env.Dir('#').abspath)+1
180     return [ doc.dir.abspath[ix:]
181              for doc in env.Alias('all_docs')[0].sources
182              if doc.name == "search.idx" ]
183
184 def writeTemplate(target = None, source = None, env = None):
185     file(target[0].abspath,"w").write(processTemplate(env))
186
187 def processTemplate(env):
188     return yaptu.process(str(env['TEMPLATE']), globals(), env.Dictionary())
189
190 writeTemplate = env.Action(writeTemplate, varlist = [ 'TEMPLATE' ])
191
192 ###########################################################################
193
194 # Extra documentation modules which are handled (named) different from
195 # library modules
196 EXTRA_MODULES = [
197     ('Overview', '#/doc/html'),
198     ('Examples', '#/Examples/doc/html'),
199     ('HowTos', '#/HowTos/doc/html'),
200     ('SENFSCons', '#/senfscons/doc/html') ]
201
202 HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
203 <html>
204 <head>
205 <title>$title</title>
206 <link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
207 <link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
208 <link rel="shortcut icon" href="@TOPDIR@/doclib/favicon.ico">
209 <style type="text/css">
210 div.tabs li.$projectname a { background-color: #EDE497; }
211 </style>
212 </head>
213 <body>
214
215 <div id="head">
216   <div id="title">
217     <div id="title2">
218       <div id="search">
219         <form action="@TOPDIR@/doclib/search.php" method="get">
220           Search: <input type="text" name="query" size="20" accesskey="s"/> 
221         </form>
222       </div>
223       <h1>SENF Extensible Network Framework</h1>
224     </div>
225   </div>
226   <div id="subtitle">
227     <ul>
228       <li><a href="@TOPDIR@/doc/html/index.html">Home</a></li>
229       <li><a class="ext" href="http://satext.fokus.fraunhofer.de/senf/debian">Download</a></li>
230       <li><a class="ext" href="http://openfacts2.berlios.de/wikien/index.php/BerliosProject:SENF_Network_Framework">Wiki</a></li>
231       <li><a class="ext" href="http://developer.berlios.de/projects/senf">BerliOS</a></li>
232       <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">ChangeLog</a></li>
233       <li><a class="ext" href="http://svn.berlios.de/viewcvs/senf/trunk/">Browse SVN</a></li>
234       <li><a class="ext" href="http://developer.berlios.de/bugs/?group_id=7489">Bug Tracker</a></li>
235     </ul>
236   </div>
237 </div>
238
239 <div id="content1">
240   <div id="content2">
241     <div class="tabs menu">
242       <ul>
243 {{      for name, path, level in modules():
244           <li class="${name} level${level}"><a href="@TOPDIR@/${path}/index.html">${name}</a></li>
245 }}
246         <li class="glossary level0"><a href="@TOPDIR@/doc/html/glossary.html">Glossary</a></li>
247       </ul>
248     </div>"""
249
250 FOOTER = """<hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
251   </div>
252 </div>
253 <div id="footer">
254   <span>
255     <a href="mailto:senf-dev@lists.berlios.de">Contact: senf-dev@lists.berlios.de</a> |
256     Copyright &copy; 2006 Fraunhofer Gesellschaft, SatCom, Stefan Bund
257   </span>
258 </div>
259 </body></html>"""
260
261 SEARCH_PHP="""
262 <?php include 'search_functions.php'; ?>
263 <?php search(); ?>"""
264
265 SEARCH_PATHS_PHP="""<?php
266 function paths() {
267   return array(
268 {{  for index in indices():
269       "../${index}/",
270 }}
271   );
272 }
273 ?>"""
274
275 env.Append( ENV = {
276     'TODAY' : str(datetime.date.today()),
277     'TEXINPUTS' : os.environ.get('TEXINPUTS',env.Dir('#/doclib').abspath + ':'),
278     'DOXYGEN' : env.get('DOXYGEN', 'doxygen'),
279 })
280
281 env.Replace(
282     ALL_TAGFILES = [],
283     DOXYGENCOM = "doclib/doxygen.sh $DOXYOPTS $SOURCE",
284 )
285
286 env.PhonyTarget('linklint', [], [
287     'rm -rf linklint',
288     'linklint -doc linklint -limit 99999999 `find -type d -name html -printf "/%P/@ "`',
289     '[ ! -r linklint/errorX.html ] || python doclib/linklint_addnames.py <linklint/errorX.html >linklint/errorX.html.new',
290     '[ ! -r linklint/errorX.html.new ] || mv linklint/errorX.html.new linklint/errorX.html',
291     '[ ! -r linklint/errorAX.html ] || python doclib/linklint_addnames.py <linklint/errorAX.html >linklint/errorAX.html.new',
292     '[ ! -r linklint/errorAX.html.new ] || mv linklint/errorAX.html.new linklint/errorAX.html',
293     'echo -e "\\nLokal link check results: linklint/index.html\\nRemote link check results: linklint/urlindex.html\\n"',
294 ])
295
296 env.PhonyTarget('fixlinks', [], [
297     'python doclib/fix-links.py -v -s .svn -s linklint -s debian linklint/errorX.txt linklint/errorAX.txt',
298 ])
299
300
301 header = env.Command('doxy-header.html', 'SConscript', writeTemplate,
302                      TEMPLATE = Literal(HEADER),
303                      TITLE = "Documentation and API reference")
304 env.Depends(header, env.Value(repr(list(modules()))))
305
306 footer = env.Command('doxy-footer.html', 'SConscript', writeTemplate,
307                      TEMPLATE = Literal(FOOTER))
308
309 env.Alias('all_docs',
310           env.Command('search.php', [ 'html-munge.xsl', 'SConscript' ],
311                       [ writeTemplate,
312                         'xsltproc --nonet --html --stringparam topdir .. -o - $SOURCE $TARGET 2>/dev/null'
313                             + "| sed"
314                             +   r" -e 's/\[\[/<?/g' -e 's/\]\]/?>/g'"
315                             +   r" -e 's/\$$projectname/Overview/g'"
316                             +   r" -e 's/\$$title/Search results/g'"
317                             +       "> ${TARGETS[0]}.tmp",
318                         'mv ${TARGET}.tmp ${TARGET}' ],
319                       TEMPLATE = Literal(HEADER
320                                          + SEARCH_PHP.replace('<?','[[').replace('?>',']]')
321                                          + FOOTER),
322                       TITLE = "Search results"))
323 env.Alias('all_docs',
324           env.Command('search_paths.php', 'SConscript', writeTemplate,
325                       TEMPLATE = Literal(SEARCH_PATHS_PHP)))
326
327 env.Alias('install_all',
328           env.Install( '$DOCINSTALLDIR/doclib', [ 'favicon.ico',
329                                                   'logo-head.png',
330                                                   'search.php',
331                                                   'search_functions.php',
332                                                   'search_paths.php',
333                                                   'senf.css' ] ))
334
335 env.Clean('all', 'doxy-header.html') # I should not need this but I do ...
336 env.Clean('all_docs', 'doxy-header.html') # I should not need this but I do ...