run_doxygen 12 KB

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