summaryrefslogtreecommitdiff
path: root/libstdc++-v3/scripts/run_doxygen
blob: e227ce17b95e859bfb3912ea1683b97ce1269b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#!/bin/bash

# Runs doxygen and massages the output files.
# Copyright (C) 2001, 2002, 2003, 2004, 2008, 2009, 2010, 2011
# Free Software Foundation, Inc.
#
# Synopsis:  run_doxygen --mode=[html|latex|man|xml] --host_alias=<alias> \
#                        v3srcdir \
#                        v3builddir \
#                        shortname
#
# Originally hacked together by Phil Edwards <pme@gcc.gnu.org>


# We can check now that the version of doxygen is >= this variable.
DOXYVER=1.7.0

find_doxygen() {
    local -r v_required=`echo $DOXYVER |  \
		awk -F. '{if(NF<3)$3=0;print ($1*100+$2)*100+$3}'`
    local testing_version doxygen maybedoxy v_found
    # thank you goat book
    set `IFS=:; X="$PATH:/usr/local/bin:/bin:/usr/bin"; echo $X`
    for dir
    do
      # AC_EXEEXT could come in useful here
      maybedoxy="$dir/doxygen"
      test -f "$maybedoxy" && testing_version=`$maybedoxy --version`
      if test -n "$testing_version"; then
       v_found=`echo $testing_version |  \
		awk -F. '{if(NF<3)$3=0;print ($1*100+$2)*100+$3}'`
       if test $v_found -ge $v_required; then
	 doxygen="$maybedoxy"
	 break
       fi
      fi
    done
    if test -z "$doxygen"; then
	echo run_doxygen error:  Could not find Doxygen $DOXYVER in path. 1>&2
	print_usage
    fi
    # We need to use other tools from the same package/version.
    echo :: Using Doxygen tools from ${dir}.
    PATH=$dir:$PATH
    hash -r
}

print_usage() {
    cat 1>&2 <<EOF
Usage:  run_doxygen --mode=MODE --host_alias=BUILD_ALIAS [<options>]
		    <v3-src-dir> <v3-build-dir> <shortnamesp>
      MODE is one of:
	  html           Generate user-level HTML library documentation.
	  man            Generate user-level man pages.
	  xml            Generate user-level XML pages.
	  latex          Generate user-level LaTeX pages.

      BUILD_ALIAS is the GCC build alias set at configure time.

Note:  Requires Doxygen ${DOXYVER} or later; get it at
       ftp://ftp.stack.nl/pub/users/dimitri/doxygen-${DOXYVER}.src.tar.gz

EOF
    exit 1
}

