Fix doxygen path build error
[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 = env.Dir('#/senf').abspath
131     pathbasel = len(pathbase)+1
132     for module in env.Alias('all_docs')[0].sources:
133         if module.name != 'html.stamp' : continue 
134         if not module.dir.dir.dir.abspath.startswith(pathbase): continue
135         mods[module.dir.dir.dir.abspath] = [ module.dir.dir.dir.abspath[pathbasel:].replace('/','_'),
136                                              module.dir.dir.dir.name,
137                                              module.dir.abspath[pathbasel:],
138                                              0 ]
139         
140     rv = []
141     keys = mods.keys()
142     keys.sort()
143     for mod in keys:
144         i = 0
145         while i < len(rv):
146             if len(rv[i]) > pathbasel and mod.startswith(rv[i] + '/'):
147                 level = mods[rv[i]][-1] + 1
148                 i += 1
149                 while i < len(rv) and mods[rv[i]][2] >= level:
150                     i += 1
151                 rv[i:i] = [ mod ]
152                 mods[mod][-1] = level
153                 break
154             i += 1
155         if i == len(rv):
156             rv.append(mod)
157
158     return ( tuple(mods[mod]) for mod in rv )
159
160 def indices():
161     ix = len(env.Dir('#').abspath)+1
162     return [ doc.dir.abspath[ix:]
163              for doc in env.Alias('all_docs')[0].sources
164              if doc.name == "search.idx" ]
165
166 def writeTemplate(target = None, source = None, env = None):
167     file(target[0].abspath,"w").write(processTemplate(env))
168
169 def processTemplate(env):
170     return yaptu.process(str(env['TEMPLATE']), globals(), env.Dictionary())
171
172 writeTemplate = env.Action(writeTemplate, varlist = [ 'TEMPLATE' ])
173
174 ###########################################################################
175
176 HEADER = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
177 <html>
178 <head>
179 <title>$title</title>
180 <link href="@TOPDIR@/doc/html/doxygen.css" rel="stylesheet" type="text/css">
181 <link href="@TOPDIR@/doclib/senf.css" rel="stylesheet" type="text/css">
182 <link rel="shortcut icon" href="@TOPDIR@/doclib/favicon.ico">
183 <style type="text/css">
184 div.tabs li.$projectname a { background-color: #EDE497; }
185 </style>
186 </head>
187 <body>
188
189 <div id="head">
190   <div id="title">
191     <div id="title2">
192       <div id="search">
193         <form action="@TOPDIR@/doclib/search.php" method="get">
194           Search: <input type="text" name="query" size="20" accesskey="s"/> 
195         </form>
196       </div>
197       <h1>SENF Extensible Network Framework</h1>
198     </div>
199   </div>
200   <div id="subtitle">
201     <ul>
202       <li><a href="@TOPDIR@/doc/html/index.html">Home</a></li>
203       <li><a class="ext" href="http://satext.fokus.fraunhofer.de/senf/debian">Download</a></li>
204       <li><a class="ext" href="http://openfacts2.berlios.de/wikien/index.php/BerliosProject:SENF_Network_Framework">Wiki</a></li>
205       <li><a class="ext" href="http://developer.berlios.de/projects/senf">BerliOS</a></li>
206       <li><a class="ext" href="http://svn.berlios.de/wsvn/senf/?op=log&rev=0&sc=0&isdir=1">ChangeLog</a></li>
207       <li><a class="ext" href="http://svn.berlios.de/viewcvs/senf/trunk/">Browse SVN</a></li>
208       <li><a class="ext" href="http://developer.berlios.de/bugs/?group_id=7489">Bug Tracker</a></li>
209     </ul>
210   </div>
211 </div>
212
213 <div id="content1">
214   <div id="content2">
215     <div class="tabs menu">
216       <li class="Overview level0"><a href="@TOPDIR@/doc/html/index.html">Overview</a></li>
217       <li class="Examples level0"><a href="@TOPDIR@/Examples/doc/html/index.html">Examples</a></li>
218       <li class="HowTos level0"><a href="@TOPDIR@/HowTos/doc/html/index.html">HowTos</a></li>
219       <li class="glossary level0"><a href="@TOPDIR@/doc/html/glossary.html">Glossary</a></li>
220     </div>
221     <div class="tabs menu">
222       <ul>
223 {{      for id, name, path, level in modules():
224           <li class="${id} level${level}"><a href="@TOPDIR@/senf/${path}/index.html">${name}</a></li>
225 }}
226       </ul>
227     </div>"""
228
229 FOOTER = """<hr style="width:0px;border:none;clear:both;margin:0;padding:0" />
230   </div>
231 </div>
232 <div id="footer">
233   <span>
234     <a href="mailto:senf-dev@lists.berlios.de">Contact: senf-dev@lists.berlios.de</a> |
235     Copyright &copy; 2006 Fraunhofer Gesellschaft, SatCom, Stefan Bund
236   </span>
237 </div>
238 </body></html>"""
239
240 SEARCH_PHP="""
241 <?php include 'search_functions.php'; ?>
242 <?php search(); ?>"""
243
244 SEARCH_PATHS_PHP="""<?php
245 function paths() {
246   return array(
247 {{  for index in indices():
248       "../${index}/",
249 }}
250   );
251 }
252 ?>"""
253
254 env.SetDefault(
255     DOXYGEN = "doxygen"
256 )
257
258 env.Replace(
259     DOXYGENCOM = "doclib/doxygen.sh $DOXYOPTS $SOURCE",
260 )
261
262 env.Append( ENV = {
263     'TODAY' : str(datetime.date.today()),
264     'TEXINPUTS' : os.environ.get('TEXINPUTS',env.Dir('#/doclib').abspath + ':'),
265     'DOXYGEN' : str(env.File(env['DOXYGEN'])),
266 })
267
268 env.PhonyTarget('linklint', [], [
269     'rm -rf linklint',
270     'linklint -doc linklint -limit 99999999 `find -type d -name html -printf "/%P/@ "`',
271     '[ ! -r linklint/errorX.html ] || python doclib/linklint_addnames.py <linklint/errorX.html >linklint/errorX.html.new',
272     '[ ! -r linklint/errorX.html.new ] || mv linklint/errorX.html.new linklint/errorX.html',
273     '[ ! -r linklint/errorAX.html ] || python doclib/linklint_addnames.py <linklint/errorAX.html >linklint/errorAX.html.new',
274     '[ ! -r linklint/errorAX.html.new ] || mv linklint/errorAX.html.new linklint/errorAX.html',
275     'echo -e "\\nLokal link check results: linklint/index.html\\nRemote link check results: linklint/urlindex.html\\n"',
276 ])
277
278 env.PhonyTarget('fixlinks', [], [
279     'python doclib/fix-links.py -v -s .svn -s linklint -s debian linklint/errorX.txt linklint/errorAX.txt',
280 ])
281
282
283 header = env.Command('doxy-header.html', 'SConscript', writeTemplate,
284                      TEMPLATE = Literal(HEADER),
285                      TITLE = "Documentation and API reference")
286 env.Depends(header, env.Value(repr(list(modules()))))
287
288 footer = env.Command('doxy-footer.html', 'SConscript', writeTemplate,
289                      TEMPLATE = Literal(FOOTER))
290
291 env.Alias('all_docs',
292           env.Command('search.php', [ 'html-munge.xsl', 'SConscript' ],
293                       [ writeTemplate,
294                         'xsltproc --nonet --html --stringparam topdir .. -o - $SOURCE $TARGET 2>/dev/null'
295                             + "| sed"
296                             +   r" -e 's/\[\[/<?/g' -e 's/\]\]/?>/g'"
297                             +   r" -e 's/\$$projectname/Overview/g'"
298                             +   r" -e 's/\$$title/Search results/g'"
299                             +       "> ${TARGETS[0]}.tmp",
300                         'mv ${TARGET}.tmp ${TARGET}' ],
301                       TEMPLATE = Literal(HEADER
302                                          + SEARCH_PHP.replace('<?','[[').replace('?>',']]')
303                                          + FOOTER),
304                       TITLE = "Search results"))
305 env.Alias('all_docs',
306           env.Command('search_paths.php', 'SConscript', writeTemplate,
307                       TEMPLATE = Literal(SEARCH_PATHS_PHP)))
308
309 env.Alias('install_all',
310           env.Install( '$DOCINSTALLDIR/doclib', [ 'favicon.ico',
311                                                   'logo-head.png',
312                                                   'search.php',
313                                                   'search_functions.php',
314                                                   'search_paths.php',
315                                                   'senf.css' ] ))
316
317 env.Clean('all', 'doxy-header.html') # I should not need this but I do ...
318 env.Clean('all_docs', 'doxy-header.html') # I should not need this but I do ...