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