]> icculus.org git repositories - divverent/netradiant.git/blob - Doxygen_files/gendoxfunctions
option -randomsamples: makes -samples use adaptive random subsampling (only subsample...
[divverent/netradiant.git] / Doxygen_files / gendoxfunctions
1 #!/bin/bash
2 # Functions for the gendox script
3
4 # Gef, Aug 2001
5
6 #------------------------------------------------------------------------
7 # Set the doxygen output language from the system locale
8 #------------------------------------------------------------------------
9 get_language() {
10         if [ -n "$LANG" ] ; then
11                 local LANG=`locale | grep LANG | cut -d= -f2`;
12         fi
13         case "$LANG" in
14                 czech)
15                         OUPUTLANGUAGE="Czech";
16                         ;;
17                 german)
18                         OUPUTLANGUAGE="German";
19                         ;;
20                 spanish)
21                         OUPUTLANGUAGE="Spanish";
22                         ;;
23                 finnish)
24                         OUPUTLANGUAGE="Finnish";
25                         ;;
26                 french)
27                         OUPUTLANGUAGE="French";
28                         ;;
29                 italian)
30                         OUPUTLANGUAGE="Italian";
31                         ;;
32                 japanese*)
33                         OUPUTLANGUAGE="Japanese";
34                         ;;
35                 dutch)
36                         OUPUTLANGUAGE="Dutch";
37                         ;;
38                 swedish)
39                         OUPUTLANGUAGE="Swedish";
40                         ;;
41                 *)
42                         OUPUTLANGUAGE="English";
43                         ;;
44         esac
45 }
46
47 #------------------------------------------------------------------------
48 # Output usage info & output help
49 #------------------------------------------------------------------------
50 output_usage() {
51         echo -e "Usage: $0 [<target(s)>] [-o <output_directory>]";
52         return;
53 }
54
55 output_help() {
56         output_usage;
57         echo -e "\nOptions:";
58         echo -e "  [<target(s)>]";
59         echo -e "    This is an optional parameter that specifies the directory, or multiple";
60         echo -e "    directories from which to generate the documentation.";
61         echo -e "";
62         echo -e "  [-o <output_directory>]";
63         echo -e "    An optional parameter that specifies the output directory in which";
64         echo -e "    to save the generated documentation.";
65         echo -e "";
66   echo -e "  -q or --quiet";
67   echo -e "    Prevents the output of status information"
68         echo -e ""
69         echo -e "  --help, or -h";
70         echo -e "    Displays this information";
71   echo -e ""
72   echo -e "  -q or --quiet";
73   echo -e "    Prevents the output of status information"
74   echo -e ""
75   echo -e "  -k or --kill";
76   echo -e "    kills running doxygen pids."
77         echo -e ""
78         echo -e "* Further information on using this script, can be found in README.doxygen";
79         echo -e "* in the current directory.";
80         
81 }
82
83 #------------------------------------------------------------------------
84 # Set the target to what was passed on the command line
85 #------------------------------------------------------------------------
86 parse_commandline() {
87         # todo:
88         # need to add the ability to check for an auto gen'd version
89         # used for automatically generating new documentation for each commit
90         # to the cvs server
91
92         # funky bash shell array
93         declare -a OPTLIST[$#];
94
95         if [ $OPTCOUNT == 0 ] ; then
96     # No options on the command line so set the target list to the core
97     TARGETCOUNT=0;
98     OUTPUTDIR="../$(basename `pwd`)-doxygen";
99         else
100     # put all the command line options into an array
101     for f in $COMLINE ; do
102       OPTLIST[$COUNTER]="$f";
103       let COUNTER++;
104     done
105   
106     for (( COUNTER=0 ; $COUNTER < $OPTCOUNT; $[COUNTER++] )) ; do
107       if [ "${OPTLIST[$COUNTER]}" == "--help" ] ; then
108         # output usage information
109         output_help;
110         RETVAL=1;
111         return;
112       elif [ "${OPTLIST[$COUNTER]}" == "-h" ] ; then
113         # output usage information
114         output_help;
115         RETVAL=1;
116         return;
117       fi
118   
119       case ${OPTLIST[$COUNTER]} in
120         -q)
121           QUIETMODE=1;
122           ;;
123         --quiet)
124           QUIETMODE=1;
125           ;;
126         -k)
127           KILLON=1;
128           ;;
129         --kill)
130           KILLON=1;
131           ;;
132         -o)
133           # look for the -o switch, and get the next command line option as the output dir
134           if [ -z ${OPTLIST[$COUNTER + 1]} ] ; then
135             [ $QUIETMODE -gt 0 ] || echo -e " ** Output switch used, but no output dir passed...";
136             [ $QUIETMODE -gt 0 ] || echo -e " ** Setting default output dir.";
137           else
138             let COUNTER++;
139             OUTPUTDIR=${OPTLIST[$COUNTER]};
140           fi
141           break;
142           ;;
143         **)
144           # If the command line option is anything other that -o then assume it's a target 
145           # Check to make sure the target exists first...
146           if [ -d ${OPTLIST[$COUNTER]} ] ; then
147             TARGETLIST[$COUNTER]=${OPTLIST[$COUNTER]};
148           else
149             output_usage;
150             echo -e " ** Error: Non-existent directory specified as a target.\nExiting.";
151             RETVAL=1;
152             return;
153           fi
154           let TARGETCOUNT++;
155           ;;
156       esac
157     done
158
159   fi # if [ $OPTCOUNT == 0 ] ;
160
161   if [ $TARGETCOUNT == 0 ] ; then
162     TARGETCOUNT=4;
163     TARGETLIST[0]="include";
164     TARGETLIST[1]="libs";
165     TARGETLIST[2]="radiant";
166     TARGETLIST[3]="plugins";
167     # Gef: outputdir for default core when no targets are passed on the command line
168     # TTimo problem still there, if -o used on command line, don't override
169     if [ -z $OUTPUTDIR ] ; then
170       OUTPUTDIR="../$(basename `pwd`)-doxygen";
171     fi
172   fi
173
174   # Add trailing slash's to the lines that need them
175         TARGETSTRING=`echo ${TARGETLIST[*]} | sed -e 's/" "/", "/'`
176   [ $QUIETMODE -gt 0 ] || echo -ne " -> Set Input to: ";
177   for (( COUNTER=0; COUNTER < $TARGETCOUNT ; $[COUNTER++] )) ; do
178     if [ $COUNTER == $[TARGETCOUNT - 1] ] ; then
179       [ $QUIETMODE -gt 0 ] || echo -ne "${TARGETLIST[$COUNTER]}\n";
180       TARGETLIST[$COUNTER]="${TARGETLIST[$COUNTER]}";
181     else
182       [ $QUIETMODE -gt 0 ] || echo -ne "${TARGETLIST[$COUNTER]}, ";
183       TARGETLIST[$COUNTER]="${TARGETLIST[$COUNTER]} \\";
184     fi
185   done
186   [ $QUIETMODE -gt 0 ] || echo -e " -> Set Output Dir to: $OUTPUTDIR";
187         return;
188 }
189
190 #------------------------------------------------------------------------
191 # Try to extract the version number
192 # todo: find a better way to determine the version
193 #------------------------------------------------------------------------
194 get_version() {
195         VERSION=`grep PROJECT_NUMBER $DOXYCONFIG | grep -v \# | cut -d= -f2`;
196         if [ -z $VERSION ] ; then
197                 if [ -f "./include/version.default" ] ; then    # checks that we are in the right dir
198                         VERSION=`cat ./include/version.default`;
199                 else
200                         VERSION="(Unknown)";
201                 fi
202         fi
203         return;
204 }
205
206 #------------------------------------------------------------------------
207 # Create a projectname from the tree name
208 #------------------------------------------------------------------------
209 get_projectname() {
210         PROJECTNAME=`grep PROJECT_NAME $DOXYCONFIG | grep -v \# | cut -d= -f2`;
211         if [ -z $PROJECTNAME ] ; then
212                 # PROJECTNAME=`echo $TARGET | sed -e s/[^A-Za-z0-9]/!/ | cut -d! -f1`;
213                 PROJECTNAME="$(basename `pwd`)";
214         fi
215         return;
216 }
217
218 #------------------------------------------------------------------------
219 # function to determine the path to the perl executable
220 #------------------------------------------------------------------------
221 get_perlpath() {
222         if [ -f "$DOXYCONFIG" ] ; then
223                 PERLPATH=`grep PERL_PATH $DOXYCONFIG | grep = | cut -d= -f2`
224         fi
225
226         if [ 'basename $PERLPATH &2>/dev/null' != "perl" ] ; then
227                 PERLPATH=`which perl 2>/dev/null | sed -e 's/perl//'`;
228         elif [ 'basename $PERLPATH &2>/dev/null' != "perl" ] ; then
229                 PERLPATH="";
230         fi
231         return;
232 }
233
234 #------------------------------------------------------------------------
235 # Function to determine the path to the dot executable
236 #------------------------------------------------------------------------
237 get_dotpath() {
238         if [ -f "$DOXYCONFIG" ] ; then
239                 DOTPATH=`grep DOT_PATH $DOXYCONFIG | grep = | cut -d= -f2`
240         fi
241
242   if [ -z $DOTPATH ] || [ `basename $DOTPATH 2>/dev/null` != "dot" ] ; then
243           DOTPATH=`which dot 2>/dev/null`;
244   fi
245
246         if [ -z $DOTPATH ] || [ `basename $DOTPATH 2>/dev/null` != "dot" ] ; then
247                 DOTPATH="";
248                 HAVEDOT="No";
249                 echo -e "** Warning: dot not found.";
250                 [ $QUIETMODE -gt 0 ] || echo -e "**          dot is part of the GraphVis package and is used to generate";
251                 [ $QUIETMODE -gt 0 ] || echo -e "**          dependancy/inheritance/include (etc) diagrams.";
252                 [ $QUIETMODE -gt 0 ] || echo -e "**          It's suggested that you install the GraphVis package for those";
253                 [ $QUIETMODE -gt 0 ] || echo -e "**          features.";
254                 [ $QUIETMODE -gt 0 ] || echo -e "**          GraphVis can be downloaded from www.graphvis.org";
255         else
256                 HAVEDOT="Yes";
257                 DOTPATH=`echo $DOTPATH | sed -e 's/dot//'`;
258         fi
259         
260         return;
261 }
262
263 #------------------------------------------------------------------------
264 # Function to move stuff around
265 #------------------------------------------------------------------------
266 # eg: move the images into the output directory & the reference doc into the
267 # html directory.
268 # called after doxygen has finished generating documentation
269 move_stuff() {
270         [ $QUIETMODE -gt 0 ] || echo -ne " -> Move stuff.\n";
271         if [ ! -d $OUTPUTDIR ] ; then
272                 mkdir $OUTPUTDIR;
273         fi
274         
275         if [ ! -d "$EXTRAS_PATH/images/" ] ; then
276                 [ $QUIETMODE -gt 0 ] || echo -e " - Looking for images.";
277                 [ $QUIETMODE -gt 0 ] || sleep 2;
278                 [ $QUIETMODE -gt 0 ] || echo -e " - I can't find the images...";
279                 [ $QUIETMODE -gt 0 ] || sleep 1;
280                 [ $QUIETMODE -gt 0 ] || echo -e " - Where did you put the images!?";
281                 [ $QUIETMODE -gt 0 ] || sleep 2;
282                 [ $QUIETMODE -gt 0 ] || echo -e " - They have to be here somewhere...";
283                 [ $QUIETMODE -gt 0 ] || sleep 1;
284                 [ $QUIETMODE -gt 0 ] || echo -e " - Looking in /dev/null";
285                 [ $QUIETMODE -gt 0 ] || sleep 3;
286                 [ $QUIETMODE -gt 0 ] || echo -e " - YOU FOOL, YOU DELETED THE IMAGES!!!";
287                 [ $QUIETMODE -gt 0 ] || sleep 1;
288                 [ $QUIETMODE -gt 0 ] || echo -e " - I quit!";
289                 RETVAL=666;
290         else
291                 if [ ! -d $OUTPUTDIR/images ] ; then
292                         mkdir $OUTPUTDIR/images ;
293                 fi
294                 cp $EXTRAS_PATH/images/* $OUTPUTDIR/images/ ;
295                 RETVAL=0;
296         fi
297         return;
298 }
299
300 #------------------------------------------------------------------------
301 # clean_up() removes old versions of the documentation
302 #------------------------------------------------------------------------
303 clean_up() {
304         if [ -f $OUTPUTDIR/html/index.html ] ; then
305                 [ $QUIETMODE -gt 0 ] || echo -e " -> Trashing old dox.";
306                 rm -f $OUTPUTDIR/html/*
307         fi
308         return;
309 }
310
311 #------------------------------------------------------------------------
312 # Create a new genConf & Doxyfile
313 #------------------------------------------------------------------------
314 gen_doxyconfig() {
315         [ $QUIETMODE -gt 0 ] || echo -e " -> Generating DoxyConfig.";
316         RETVAL=0;
317         # first need to make sure there is a Doxyfile here
318         if [ ! -f $DOXYFILE ] ; then
319                 # what now? (could generate one with 'doxygen -e Doxyfile') but it would be screwed.
320                 echo -e "No Doxyfile here...";
321                 RETVAL=3;
322                 return;
323         else
324                 # Create a new doxyfile with the @INCLUDE statement including the generated stuff
325                 echo "`cat $DOXYFILE | grep -v @INCLUDE`" > $NEWDOXYFILE
326                 echo "@INCLUDE = $CONFIG_OUTPUT" >> $NEWDOXYFILE
327         fi
328         
329         # remove the old config file
330         rm -f $CONFIG_OUTPUT
331         
332         # create a new one
333         touch $CONFIG_OUTPUT
334         echo "# Generated configuration - Do Not Edit." >> $CONFIG_OUTPUT;
335         echo "# If you want to modify options, edit DoxyConfig and re-run genconf." >> $CONFIG_OUTPUT;
336         echo -e "\n" >> $CONFIG_OUTPUT;
337         echo -e "PROJECT_NAME=$PROJECTNAME" >> $CONFIG_OUTPUT;
338         echo -e "PROJECT_NUMBER=$VERSION" >> $CONFIG_OUTPUT;
339         echo -e "PERL_PATH=$PERLPATH" >> $CONFIG_OUTPUT;
340         echo -e "HAVE_DOT=$HAVEDOT" >> $CONFIG_OUTPUT;
341         echo -e "DOT_PATH=$DOTPATH" >> $CONFIG_OUTPUT;
342         echo -e "OUTPUT_LANGUAGE=$OUTPUTLANGUAGE" >> $CONFIG_OUTPUT;
343
344         echo -n "INPUT=" >> $CONFIG_OUTPUT;
345         for (( COUNTER=0 ; COUNTER < $TARGETCOUNT; $[COUNTER++] )) ; do
346                 # echo -e "${TARGETLIST[$COUNTER]}";
347                 echo -e "${TARGETLIST[$COUNTER]}" >> $CONFIG_OUTPUT
348         done
349         # echo -e "INPUT=$TARGET" >> $CONFIG_OUTPUT;
350
351         echo -e "OUTPUT_DIRECTORY=$OUTPUTDIR" >> $CONFIG_OUTPUT;
352         echo -e "\n" >> $CONFIG_OUTPUT;
353         return; 
354 }
355
356 #------------------------------------------------------------------------
357 # Build the reference page & index
358 #------------------------------------------------------------------------
359 build_extra_html() {
360         # file locations
361         REF_OUT="$OUTPUTDIR/reference/index.html"
362         INDEX_OUT="$OUTPUTDIR/index.html"
363         
364         # Make the output directory if it doesn't exist
365         if [ ! -d $OUTPUTDIR/reference/ ] ; then
366                 [ $QUIETMODE -gt 0 ] || echo -e " -> Making reference directory";
367                 mkdir $OUTPUTDIR/reference
368         fi
369         
370         # cat the files together and output the result to each file
371         [ $QUIETMODE -gt 0 ] || echo -e " -> Building reference document";
372         cat $EXTRAS_PATH/doxygen_reference_head.html $EXTRAS_PATH/reference1.html $EXTRAS_PATH/doxygen_reference_foot.html > $REF_OUT;
373
374         if [ ! -d $OUTPUTDIR/example/ ] ; then
375                 [ $QUIETMODE -gt 0 ] || echo -e " -> Making example dir";
376                 mkdir $OUTPUTDIR/example
377         fi
378         [ $QUIETMODE -gt 0 ] || echo -e " -> Moving example docs";
379         cp $EXTRAS_PATH/example/* $OUTPUTDIR/example/
380   cp $EXTRAS_PATH/doxygen_gtkradiant.css $OUTPUTDIR/example/
381
382         # Make a redirecting index.html
383         cat $EXTRAS_PATH/doxygen_index.html > $INDEX_OUT;
384         return;
385 }
386
387 #------------------------------------------------------------------------
388 # Execute doxygen
389 #------------------------------------------------------------------------
390 run_doxygen() {
391         # copy doxy_mainpage.h to the target directory
392         # pipe it through sed to add generation time/date and username - $machine
393         TEMPLOCATION=`echo $TARGETSTRING | cut -d' ' -f1`;
394   if [ X"$USERNAME" == "X" ] ; then
395           USERNAME=`whoami`;
396   fi
397         MACHINE=`uname -n`; # `uname -n` or `hostname` ??
398         cp $EXTRAS_PATH/doxy_mainpage.h temp.h
399         cat temp.h |
400     sed "s/+project+/$PROJECTNAME/" |
401                 sed "s|+target+|$TARGETSTRING|" |
402                 sed "s/+user+/$USERNAME/" |
403                 sed "s/+machine+/$MACHINE/" |
404     sed "s/+date+/$(date '+%b %d %Y')/" > $TEMPLOCATION/doxy_mainpage.h ;
405
406   rm -f temp.h
407
408         # Start doxygen with the command "doxygen $DOXYFILE"
409         [ $QUIETMODE -gt 0 ] || echo -e " -> Executing doxygen.";
410         [ $QUIETMODE -gt 0 ] || echo -e "> doxygen $NEWDOXYFILE";
411         doxygen $NEWDOXYFILE
412         RETVAL=$?
413
414         # remove doxy_mainpage.h from the target directory
415         rm -f $TEMPLOCATION/doxy_mainpage.h
416         return;
417 }
418
419 #------------------------------------------------------------------------
420 # End.
421