parse_options() {
  for o
  do
    # Blatantly ripped from autoconf, er, I mean, "gratefully standing
    # on the shoulders of those giants who have gone before us."
    case "$o" in
      -*=*) arg=`echo "$o" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
      *) arg= ;;
    esac

    case "$o" in
      --mode=*)
	mode=$arg ;;
      --host_alias=*)
	host_alias=$arg ;;
      --mode | --host_alias | --help | -h)
	print_usage ;;
      *)
	# this turned out to be a mess, maybe change to --srcdir=, etc
	if test $srcdir = unset; then
	  srcdir=$o
	elif test $outdir = unset; then
	  builddir=${o}
	  outdir=${o}/doc/doxygen
	elif test $shortname = unset; then
	  shortname=$o
	else
	  echo run_doxygen error:  Too many arguments 1>&2
	  exit 1
	fi
	;;
      esac
  done
}


# script begins here
mode=unset
host_alias=unset
srcdir=unset
outdir=unset
shortname=unset
do_html=false
do_man=false
do_xml=false
do_latex=false
enabled_sections=
generate_tagfile=
DATEtext=`date '+%Y-%m-%d'`

# Show how this script is called.
echo run_doxygen $*

parse_options $*
find_doxygen

if test $srcdir = unset || test $outdir = unset || test $mode = unset || test $shortname = unset || test $host_alias = unset; then
    # this could be better
    echo run_doxygen error:  You have not given enough information...! 1>&2
    print_usage
fi

case x"$mode" in
    xhtml)
      do_html=true
      enabled_sections=maint
      generate_tagfile="$outdir/html/libstdc++.tag"
      ;;
    xlatex)
      do_latex=true
      enabled_sections=maint
      ;;
    xman)
      do_man=true
      ;;
    xxml)
      do_xml=true
      enabled_sections=maint
      ;;
    *)
      echo run_doxygen error:  $mode is an invalid mode 1>&2
      exit 1 ;;
esac

case x"$shortname" in
    xYES)
      ;;
    xNO)
      ;;
    *)
      echo run_doxygen error:  $shortname is invalid 1>&2
      exit 1 ;;
esac


mkdir -p $outdir
chmod u+w $outdir

# Run it
(
    set -e
    cd $builddir
    sed -e "s=@outdir@=${outdir}=g" \
	-e "s=@srcdir@=${srcdir}=g" \
	-e "s=@shortname@=${shortname}=g" \
	-e "s=@builddir@=${builddir}=g" \
	-e "s=@host_alias@=${host_alias}=g" \
	-e "s=@enabled_sections@=${enabled_sections}=" \
	-e "s=@do_html@=${do_html}=" \
	-e "s=@do_latex@=${do_latex}=" \
	-e "s=@do_man@=${do_man}=" \
	-e "s=@do_xml@=${do_xml}=" \
	-e "s=@generate_tagfile@=${generate_tagfile}=" \
	${srcdir}/doc/doxygen/user.cfg.in > ${outdir}/${mode}.cfg
    echo :: NOTE that this may take some time...
    echo doxygen ${outdir}/${mode}.cfg
    doxygen ${outdir}/${mode}.cfg
)
ret=$?
test $ret -ne 0 && exit $ret

if $do_xml; then
    echo ::
    echo :: XML pages begin with
    echo :: ${outdir}/xml/index.xml
fi

if $do_latex; then
    cd ${outdir}/${mode}

    # Also drop in the header file and style sheet
    doxygen -w latex header.tex doxygen.sty
    
    echo ::
    echo :: LaTeX pages begin with
    echo :: ${outdir}/latex/refman.tex
fi
    
if $do_html; then
  cd ${outdir}/${mode}

  #doxytag -t libstdc++.tag . > /dev/null 2>&1
  sed -e '/<path>/d' libstdc++.tag > TEMP
  mv TEMP libstdc++.tag

  sed -e "s=@DATE@=${DATEtext}=" \
      ${srcdir}/doc/doxygen/mainpage.html > index.html

  # The following bit of line noise changes annoying
  #   std::foo < typename _Ugly1, typename _Ugly2, .... _DefaultUgly17 >
  # to user-friendly
  #   std::foo
  # in the major "Compound List" page.
  sed -e 's=\(::[[:alnum:]_]*\)&lt; .* &gt;=\1=' annotated.html > annstrip.html
  mv annstrip.html annotated.html

  cp ${srcdir}/doc/doxygen/tables.html tables.html

  echo ::
  echo :: HTML pages begin with
  echo :: ${outdir}/html/index.html
fi

# Mess with the man pages.  We don't need documentation of the internal
# headers, since the man pages for those contain nothing useful anyhow.  The
# man pages for doxygen modules need to be renamed (or deleted).  And the
# generated #include lines need to be changed from the internal names to the
# standard ones (e.g., "#include <stl_tempbuf.h>" -> "#include <memory>").
if $do_man; then
echo ::
echo :: Fixing up the man pages...
cd $outdir/man/man3

# File names with embedded spaces (EVIL!) need to be....?  renamed or removed?
find . -name "* *" -print0 | xargs -0r rm        # requires GNU tools

# man pages are for functions/types/other entities, not source files
# directly.  who the heck would type "man foo.h" anyhow?
find . -name "[a-z]*" -a ! -name "std_*" -print | xargs rm
rm -f *.h.3 *.hpp.3 *config* *.cc.3 *.tcc.3 *_t.3
#rm ext_*.3 tr1_*.3 debug_*.3

# this is used to examine what we would have deleted, for debugging
#mkdir trash
#find . -name "[a-z]*" -a ! -name "std_*" -print | xargs -i mv {} trash
#mv *.h.3 *config* *.cc.3 *.tcc.3 *_t.3  trash

# Standardize the displayed header names.  If anyone who knows perl cares
# enough to rewrite all this, feel free.  This only gets run once a century,
# and I'm off getting coffee then anyhow, so I didn't care enough to make
# this super-fast.
g++ ${srcdir}/doc/doxygen/stdheader.cc -o ./stdheader
problematic=`egrep -l '#include <.*_.*>' [a-z]*.3`
for f in $problematic; do
    # this is also slow, but safe and easy to debug
    oldh=`sed -n '/fC#include </s/.*<\(.*\)>.*/\1/p' $f`
    newh=`echo $oldh | ./stdheader`
    sed "s=${oldh}=${newh}=" $f > TEMP
    mv TEMP $f
done
rm stdheader

# Some of the pages for generated modules have text that confuses certain
# implementations of man(1), e.g., Linux's.  We need to have another top-level
# *roff tag to /stop/ the .SH NAME entry.
problematic=`egrep --files-without-match '^\.SH SYNOPSIS' [A-Z]*.3`
#problematic='Containers.3 Sequences.3 Assoc_containers.3 Iterator_types.3'

for f in $problematic; do
    sed '/^\.SH NAME/{
n
a\
\
.SH SYNOPSIS
    }' $f > TEMP
    mv TEMP $f
done

# Also, break this (generated) line up.  It's ugly as sin.
problematic=`grep -l '[^^]Definition at line' *.3`
for f in $problematic; do
    sed 's/Definition at line/\
.PP\
&/'  $f > TEMP
    mv TEMP $f
done

cp ${srcdir}/doc/doxygen/Intro.3 C++Intro.3

# Why didn't I do this at the start?  Were rabid weasels eating my brain?
# Who the fsck would "man std_vector" when the class isn't named that?

# First, deal with nested namespaces.
for f in *chrono_*; do
    newname=`echo $f | sed 's/chrono_/chrono::/'`
    mv $f $newname
done
for f in *__debug_*; do
    newname=`echo $f | sed 's/__debug_/__debug::/'`
    mv $f $newname
done
for f in *decimal_*; do
    newname=`echo $f | sed 's/decimal_/decimal::/'`
    mv $f $newname
done
for f in *__detail_*; do
    newname=`echo $f | sed 's/__detail_/__detail::/'`
    mv $f $newname
done
for f in *__parallel_*; do
    newname=`echo $f | sed 's/__parallel_/__parallel::/'`
    mv $f $newname
done
for f in *__profile_*; do
    newname=`echo $f | sed 's/__profile_/__profile::/'`
    mv $f $newname
done
for f in *__atomic0_*; do
    newname=`echo $f | sed 's/__atomic0_/__atomic0::/'`
    mv $f $newname
done
for f in *__atomic2_*; do
    newname=`echo $f | sed 's/__atomic2_/__atomic2::/'`
    mv $f $newname
done

# Then, clean up other top-level namespaces.
for f in std_tr1_*; do
    newname=`echo $f | sed 's/^std_tr1_/std::tr1::/'`
    mv $f $newname
done
for f in std_*; do
    newname=`echo $f | sed 's/^std_/std::/'`
    mv $f $newname
done
for f in __gnu_cxx_*; do
    newname=`echo $f | sed 's/^__gnu_cxx_/__gnu_cxx::/'`
    mv $f $newname
done
for f in __gnu_debug_*; do
    newname=`echo $f | sed 's/^__gnu_debug_/__gnu_debug::/'`
    mv $f $newname
done
for f in __gnu_parallel_*; do
    newname=`echo $f | sed 's/^__gnu_parallel_/__gnu_parallel::/'`
    mv $f $newname
done
for f in __gnu_profile_*; do
    newname=`echo $f | sed 's/^__gnu_profile_/__gnu_profile::/'`
    mv $f $newname
done
for f in __gnu_pbds_*; do
    newname=`echo $f | sed 's/^__gnu_pbds_/__gnu_pbds::/'`
    mv $f $newname
done
for f in __cxxabiv1_*; do
    newname=`echo $f | sed 's/^__cxxabiv1_/abi::/'`
    mv $f $newname
done

# Then piecemeal nested classes
for f in *__future_base_*; do
    newname=`echo $f | sed 's/__future_base_/__future_base::/'`
    mv $f $newname
done



# Generic removal bits, where there are things in the generated man
# pages that need to be killed.
for f in *_libstdc__-v3_*; do
    rm $f
done

for f in *_src_*; do
    rm $f
done


# Also, for some reason, typedefs don't get their own man pages.  Sigh.
for f in ios streambuf istream ostream iostream stringbuf \
	 istringstream ostringstream stringstream filebuf ifstream \
	 ofstream fstream string;
do
    echo ".so man3/std::basic_${f}.3" > std::${f}.3
    echo ".so man3/std::basic_${f}.3" > std::w${f}.3
done

echo ::
echo :: Man pages in ${outdir}/man
fi

# all done
echo ::

exit 0