minor fixes for clang++
[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 site_scons/lib/.
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
56 #   site_scon/lib/doxygen.sh
57 #
58 #
59 # 3.1. Building prerequisites
60 #
61 # The prerequisites are images referenced by the documentation. These
62 # images are mostly generated using the Dia2Png builder.
63 #
64 #
65 # 3.2. The main doxygen build (Doxygen builder)
66 #
67 # The Doxygen builder will call the doxygen command to build the
68 # documentation.
69 #
70 # The doxygen command is configured as 'site_scon/lib/doxygen.sh' which
71 # does some additional processing in addition to calling doxygen
72 # proper
73 #
74 # * it sets environment variables depending on command line arguments.
75 #   These variables are then used in the Doxyfile's
76 #
77 # * after doxygen is finished, 'installdox' is called to resolve
78 #   tag file references.
79 #
80 # * the HTML documentation is post-processed using some sed, tidy, and
81 #   an XSLT template
82 #
83 # * a generated tag file is post-processed using an XSLT template
84 #
85 # (see site_scon/lib/doxygen.sh for more information). The Doxygen
86 # configuration is set up such, that
87 #
88 # * doxygen calls 'site_scons/lib/filter.pl' on each source file. This
89 #   filter will strip excess whitespace from the beginning of lines in
90 #   '\code' and '<pre>' blocks. Additionally it will expand all tabs,
91 #   tab width is 8 spaces (there should be no tabs in the source but
92 #   ...)
93 #
94 # * 'site_scons/lib/filter.pl' calls 'site_scons/lib/makeDiaImageMap.py'
95 #   whenever finding a '\diaimage' command. This will create an image
96 #   map (in an encoded form which will be fixed by html-munge.xsl
97 #   later)
98 #
99 # * doxygen calls 'site_scons/lib/dot' to generate the 'dot' images.
100 #
101 # * 'site_scons/lib/dot' calls 'site_scons/lib/dot-munge.pl' on the
102 #    .dot files. dot-munge.pl changes the font and font-size and adds
103 #    line-breaks to long labels
104 #
105 # * 'site_scons/lib/dot' calls the real dot binary. If the resulting
106 #   image is more than 800 pixels wide, dot is called again, this time
107 #   using the oposite rank direction (top-bottom vs. left-right). The
108 #   image with the smaller width is selected and returned.
109 #
110 #
111 # 4. Fixing broken links
112 #
113 # After the documentation has been generated, additional calls first
114 # to the 'linklint' and then to the 'fixlinks' target will try to fix
115 # broken links generated by doxygen. First, 'linklint' will call the
116 # linklint tool to check for broken links in the documentation.
117 #
118 # 'fixlinks' is then called which calls 'doclib/fixlinks.py' which
119 # scans *all* html files, builds an index of all (unique) anchors and
120 # then fixes the url part of all links with correct anchor but bad
121 # file name.
122 #
123
124
125 Import('env')
126 import SENFSCons, datetime, os
127
128 ###########################################################################
129
130 import yaptu
131
132 def modules():
133     # Naja ... etwas rumgehackt aber was solls ...
134     global EXTRA_MODULES
135     mods = {}
136     pathbase = env.Dir('#/senf').abspath
137     pathbasel = len(pathbase)+1
138     for module in env.Alias('all_docs')[0].sources:
139         if module.name != 'html.stamp' : continue
140         if not module.dir.dir.dir.abspath.startswith(pathbase): continue
141         mods[module.dir.dir.dir.abspath] = [ module.dir.dir.dir.abspath[pathbasel:].replace('/','_'),
142                                              module.dir.dir.dir.name,
143                                              module.dir.abspath[pathbasel:],
144                                              0 ]
145
146     rv = []
147     keys = mods.keys()
148     keys.sort()
149     for mod in keys:
150         i = 0
151         while i < len(rv):
152             if len(rv[i]) > pathbasel and mod.startswith(rv[i] + '/'):
153                 level = mods[rv[i]][-1] + 1
154                 i += 1
155                 while i < len(rv) and mods[rv[i]][2] >= level:
156                     i += 1
157                 rv[i:i] = [ mod ]
158                 mods[mod][-1] = level
159                 break
160             i += 1
161         if i == len(rv):
162             rv.append(mod)
163
164     return ( tuple(mods[mod]) for mod in rv )
165
166 def indices():
167     ix = len(env.Dir('#').abspath)+1
168     return [ doc.dir.abspath[ix:]
169              for doc in env.Alias('all_docs')[0].sources
170              if doc.name == "search.idx" ]
171
172 def writeTemplate(target = None, source = None, env = None):
173     file(target[0].abspath,"w").write(processTemplate(env))
174
175 def processTemplate(env):
176     return yaptu.process(str(env['TEMPLATE']), globals(), env.Dictionary())
177
178 writeTemplate = env.Action(writeTemplate, varlist = [ 'TEMPLATE' ])
179
180 ###########################################################################
181
182 HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
183 <html>
184 <head>
185 <title>$title</title>
186 <link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
187 <link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
188 <link rel="shortcut icon" href="@TOPDIR@/doclib/favicon.ico">
189 <style type="text/css">
190 div.tabs li.$projectname a { background-color: #EDE497; }
191 </style>
192 </head>
193 <body>
194
195 <div id="head">
196   <div id="title">
197     <div id="title2">
198       <div id="search">
199         <form action="@TOPDIR@/doclib/search.php" method="get">
200           Search: <input type="text" name="query" size="20" accesskey="s"/>
201         </form>
202       </div>
203       <h1>SENF Extensible Network Framework</h1>
204     </div>
205   </div>
206   <div id="subtitle">
207     <ul>
208       <li><a href="@TOPDIR@/doc/html/index.html">Home</a></li>
209       <li><a class="ext" href="http://satext.fokus.fraunhofer.de/senf/debian">Download</a></li>
210       <li><a class="ext" href="http://openfacts2.berlios.de/wikien/index.php/BerliosProject:SENF_Network_Framework">Wiki</a></li>
211       <li><a class="ext" href="http://developer.berlios.de/projects/senf">BerliOS</a></li>
212       <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">ChangeLog</a></li>
213       <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/trunk/">Browse SVN</a></li>
214       <li><a class="ext" href="http://developer.berlios.de/bugs/?group_id=7489">Bug Tracker</a></li>
215     </ul>
216   </div>
217 </div>
218
219 <div id="content1">
220   <div id="content2">
221     <div class="tabs menu">
222       <li class="Overview level0"><a href="@TOPDIR@/doc/html/index.html">Overview</a></li>
223       <li class="Examples level0"><a href="@TOPDIR@/Examples/doc/html/index.html">Examples</a></li>
224       <li class="HowTos level0"><a href="@TOPDIR@/HowTos/doc/html/index.html">HowTos</a></li>
225       <li class="glossary level0"><a href="@TOPDIR@/doc/html/glossary.html">Glossary</a></li>
226     </div>
227     <div class="tabs menu">
228       <ul>
229 {{      for id, name, path, level in modules():
230           <li class="${id} level${level}"><a href="@TOPDIR@/senf/${path}/index.html">${name}</a></li>
231 }}
232       </ul>
233     </div>"""
234
235 FOOTER = """<hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
236   </div>
237 </div>
238 <div id="footer">
239   <span>
240     <a href="mailto:senf-dev@lists.berlios.de">Contact: senf-dev@lists.berlios.de</a> |
241     &copy; 2006-2010 <a href="http://www.fokus.fraunhofer.de/en/net/index.html">
242     Fraunhofer Institute for Open Communication Systems, Network Research</a>
243   </span>
244 </div>
245 </body></html>"""
246
247 SEARCH_PHP="""
248 <?php include 'search_functions.php'; ?>
249 <?php search(); ?>"""
250
251 SEARCH_PATHS_PHP="""<?php
252 function paths() {
253   return array(
254 {{  for index in indices():
255       "../${index}/",
256 }}
257   );
258 }
259 ?>"""
260
261 env.SetDefault(
262     DOXYGEN = "doxygen"
263 )
264
265 env.Append( ENV = {
266     'TODAY' : str(datetime.date.today()),
267 })
268
269 env.PhonyTarget('linklint', [], [
270     'rm -rf doc/linklint',
271     'linklint -doc doc/linklint -limit 99999999 `find -type d -name html -printf "/%P/@ "`',
272 ])
273
274 env.PhonyTarget('fixlinks', [], [
275     'python doclib/fix-links.py -v -s .svn -s linklint -s debian -s doclib -s search',
276 ])
277
278 header = env.Command('doxy-header.html', 'SConscript', writeTemplate,
279                      TEMPLATE = Literal(HEADER),
280                      TITLE = "Documentation and API reference")
281 env.Depends(header, env.Value(repr(list(modules()))))
282
283 footer = env.Command('doxy-footer.html', 'SConscript', writeTemplate,
284                      TEMPLATE = Literal(FOOTER))
285
286 env.Alias('all_docs',
287           env.Command('search.php', [ '#/site_scons/lib/html-munge.xsl', 'SConscript' ],
288                       [ writeTemplate,
289                         'xsltproc --nonet --html --stringparam topdir .. -o - $SOURCE $TARGET 2>/dev/null'
290                             + "| sed"
291                             +   r" -e 's/\[\[/<?/g' -e 's/\]\]/?>/g'"
292                             +   r" -e 's/\$$projectname/Overview/g'"
293                             +   r" -e 's/\$$title/Search results/g'"
294                             +       "> ${TARGETS[0]}.tmp",
295                         'mv ${TARGET}.tmp ${TARGET}' ],
296                       TEMPLATE = Literal(HEADER
297                                          + SEARCH_PHP.replace('<?','[[').replace('?>',']]')
298                                          + FOOTER),
299                       TITLE = "Search results"))
300 env.Alias('all_docs',
301           env.Command('search_paths.php', 'SConscript', writeTemplate,
302                       TEMPLATE = Literal(SEARCH_PATHS_PHP)))
303
304 env.Alias('install_all',
305           env.Install( '$DOCINSTALLDIR/doclib', [ 'favicon.ico',
306                                                   'logo-head.png',
307                                                   'search.php',
308                                                   'search_functions.php',
309                                                   'search_paths.php',
310                                                   'senf.css' ] ))
311
312 env.Clean('all', 'doxy-header.html') # I should not need this but I do ...
313 env.Clean('all_docs', 'doxy-header.html') # I should not need this but I do ...
314
315 env.Install('${DOCINSTALLDIR}', 'index.html')
316
317 env.Depends(SENFSCons.Doxygen(env, output_directory="../doc"), env.Value(env['ENV']['REVISION']))