Add .gitignore files
[senf.git] / doclib / doxygen.sh
1 #!/bin/sh -e
2
3 do_html_cleanup()
4 {
5     sed -e 's/id="current"/class="current"/' \
6         | tidy -ascii -q --wrap 0 --show-warnings no --fix-uri no \
7         | sed -e 's/name="\([^"]*\)"\([^>]*\) id="\1"/name="\1"\2/g' \
8         | xsltproc --novalid --nonet --html --stringparam topdir $TOPDIR "$base/html-munge.xsl" -
9 }
10
11 ###########################################################################
12
13 name="`basename "$0"`"; #`"
14 base="`dirname "$0"`"; base="`cd "$base"; pwd`" #`"
15
16 TEMP=`getopt -n $name -o '' -l html,tagfile,tagfile-name:,tagfiles:,output-dir:,html-dir:  -- "$@"`
17 if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
18 eval set -- "$TEMP"
19
20 tagxsl="$base/tag-munge.xsl"
21
22 html="NO"; tagfile="NO"; tagfile_name=""; tagfiles=""; output_dir="doc"; html_dir="html"
23
24 while true; do
25     case "$1" in
26         --html) 
27             html="YES" ; shift ;;
28         --tagfile) 
29             tagfile="YES" ; shift ;;
30         --tagfile-name) 
31             tagfile_name="$2"; shift 2 ;;
32         --tagfiles) 
33             for f in $2; do
34                 f="`readlink -mn "$f"`" #`"
35                 tagfiles="$tagfiles${tagfiles:+ }$f"
36             done
37             shift 2
38             ;;
39         --output-dir)
40             output_dir="$2"; shift 2 ;;
41         --html-dir)
42             html_dir="$2"; shift 2 ;;
43         --)
44             shift; break ;;
45         *)
46             echo "Internal error: $*"; exit 1 ;;
47     esac
48 done
49
50 if [ -z "$1" ]; then
51     cat <<EOF
52 Usage:
53     $name
54         [--html]
55         [--tagfile]
56         [--tagfile-name=<name>]
57         [--tagfiles=<files>]
58         [--output-dir=<dir>]
59         [--html-dir=<dir>]
60             <doxyfile-or-dir>
61 EOF
62     exit 1
63 fi
64
65 if [ "$tagfile" == "YES" -a -z "$tagfile_name" ]; then
66     echo "--tagfile-name is required with --tagfile"
67     exit 1
68 fi
69
70 doxydir="$1"
71
72 if [ -f "$doxydir" ]; then
73     doxydir="`dirname "$doxydir"`" #`"
74 fi
75
76 doxydir="`readlink -mn "$doxydir"`" #`"
77
78 ###########################################################################
79
80 # Create relative path from absolute directory $1 to absolute path $2
81 relpath()
82 {
83     local src="${1#/}"
84     local dst="${2#/}"
85     while true; do
86         srcd="${src%%/*}"
87         dstd="${dst%%/*}"
88         if [ "$srcd" = "$dstd" ]; then
89             src="${src#*/}"
90             dst="${dst#*/}"
91         else
92             break
93         fi
94     done
95     echo "`echo "$src" | sed -e "s/[^\/]*/../g"`/$dst" # `"
96 }
97
98 # Log executed commands
99 cmd()
100 {
101     echo "+" "$@"
102     "$@"
103 }
104
105 html_cleanup()
106 {
107     mv "$1" "${1}.orig"
108     do_html_cleanup <"${1}.orig" >"$1"
109 }
110
111 ###########################################################################
112
113 ## Find $TOPDIR
114
115 cd "$doxydir"
116 while [ ! -r "SConstruct" -a "`pwd`" != "/" ]; do cd ..; done
117 if [ ! -r "SConstruct" ]; then
118     echo "topdir not found"
119     exit 1;
120 fi
121 TOPDIR="`pwd`";
122 cd "$doxydir"
123
124
125 ## Remove tagfile_name from list of tagfiles
126
127 if [ -n "$tagfile_name" ]; then 
128     tagfile_name="`readlink -mn "$output_dir/$tagfile_name"`" #`"
129     x="$tagfiles"; tagfiles=""
130     for f in $x; do
131         if [ "$f" != "$tagfile_name" ]; then
132             tagfiles="$tagfiles${tagfiles:+ }$f"
133         fi
134     done
135 fi
136
137 ## Call doxygen proper
138
139 generate_tagfile=""
140 if [ "$tagfile" == "YES" ]; then
141     generate_tagfile="$tagfile_name"
142 fi
143 export TOPDIR html tagfile tagfile_name tagfiles output_dir html_dir generate_tagfile
144
145 cmd ${DOXYGEN:-doxygen}
146
147
148 ## Clean up tagfile, if generated
149
150 if [ "$tagfile" == "YES" ]; then
151     mv "$tagfile_name" "${tagfile_name}.orig"
152     cmd xsltproc --novalid --nonet -o "$tagfile_name" "$tagxsl" "${tagfile_name}.orig"
153 fi
154
155
156 ## Call installdox
157
158 if [ -n "$tagfiles" ]; then
159     args=""
160     for f in $tagfiles; do
161         n="`basename "$f"`" #`"
162         d="`dirname "$f"`" #`"
163         url="`relpath "$doxydir/$output_dir/$html_dir" "$d/$html_dir"`" #`"
164         args="$args${args:+ }-l $n@$url"
165     done
166
167     (
168         cd "./$output_dir/$html_dir"
169         cmd "./installdox" $args
170     )
171 fi
172
173
174 ## Postprocess html files, if generated
175
176 if [ "$html" == "YES" ]; then
177     for h in "$doxydir/$output_dir/$html_dir"/*.html; do
178         cmd html_cleanup "$h"
179     done
180 fi