2 # Functions for the gendox script
6 #------------------------------------------------------------------------
7 # Set the doxygen output language from the system locale
8 #------------------------------------------------------------------------
10 if [ -n "$LANG" ] ; then
11 local LANG=`locale | grep LANG | cut -d= -f2`;
15 OUPUTLANGUAGE="Czech";
18 OUPUTLANGUAGE="German";
21 OUPUTLANGUAGE="Spanish";
24 OUPUTLANGUAGE="Finnish";
27 OUPUTLANGUAGE="French";
30 OUPUTLANGUAGE="Italian";
33 OUPUTLANGUAGE="Japanese";
36 OUPUTLANGUAGE="Dutch";
39 OUPUTLANGUAGE="Swedish";
42 OUPUTLANGUAGE="English";
47 #------------------------------------------------------------------------
48 # Output usage info & output help
49 #------------------------------------------------------------------------
51 echo -e "Usage: $0 [<target(s)>] [-o <output_directory>]";
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.";
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.";
66 echo -e " -q or --quiet";
67 echo -e " Prevents the output of status information"
69 echo -e " --help, or -h";
70 echo -e " Displays this information";
72 echo -e " -q or --quiet";
73 echo -e " Prevents the output of status information"
75 echo -e " -k or --kill";
76 echo -e " kills running doxygen pids."
78 echo -e "* Further information on using this script, can be found in README.doxygen";
79 echo -e "* in the current directory.";
83 #------------------------------------------------------------------------
84 # Set the target to what was passed on the command line
85 #------------------------------------------------------------------------
88 # need to add the ability to check for an auto gen'd version
89 # used for automatically generating new documentation for each commit
92 # funky bash shell array
93 declare -a OPTLIST[$#];
95 if [ $OPTCOUNT == 0 ] ; then
96 # No options on the command line so set the target list to the core
98 OUTPUTDIR="../$(basename `pwd`)-doxygen";
100 # put all the command line options into an array
101 for f in $COMLINE ; do
102 OPTLIST[$COUNTER]="$f";
106 for (( COUNTER=0 ; $COUNTER < $OPTCOUNT; $[COUNTER++] )) ; do
107 if [ "${OPTLIST[$COUNTER]}" == "--help" ] ; then
108 # output usage information
112 elif [ "${OPTLIST[$COUNTER]}" == "-h" ] ; then
113 # output usage information
119 case ${OPTLIST[$COUNTER]} in
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.";
139 OUTPUTDIR=${OPTLIST[$COUNTER]};
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]};
150 echo -e " ** Error: Non-existent directory specified as a target.\nExiting.";
159 fi # if [ $OPTCOUNT == 0 ] ;
161 if [ $TARGETCOUNT == 0 ] ; then
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";
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]}";
182 [ $QUIETMODE -gt 0 ] || echo -ne "${TARGETLIST[$COUNTER]}, ";
183 TARGETLIST[$COUNTER]="${TARGETLIST[$COUNTER]} \\";
186 [ $QUIETMODE -gt 0 ] || echo -e " -> Set Output Dir to: $OUTPUTDIR";
190 #------------------------------------------------------------------------
191 # Try to extract the version number
192 # todo: find a better way to determine the version
193 #------------------------------------------------------------------------
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`;
206 #------------------------------------------------------------------------
207 # Create a projectname from the tree name
208 #------------------------------------------------------------------------
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`)";
218 #------------------------------------------------------------------------
219 # function to determine the path to the perl executable
220 #------------------------------------------------------------------------
222 if [ -f "$DOXYCONFIG" ] ; then
223 PERLPATH=`grep PERL_PATH $DOXYCONFIG | grep = | cut -d= -f2`
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
234 #------------------------------------------------------------------------
235 # Function to determine the path to the dot executable
236 #------------------------------------------------------------------------
238 if [ -f "$DOXYCONFIG" ] ; then
239 DOTPATH=`grep DOT_PATH $DOXYCONFIG | grep = | cut -d= -f2`
242 if [ -z $DOTPATH ] || [ `basename $DOTPATH 2>/dev/null` != "dot" ] ; then
243 DOTPATH=`which dot 2>/dev/null`;
246 if [ -z $DOTPATH ] || [ `basename $DOTPATH 2>/dev/null` != "dot" ] ; then
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";
257 DOTPATH=`echo $DOTPATH | sed -e 's/dot//'`;
263 #------------------------------------------------------------------------
264 # Function to move stuff around
265 #------------------------------------------------------------------------
266 # eg: move the images into the output directory & the reference doc into the
268 # called after doxygen has finished generating documentation
270 [ $QUIETMODE -gt 0 ] || echo -ne " -> Move stuff.\n";
271 if [ ! -d $OUTPUTDIR ] ; then
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!";
291 if [ ! -d $OUTPUTDIR/images ] ; then
292 mkdir $OUTPUTDIR/images ;
294 cp $EXTRAS_PATH/images/* $OUTPUTDIR/images/ ;
300 #------------------------------------------------------------------------
301 # clean_up() removes old versions of the documentation
302 #------------------------------------------------------------------------
304 if [ -f $OUTPUTDIR/html/index.html ] ; then
305 [ $QUIETMODE -gt 0 ] || echo -e " -> Trashing old dox.";
306 rm -f $OUTPUTDIR/html/*
311 #------------------------------------------------------------------------
312 # Create a new genConf & Doxyfile
313 #------------------------------------------------------------------------
315 [ $QUIETMODE -gt 0 ] || echo -e " -> Generating DoxyConfig.";
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...";
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
329 # remove the old config file
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;
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
349 # echo -e "INPUT=$TARGET" >> $CONFIG_OUTPUT;
351 echo -e "OUTPUT_DIRECTORY=$OUTPUTDIR" >> $CONFIG_OUTPUT;
352 echo -e "\n" >> $CONFIG_OUTPUT;
356 #------------------------------------------------------------------------
357 # Build the reference page & index
358 #------------------------------------------------------------------------
361 REF_OUT="$OUTPUTDIR/reference/index.html"
362 INDEX_OUT="$OUTPUTDIR/index.html"
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
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;
374 if [ ! -d $OUTPUTDIR/example/ ] ; then
375 [ $QUIETMODE -gt 0 ] || echo -e " -> Making example dir";
376 mkdir $OUTPUTDIR/example
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/
382 # Make a redirecting index.html
383 cat $EXTRAS_PATH/doxygen_index.html > $INDEX_OUT;
387 #------------------------------------------------------------------------
389 #------------------------------------------------------------------------
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
397 MACHINE=`uname -n`; # `uname -n` or `hostname` ??
398 cp $EXTRAS_PATH/doxy_mainpage.h 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 ;
408 # Start doxygen with the command "doxygen $DOXYFILE"
409 [ $QUIETMODE -gt 0 ] || echo -e " -> Executing doxygen.";
410 [ $QUIETMODE -gt 0 ] || echo -e "> doxygen $NEWDOXYFILE";
414 # remove doxy_mainpage.h from the target directory
415 rm -f $TEMPLOCATION/doxy_mainpage.h
419 #------------------------------------------------------------------------