run_doxygen 9.34 KB
Newer Older
1
#!/bin/bash
2

Phil Edwards committed
3
# Runs doxygen and massages the output files.
4
# Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
5
#
6
# Synopsis:  run_doxygen --mode=[user|maint|man] --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.3.9
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 20 21 22 23 24 25
    # 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`
26 27 28 29 30 31 32
      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
33 34 35 36 37 38
      fi
    done
    if test -z "$doxygen"; then
        echo run_doxygen error:  Could not find Doxygen $DOXYVER in path. 1>&2
        print_usage
    fi
39 40 41 42
    # We need to use other tools from the same package/version.
    echo :: Using Doxygen tools from ${dir}.
    PATH=$dir:$PATH
    hash -r
43
}
44 45 46

print_usage() {
    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 51
          user           Generate user-level HTML library documentation.
          maint          Generate maintainers' HTML documentation (lots more;
52
                             exposes non-public members, etc).
53
          man            Generate user-level man pages.
54

55 56
      BUILD_ALIAS is the GCC build alias set at configure time.

57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
      more options when i think of them

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 ;;
79 80 81
      --host_alias=*)
        host_alias=$arg ;;
      --mode | --host_alias | --help | -h)
82 83 84 85 86 87
        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
88
          builddir=${o}
89 90 91 92 93 94 95 96 97 98 99 100 101
          outdir=${o}/docs/doxygen
        else
          echo run_doxygen error:  Too many arguments 1>&2
          exit 1
        fi
        ;;
      esac
  done
}


# script begins here
mode=unset
102
host_alias=unset
103 104
srcdir=unset
outdir=unset
Phil Edwards committed
105 106
do_html=false
do_man=false
107
enabled_sections=
108
generate_tagfile=
109
DATEtext=`date '+%Y-%m-%d'`
110

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

114
parse_options $*
115
find_doxygen
116

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

case x"$mode" in
124 125 126 127 128 129 130 131 132 133 134 135 136 137
    xuser)
      do_html=true
      LEVELtext='User'
      generate_tagfile="$outdir/html_$mode/libstdc++.tag"
      ;;
    xmaint)
      do_html=true
      enabled_sections=maint
      LEVELtext='Maintainer'
      generate_tagfile="$outdir/html_$mode/libstdc++.tag"
      ;;
    xman)
      do_man=true
      ;;
138 139 140 141 142
    *)
      echo run_doxygen error:  $mode is an invalid mode 1>&2
      exit 1 ;;
esac

143
#rm -rf $outdir
144 145
mkdir -p $outdir
chmod u+w $outdir
146 147

# work around a stupid doxygen bug
Phil Edwards committed
148
if $do_man; then
149 150
    mkdir -p $outdir/man/man3/ext
    chmod -R u+w $outdir/man/man3/ext
Phil Edwards committed
151
fi
152

153 154
(
  set -e
155
  cd $builddir
Phil Edwards committed
156 157
  sed -e "s=@outdir@=${outdir}=g" \
      -e "s=@srcdir@=${srcdir}=g" \
158
      -e "s=@host_alias@=${host_alias}=g" \
159 160 161 162
      -e "s=@html_output_dir@=html_${mode}=" \
      -e "s=@enabled_sections@=${enabled_sections}=" \
      -e "s=@do_html@=${do_html}=" \
      -e "s=@do_man@=${do_man}=" \
163
      -e "s=@generate_tagfile@=${generate_tagfile}=" \
164
      ${srcdir}/docs/doxygen/user.cfg.in > ${outdir}/${mode}.cfg
165
  echo :: NOTE that this may take some time...
166 167
  echo doxygen ${outdir}/${mode}.cfg
  doxygen ${outdir}/${mode}.cfg
168
  echo :: Finished, exit code was $?
169
)
170 171
ret=$?
test $ret -ne 0 && exit $ret
172

Phil Edwards committed
173
if $do_html; then
174
  cd ${outdir}/html_${mode}
175 176

  #doxytag -t libstdc++.tag . > /dev/null 2>&1
Phil Edwards committed
177 178
  sed -e '/<path>/d' libstdc++.tag > TEMP
  mv TEMP libstdc++.tag
179

