OSDN Git Service

2009-02-18 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / scripts / run_doxygen
1 #!/bin/bash
2
3 # Runs doxygen and massages the output files.
4 # Copyright (C) 2001, 2002, 2003, 2004, 2008 Free Software Foundation, Inc.
5 #
6 # Synopsis:  run_doxygen --mode=[html|man|xml] --host_alias=<alias> \
7 #                        v3srcdir  v3builddir
8 #
9 # Originally hacked together by Phil Edwards <pme@gcc.gnu.org>
10
11
12 # We can check now that the version of doxygen is >= this variable.
13 DOXYVER=1.5.1
14
15 find_doxygen() {
16     local -r v_required=`echo $DOXYVER |  \
17                 awk -F. '{if(NF<3)$3=0;print ($1*100+$2)*100+$3}'`
18     local testing_version doxygen maybedoxy v_found
19     # thank you goat book
20     set `IFS=:; X="$PATH:/usr/local/bin:/bin:/usr/bin"; echo $X`
21     for dir
22     do
23       # AC_EXEEXT could come in useful here
24       maybedoxy="$dir/doxygen"
25       test -f "$maybedoxy" && testing_version=`$maybedoxy --version`
26       if test -n "$testing_version"; then
27        v_found=`echo $testing_version |  \
28                 awk -F. '{if(NF<3)$3=0;print ($1*100+$2)*100+$3}'`
29        if test $v_found -ge $v_required; then
30          doxygen="$maybedoxy"
31          break
32        fi
33       fi
34     done
35     if test -z "$doxygen"; then
36         echo run_doxygen error:  Could not find Doxygen $DOXYVER in path. 1>&2
37         print_usage
38     fi
39     # We need to use other tools from the same package/version.
40     echo :: Using Doxygen tools from ${dir}.
41     PATH=$dir:$PATH
42     hash -r
43 }
44
45 print_usage() {
46     cat 1>&2 <<EOF
47 Usage:  run_doxygen --mode=MODE --host_alias=BUILD_ALIAS [<options>]
48                     <v3-src-dir> <v3-build-dir>
49       MODE is one of:
50           html           Generate user-level HTML library documentation.
51           man            Generate user-level man pages.
52           xml            Generate user-level XML pages.
53
54       BUILD_ALIAS is the GCC build alias set at configure time.
55
56 Note:  Requires Doxygen ${DOXYVER} or later; get it at
57        ftp://ftp.stack.nl/pub/users/dimitri/doxygen-${DOXYVER}.src.tar.gz
58
59 EOF
60     exit 1
61 }
62
63 parse_options() {
64   for o
65   do
66     # Blatantly ripped from autoconf, er, I mean, "gratefully standing
67     # on the shoulders of those giants who have gone before us."
68     case "$o" in
69       -*=*) arg=`echo "$o" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
70       *) arg= ;;
71     esac
72
73     case "$o" in
74       --mode=*)
75         mode=$arg ;;
76       --host_alias=*)
77         host_alias=$arg ;;
78       --mode | --host_alias | --help | -h)
79         print_usage ;;
80       *)
81         # this turned out to be a mess, maybe change to --srcdir=, etc
82         if test $srcdir = unset; then
83           srcdir=$o
84         elif test $outdir = unset; then
85           builddir=${o}
86           outdir=${o}/doc/doxygen
87         else
88           echo run_doxygen error:  Too many arguments 1>&2
89           exit 1
90         fi
91         ;;
92       esac
93   done
94 }
95
96
97 # script begins here
98 mode=unset
99 host_alias=unset
100 srcdir=unset
101 outdir=unset
102 do_html=false
103 do_man=false 
104 do_xml=false 
105 enabled_sections=
106 generate_tagfile=
107 DATEtext=`date '+%Y-%m-%d'`
108
109 # Show how this script is called.
110 echo run_doxygen $*
111
112 parse_options $*
113 find_doxygen
114
115 if test $srcdir = unset || test $outdir = unset || test $mode = unset || test $host_alias = unset; then
116     # this could be better
117     echo run_doxygen error:  You have not given enough information...! 1>&2
118     print_usage
119 fi
120
121 case x"$mode" in
122     xhtml)
123       do_html=true
124       enabled_sections=maint
125       generate_tagfile="$outdir/html/libstdc++.tag"
126       ;;
127     xman)
128       do_man=true
129       ;;
130     xxml)
131       do_xml=true
132       enabled_sections=maint
133       ;;
134     *)
135       echo run_doxygen error:  $mode is an invalid mode 1>&2
136       exit 1 ;;
137 esac
138
139 mkdir -p $outdir
140 chmod u+w $outdir
141
142 # work around a stupid doxygen bug
143 if $do_man; then
144     mkdir -p $outdir/man/man3/ext
145     chmod -R u+w $outdir/man/man3/ext
146 fi
147
148 if $do_xml; then
149     mkdir -p $outdir/xml
150 fi
151
152 (
153   set -e
154   cd $builddir
155   sed -e "s=@outdir@=${outdir}=g" \
156       -e "s=@srcdir@=${srcdir}=g" \
157       -e "s=@builddir@=${builddir}=g" \
158       -e "s=@host_alias@=${host_alias}=g" \
159       -e "s=@enabled_sections@=${enabled_sections}=" \
160       -e "s=@do_html@=${do_html}=" \
161       -e "s=@do_man@=${do_man}=" \
162      -e "s=@do_xml@=${do_xml}=" \
163       -e "s=@generate_tagfile@=${generate_tagfile}=" \
164       ${srcdir}/doc/doxygen/user.cfg.in > ${outdir}/${mode}.cfg
165   echo :: NOTE that this may take some time...
166   echo doxygen ${outdir}/${mode}.cfg
167   doxygen ${outdir}/${mode}.cfg
168   echo :: Finished, exit code was $?
169 )
170 ret=$?
171 test $ret -ne 0 && exit $ret
172
173 if $do_html; then
174   cd ${outdir}/html
175
176   #doxytag -t libstdc++.tag . > /dev/null 2>&1
177   sed -e '/<path>/d' libstdc++.tag > TEMP
178   mv TEMP libstdc++.tag
179
180   sed -e "s=@DATE@=${DATEtext}=" \
181       ${srcdir}/doc/doxygen/mainpage.html > index.html
182
183   # The following bit of line noise changes annoying
184   #   std::foo < typename _Ugly1, typename _Ugly2, .... _DefaultUgly17 >
185   # to user-friendly
186   #   std::foo
187   # in the major "Compound List" page.
188   sed -e 's=\(::[[:alnum:]_]*\)&lt; .* &gt;=\1=' annotated.html > annstrip.html
189   mv annstrip.html annotated.html
190
191   # Work around a bug in doxygen 1.3.
192 #  for f in class*html struct*html; do
193   for f in class*html; do
194       sed '1,10s!^<title> Template!<title>Template !' $f > TEMP
195       mv TEMP $f
196   done
197
198   cp ${srcdir}/doc/doxygen/tables.html tables.html
199   echo ::
200   echo :: HTML pages begin with
201   echo :: ${outdir}/html/index.html
202 fi
203
204 # Mess with the man pages.  We don't need documentation of the internal
205 # headers, since the man pages for those contain nothing useful anyhow.  The
206 # man pages for doxygen modules need to be renamed (or deleted).  And the
207 # generated #include lines need to be changed from the internal names to the
208 # standard ones (e.g., "#include <stl_tempbuf.h>" -> "#include <memory>").
209 if $do_man; then
210 echo ::
211 echo :: Fixing up the man pages...
212 cd $outdir/man/man3
213
214 # here's the other end of the "stupid doxygen bug" mentioned above
215 rm -rf ext
216
217 # File names with embedded spaces (EVIL!) need to be....?  renamed or removed?
218 find . -name "* *" -print0 | xargs -0r rm        # requires GNU tools
219
220 # Cleanups before tr1* files get killed.
221 mv tr1_random_distributions.3 random_distributions.3
222 mv tr1_random_distributions_continuous.3 random_distributions_continuous.3
223 mv tr1_random_distributions_discrete.3 random_distributions_discrete.3
224 mv tr1_random_generators.3 random_generators.3
225
226 # man pages are for functions/types/other entities, not source files
227 # directly.  who the heck would type "man foo.h" anyhow?
228 #find . -name "[a-z]*" -a ! -name "std_*" -print | xargs rm
229 rm -f *.h.3 *.hpp.3 *config* *.cc.3 *.tcc.3 *_t.3
230 rm ext_*.3
231 rm tr1_*.3
232 rm debug_*.3
233
234 # this is used to examine what we would have deleted, for debugging
235 #mkdir trash
236 #find . -name "[a-z]*" -a ! -name "std_*" -print | xargs -i mv {} trash
237 #mv *.h.3 *config* *.cc.3 *.tcc.3 *_t.3  trash
238
239 # Standardize the displayed header names.  If anyone who knows perl cares
240 # enough to rewrite all this, feel free.  This only gets run once a century,
241 # and I'm off getting coffee then anyhow, so I didn't care enough to make
242 # this super-fast.
243 g++ ${srcdir}/doc/doxygen/stdheader.cc -o ./stdheader
244 problematic=`egrep -l '#include <.*_.*>' [a-z]*.3`
245 for f in $problematic; do
246     # this is also slow, but safe and easy to debug
247     oldh=`sed -n '/fC#include </s/.*<\(.*\)>.*/\1/p' $f`
248     newh=`echo $oldh | ./stdheader`
249     sed "s=${oldh}=${newh}=" $f > TEMP
250     mv TEMP $f
251 done
252 rm stdheader
253
254 # Some of the pages for generated modules have text that confuses certain
255 # implementations of man(1), e.g., Linux's.  We need to have another top-level
256 # *roff tag to /stop/ the .SH NAME entry.
257 #problematic=`egrep --files-without-match '^\.SH SYNOPSIS' [A-Z]*.3`
258
259 #problematic='Containers.3 Sequences.3 Assoc_containers.3 Iterator_types.3'
260 #for f in $problematic; do
261 #    sed '/^\.SH NAME/{
262 #n
263 #a\
264 #\
265 #.SH SYNOPSIS
266 #    }' $f > TEMP
267 #    mv TEMP $f
268 #done
269
270 # Also, break this (generated) line up.  It's ugly as sin.
271 problematic=`grep -l '[^^]Definition at line' *.3`
272 for f in $problematic; do
273     sed 's/Definition at line/\
274 .PP\
275 &/'  $f > TEMP
276     mv TEMP $f
277 done
278
279 cp ${srcdir}/doc/doxygen/Intro.3 C++Intro.3
280
281 # Why didn't I do this at the start?  Were rabid weasels eating my brain?
282 # Who the fsck would "man std_vector" when the class isn't named that?
283
284 # First, deal with nested namespaces.
285 for f in *__detail_*; do
286     newname=`echo $f | sed 's/__detail_/__detail::/'`
287     mv $f $newname
288 done
289 for f in *__parallel_*; do
290     newname=`echo $f | sed 's/__parallel_/__parallel::/'`
291     mv $f $newname
292 done
293
294 # Then, clean up other top-level namespaces.
295 for f in std_tr1_*; do
296     newname=`echo $f | sed 's/^std_tr1_/std::tr1::/'`
297     mv $f $newname
298 done
299 for f in std_*; do
300     newname=`echo $f | sed 's/^std_/std::/'`
301     mv $f $newname
302 done
303 for f in __gnu_cxx_*; do
304     newname=`echo $f | sed 's/^__gnu_cxx_/__gnu_cxx::/'`
305     mv $f $newname
306 done
307 for f in __gnu_debug_*; do
308     newname=`echo $f | sed 's/^__gnu_debug_/__gnu_debug::/'`
309     mv $f $newname
310 done
311 for f in __gnu_parallel_*; do
312     newname=`echo $f | sed 's/^__gnu_parallel_/__gnu_parallel::/'`
313     mv $f $newname
314 done
315 for f in __atomic0_*; do
316     newname=`echo $f | sed 's/^__atomic0_/std::__atomic0::/'`
317     mv $f $newname
318 done
319 for f in __atomic2_*; do
320     newname=`echo $f | sed 's/^__atomic2_/std::__atomic2::/'`
321     mv $f $newname
322 done
323
324
325 # Generic removal bits, where there are things in the generated man
326 # pages that need to be killed.
327 for f in *_libstdc__-v3_*; do
328     rm $f 
329 done
330
331 for f in *_src_*; do
332     rm $f 
333 done
334
335
336 # Also, for some reason, typedefs don't get their own man pages.  Sigh.
337 for f in ios streambuf istream ostream iostream stringbuf \
338          istringstream ostringstream stringstream filebuf ifstream \
339          ofstream fstream string;
340 do
341     echo ".so man3/std::basic_${f}.3" > std::${f}.3
342     echo ".so man3/std::basic_${f}.3" > std::w${f}.3
343 done
344
345 echo ::
346 echo :: Man pages in ${outdir}/man
347 fi
348
349 # all done
350 echo ::
351
352 exit 0