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