180 181
  sed -e "s=@LEVEL@=${LEVELtext}=" \
      -e "s=@DATE@=${DATEtext}=" \
182 183
      ${srcdir}/docs/doxygen/mainpage.html > index.html

184 185 186 187 188
  # 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.
189 190
  sed -e 's=\(::[[:alnum:]_]*\)&lt; .* &gt;=\1=' annotated.html > annstrip.html
  mv annstrip.html annotated.html
191 192 193 194 195 196 197

  # Work around a bug in doxygen 1.3.
  for f in class*html struct*html; do
      sed '1,10s!^<title> Template!<title>Template !' $f > TEMP
      mv TEMP $f
  done

198 199 200 201
  cp ${srcdir}/docs/doxygen/tables.html tables.html
  echo ::
  echo :: HTML pages begin with
  echo :: ${outdir}/html_${mode}/index.html
Phil Edwards committed
202
fi
203

Phil Edwards committed
204 205 206 207 208
# 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>").
Phil Edwards committed
209
if $do_man; then
210
echo ::
Phil Edwards committed
211
echo :: Fixing up the man pages...
212 213 214 215
cd $outdir/man/man3

# here's the other end of the "stupid doxygen bug" mentioned above
rm -rf ext
Phil Edwards committed
216

217
# File names with embedded spaces (EVIL!) need to be....?  renamed or removed?
Phil Edwards committed
218
find . -name "* *" -print0 | xargs -0r rm        # requires GNU tools
Phil Edwards committed
219 220 221 222 223 224 225 226 227 228

# can leave SGIextensions.3 alone, it's an okay name
mv s20_3_1_base.3           Intro_functors.3
mv s20_3_2_arithmetic.3     Arithmetic_functors.3
mv s20_3_3_comparisons.3    Comparison_functors.3
mv s20_3_4_logical.3        Logical_functors.3
mv s20_3_5_negators.3       Negation_functors.3
mv s20_3_6_binder.3         Binder_functors.3
mv s20_3_7_adaptors.3       Func_ptr_functors.3
mv s20_3_8_memadaptors.3    Member_ptr_functors.3
229
mv iterator_tags.3          Iterator_types.3
230 231
mv std.3                    Namespace_std.3
mv __gnu_cxx.3              Namespace___gnu_cxx.3
232

233 234
# man pages are for functions/types/other entities, not source files
# directly.  who the heck would type "man foo.h" anyhow?
235
find . -name "[a-z]*" -a ! -name "std_*" -print | xargs rm
236
rm -f *.h.3 *config* *.cc.3 *.tcc.3 *_t.3
Phil Edwards committed
237 238
# this is used to examine what we would have deleted, for debugging
#mkdir trash
239 240
#find . -name "[a-z]*" -a ! -name "std_*" -print | xargs -i mv {} trash
#mv *.h.3 *config* *.cc.3 *.tcc.3 *_t.3  trash
Phil Edwards committed
241 242 243 244 245 246 247 248 249

# 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}/docs/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
250
    oldh=`sed -n '/fC#include </s/.*<\(.*\)>.*/\1/p' $f`
Phil Edwards committed
251 252 253 254 255 256
    newh=`echo $oldh | ./stdheader`
    sed "s=${oldh}=${newh}=" $f > TEMP
    mv TEMP $f
done
rm stdheader

257 258 259 260
# 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`
261
problematic='Containers.3 Sequences.3 Assoc_containers.3 Iterator_types.3'
262 263 264 265
for f in $problematic; do
    sed '/^\.SH NAME/{
n
a\
266
\
267 268 269 270 271
.SH SYNOPSIS
    }' $f > TEMP
    mv TEMP $f
done

272 273 274 275 276 277 278 279 280 281 282 283 284
# 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}/docs/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?
285 286 287 288
for f in std_tr1_*; do
    newname=`echo $f | sed 's/^std_tr1_/std::tr1::/'`
    mv $f $newname
done
289 290 291 292 293 294 295 296
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
297 298 299 300 301

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

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

308

309 310 311 312 313 314 315 316
# 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
317

318 319
echo ::
echo :: Man pages in ${outdir}/man
Phil Edwards committed
320
fi
Phil Edwards committed
321 322

# all done
323 324 325
echo ::

exit 0
326

327
# vim:ts=4:et: