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