doclib: class index as first entry of classes box
[senf.git] / doclib / doxygen.sh
index 2992bd2..7061ee4 100755 (executable)
@@ -1,11 +1,68 @@
-#!/bin/sh -e
+#!/bin/bash -e
 
 do_html_cleanup()
 {
     sed -e 's/id="current"/class="current"/' \
        | tidy -ascii -q --wrap 0 --show-warnings no --fix-uri no \
        | sed -e 's/name="\([^"]*\)"\([^>]*\) id="\1"/name="\1"\2/g' \
-       | xsltproc --novalid --nonet --html --stringparam topdir $TOPDIR "$base/html-munge.xsl" -
+       | xsltproc --novalid --nonet --html --stringparam topdir "$reltopdir" \
+             "$base/html-munge.xsl" -
+}
+
+###########################################################################
+
+# Build absolute, normalized pathname
+abspath()
+{
+    case "$1" in
+       /*) echo "$1" ;;
+       *) echo "`pwd`/$1" ;;
+    esac | sed \
+       -e 's/\/\/*/\//g' \
+       -e:a \
+       -e 's/\/\.\(\/\|$\)/\1/g' \
+       -eta \
+       -e:b \
+       -e 's/\/[^\/]*\/..\(\/\|$\)/\1/' \
+       -etb \
+        -e 's/^\(\/..\)*\(\/\|$\)/\2/' \
+       -e 's/^$/\//'
+}
+
+# Create relative path from absolute directory $1 to absolute path $2
+relpath()
+{
+    local src="${1#/}"
+    local dst="${2#/}"
+    while true; do
+       if [ -z "$src" -a -z "$dst" ]; then
+           echo "Internal error in relpath()" 1>&2
+           exit 1
+       fi
+       srcd="${src%%/*}"
+       dstd="${dst%%/*}"
+       if [ "$srcd" = "$dstd" ]; then
+           src="${src#$srcd}"; src="${src#/}"
+           dst="${dst#$dstd}"; dst="${dst#/}"
+       else
+           break
+       fi
+    done
+    rel="`echo "$src" | sed -e "s/[^\/]*/../g"`/$dst" # `"
+    echo "${rel%/}"
+}
+
+# Log executed commands
+cmd()
+{
+    echo "+" "$@"
+    "$@"
+}
+
+html_cleanup()
+{
+    mv "$1" "${1}.orig"
+    do_html_cleanup <"${1}.orig" >"$1"
 }
 
 ###########################################################################
@@ -23,15 +80,15 @@ html="NO"; tagfile="NO"; tagfile_name=""; tagfiles=""; output_dir="doc"; html_di
 
 while true; do
     case "$1" in
-       --html) 
+       --html)
            html="YES" ; shift ;;
-       --tagfile) 
+       --tagfile)
            tagfile="YES" ; shift ;;
-       --tagfile-name) 
+       --tagfile-name)
            tagfile_name="$2"; shift 2 ;;
-       --tagfiles) 
+       --tagfiles)
            for f in $2; do
-               f="`readlink -mn "$f"`" #`"
+               f="`abspath "$f"`" #`"
                tagfiles="$tagfiles${tagfiles:+ }$f"
            done
            shift 2
@@ -62,7 +119,7 @@ EOF
     exit 1
 fi
 
-if [ "$tagfile" == "YES" -a -z "$tagfile_name" ]; then
+if [ "$tagfile" = "YES" -a -z "$tagfile_name" ]; then
     echo "--tagfile-name is required with --tagfile"
     exit 1
 fi
@@ -73,40 +130,7 @@ if [ -f "$doxydir" ]; then
     doxydir="`dirname "$doxydir"`" #`"
 fi
 
-doxydir="`readlink -mn "$doxydir"`" #`"
-
-###########################################################################
-
-# Create relative path from absolute directory $1 to absolute path $2
-relpath()
-{
-    local src="${1#/}"
-    local dst="${2#/}"
-    while true; do
-       srcd="${src%%/*}"
-       dstd="${dst%%/*}"
-       if [ "$srcd" = "$dstd" ]; then
-           src="${src#*/}"
-           dst="${dst#*/}"
-       else
-           break
-       fi
-    done
-    echo "`echo "$src" | sed -e "s/[^\/]*/../g"`/$dst" # `"
-}
-
-# Log executed commands
-cmd()
-{
-    echo "+" "$@"
-    "$@"
-}
-
-html_cleanup()
-{
-    mv "$1" "${1}.orig"
-    do_html_cleanup <"${1}.orig" >"$1"
-}
+doxydir="`abspath "$doxydir"`" #`"
 
 ###########################################################################
 
@@ -119,13 +143,14 @@ if [ ! -r "SConstruct" ]; then
     exit 1;
 fi
 TOPDIR="`pwd`";
+reltopdir="`relpath "$doxydir/$output_dir/$html_dir" "$TOPDIR"`" #`"
 cd "$doxydir"
 
 
 ## Remove tagfile_name from list of tagfiles
 
-if [ -n "$tagfile_name" ]; then 
-    tagfile_name="`readlink -mn "$output_dir/$tagfile_name"`" #`"
+if [ -n "$tagfile_name" ]; then
+    tagfile_name="`abspath "$output_dir/$tagfile_name"`" #`"
     x="$tagfiles"; tagfiles=""
     for f in $x; do
        if [ "$f" != "$tagfile_name" ]; then
@@ -137,7 +162,7 @@ fi
 ## Call doxygen proper
 
 generate_tagfile=""
-if [ "$tagfile" == "YES" ]; then
+if [ "$tagfile" = "YES" ]; then
     generate_tagfile="$tagfile_name"
 fi
 export TOPDIR html tagfile tagfile_name tagfiles output_dir html_dir generate_tagfile
@@ -147,7 +172,7 @@ cmd ${DOXYGEN:-doxygen}
 
 ## Clean up tagfile, if generated
 
-if [ "$tagfile" == "YES" ]; then
+if [ "$tagfile" = "YES" ]; then
     mv "$tagfile_name" "${tagfile_name}.orig"
     cmd xsltproc --novalid --nonet -o "$tagfile_name" "$tagxsl" "${tagfile_name}.orig"
 fi
@@ -173,7 +198,7 @@ fi
 
 ## Postprocess html files, if generated
 
-if [ "$html" == "YES" ]; then
+if [ "$html" = "YES" ]; then
     for h in "$doxydir/$output_dir/$html_dir"/*.html; do
        cmd html_cleanup "$h"
     done