0027233: Configuration - do not include version in SONAME for Android target
[occt.git] / adm / gendoc.tcl
1 # =======================================================================
2 # Created on: 2014-03-21
3 # Created by: OMY
4 # Copyright (c) 1996-1999 Matra Datavision
5 # Copyright (c) 1999-2014 OPEN CASCADE SAS
6 #
7 # This file is part of Open CASCADE Technology software library.
8 #
9 # This library is free software; you can redistribute it and/or modify it under
10 # the terms of the GNU Lesser General Public License version 2.1 as published
11 # by the Free Software Foundation, with special exception defined in the file
12 # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 # distribution for complete text of the license and disclaimer of any warranty.
14 #
15 # Alternatively, this file may be used under the terms of Open CASCADE
16 # commercial license or contractual agreement.
17  
18 # =======================================================================
19 # This script defines command gendoc compiling OCCT documents 
20 # from *.md files to HTML pages
21 # =======================================================================
22
23 # load auxiliary tools
24 source [file join [file dirname [info script]] occaux.tcl]
25
26 # ======================================
27 #  Common functions
28 # ======================================
29
30 # Prints help message
31 proc OCCDoc_PrintHelpMessage {} {
32     puts "\nUsage: gendoc \[-h\] {-refman|-overview} \[-html|-pdf|-chm\] \[-m=<list of modules>|-ug=<list of docs>\] \[-v\] \[-s=<search_mode>\] \[-mathjax=<path>\]"
33     puts ""
34     puts "Options are:"
35     puts ""
36     puts "choice of documentation to be generated:"
37     puts "  -overview          : To generate Overview and User Guides"
38     puts "                       (cannot be used with -refman)"
39     puts "  -refman            : To generate class Reference Manual"
40     puts "                       (cannot be used with -overview)"
41     puts ""
42     puts "choice of output format:"
43     puts "  -html              : To generate HTML files"
44     puts "                       (default, cannot be used with -pdf or -chm)"
45     puts "  -pdf               : To generate PDF files"
46     puts "                       (cannot be used with -refman, -html, or -chm)"
47     puts "  -chm               : To generate CHM files"
48     puts "                       (cannot be used with -html or -pdf)"
49     puts ""
50     puts "additional options:"
51     puts "  -m=<modules_list>  : List of OCCT modules (separated with comma),"
52     puts "                       for generation of Reference Manual"
53     puts "  -ug=<docs_list>    : List of MarkDown documents (separated with comma),"
54     puts "                       to use for generation of Overview / User Guides"
55     puts "  -mathjax=<path>    : To use local or alternative copy of MathJax"
56     puts "  -s=<search_mode>   : Specifies the Search mode of HTML documents"
57     puts "                       Can be: none | local | server | external"
58     puts "  -h                 : Prints this help message"
59     puts "  -v                 : Enables more verbose output"    
60 }
61
62 # A command for User Documentation compilation
63 proc gendoc {args} {
64
65   # Parameters
66   set DOC_TYPE                  "REFMAN"
67   set GEN_MODE                  "HTML_ONLY"
68   set DOCFILES                  {}
69   set MODULES                   {}
70   set DOCLABEL                  ""
71   set VERB_MODE                 "NO"
72   set SEARCH_MODE               "none"
73   set MATHJAX_LOCATION          "http://cdn.mathjax.org/mathjax/latest"
74   set mathjax_js_name           "MathJax.js"
75   set DOCTYPE_COMBO_FLAG        0
76   set GENMODE_COMBO_FLAG        0
77   set GENERATE_PRODUCTS_REFMAN "NO"
78
79   global available_docfiles;   # The full list of md files for HTML or CHM generation
80   global available_pdf;        # The full list of md files for PDF generation
81   global tcl_platform
82   global args_names
83   global args_values
84   global env
85
86   # Load list of docfiles
87   if { [OCCDoc_LoadFilesList] != 0 } {
88     puts "Error: File FILES_HTML.txt or FILES_PDF.txt was not found on this computer.\nAborting..."
89     return -1
90   }
91
92   # Parse CL arguments
93   if {[OCCDoc_ParseArguments $args] == 1} {
94     return -1
95   }
96
97   # Print help message if no arguments provided
98   if {[llength $args_names] == 0} {
99     OCCDoc_PrintHelpMessage
100     return 0
101   }
102
103   foreach arg_n $args_names {
104     if {$arg_n == "h"} {
105       OCCDoc_PrintHelpMessage
106       return 0
107     } elseif {$arg_n == "html"} {
108       if { ([ lsearch $args_names "refman" ]   == -1) &&
109            ([ lsearch $args_names "overview" ] == -1) } {
110         puts "Warning: Please specify -refman or -overview argument."
111         return -1
112       }
113       if { [ lsearch $args_names "refman" ] != -1 } {
114         continue
115       }
116       if { $GENMODE_COMBO_FLAG != 1 } {
117         set GEN_MODE "HTML_ONLY"
118         set GENMODE_COMBO_FLAG 1
119       } else {
120         puts "Error: Options -html, -pdf and -chm can not be combined."
121         return -1
122       }
123     } elseif {$arg_n == "chm"} {
124       if { ([ lsearch $args_names "refman" ]   == -1) &&
125            ([ lsearch $args_names "overview" ] == -1) } {
126         puts "Warning: Please specify -refman or -overview argument."
127         return -1
128       }
129       if { [ lsearch $args_names "refman" ] != -1 } {
130         continue
131       }
132       if { $GENMODE_COMBO_FLAG != 1 } { 
133         set GEN_MODE "CHM_ONLY"
134         set GENMODE_COMBO_FLAG 1
135       } else {
136         puts "Error: Options -html, -pdf and -chm cannot be combined."
137         return -1
138       }
139     } elseif {$arg_n == "pdf"} {
140       if { ([ lsearch $args_names "refman" ]   == -1) &&
141            ([ lsearch $args_names "overview" ] == -1) } {
142         puts "Warning: Please specify -refman or -overview argument."
143         return -1
144       }
145       if { [ lsearch $args_names "refman" ] != -1 } {
146         continue
147       }
148       if { $GENMODE_COMBO_FLAG != 1 } { 
149         set GEN_MODE "PDF_ONLY"
150         set GENMODE_COMBO_FLAG 1
151       } else {
152         puts "Error: Options -html, -pdf and -chm cannot be combined."
153         return -1
154       }
155     } elseif {$arg_n == "overview"} {
156       if { $DOCTYPE_COMBO_FLAG != 1 } {
157         set DOC_TYPE "OVERVIEW"
158         set DOCTYPE_COMBO_FLAG 1
159       } else {
160         puts "Error: Options -refman and -overview cannot be combined."
161         return -1
162       }
163
164       # Print ignored options
165       if { [ lsearch $args_names "m" ] != -1 } {
166         puts "\nInfo: The following options will be ignored: \n"
167         puts "  * -m"
168       }
169       puts ""
170     } elseif {$arg_n == "refman"} {
171       if { $DOCTYPE_COMBO_FLAG != 1 } { 
172         set DOC_TYPE "REFMAN"
173         set DOCTYPE_COMBO_FLAG 1
174         if { [info exists env(PRODROOT)] && [file exists $::env(PRODROOT)/src/VAS/Products.tcl] } {
175           set GENERATE_PRODUCTS_REFMAN "YES"
176         }
177       } else {
178         puts "Error: Options -refman and -overview cannot be combined."
179         return -1
180       }
181       # Print ignored options
182       if { ([ lsearch $args_names "pdf" ]     != -1) || 
183            ([ lsearch $args_names "chm" ]     != -1) || 
184            ([ lsearch $args_names "ug" ]      != -1) } {
185         puts "\nInfo: The following options will be ignored: \n"
186         if { [ lsearch $args_names "pdf" ] != -1 } {
187           puts "  * -pdf"
188         }
189         if { [ lsearch $args_names "chm" ] != -1 } {
190           puts "  * -chm"
191         }
192         if { [ lsearch $args_names "ug" ] != -1 } {
193           puts "  * -ug"
194         }
195         puts ""
196       }
197       
198     } elseif {$arg_n == "v"} {
199       set VERB_MODE "YES"
200     } elseif {$arg_n == "ug"} {
201       if { ([ lsearch $args_names "refman" ]   != -1) } {
202         continue
203       }
204       if {$args_values(ug) != "NULL"} {
205         set DOCFILES $args_values(ug)
206       } else {
207         puts "Error in argument ug."
208         return -1
209       }
210       # Check if all chosen docfiles are correct
211       foreach docfile $DOCFILES {
212         if { [ lsearch $args_names "pdf" ] == -1 } {
213           # Check to generate HTMLs
214           if { [lsearch $available_docfiles $docfile] == -1 } {
215             puts "Error: File \"$docfile\" is not presented in the list of available docfiles."
216             puts "       Please specify the correct docfile name."
217             return -1
218           } 
219         } else {
220           # Check to generate PDFs
221           if { [lsearch $available_pdf $docfile] == -1 } {
222             puts "Error: File \"$docfile\" is not presented in the list of generic PDFs."
223             puts "       Please specify the correct pdf name."
224             return -1
225           }
226         }
227       }
228     } elseif {$arg_n == "m"} {
229       if { [ lsearch $args_names "overview" ] != -1 } {
230         continue
231       }
232       if {$args_values(m) != "NULL"} {
233         set MODULES $args_values(m)
234       } else {
235         puts "Error in argument m."
236         return -1
237       }
238     } elseif {$arg_n == "s"} {
239       if { [ lsearch $args_names "pdf" ] != -1 } {
240         continue
241       }
242       if {$args_values(s) != "NULL"} {
243         set SEARCH_MODE $args_values(s)
244       } else {
245         puts "Error in argument s."
246         return -1
247       }
248     } elseif {$arg_n == "mathjax"} {
249       if { [ lsearch $args_names "pdf" ] != -1 } {
250         set possible_mathjax_loc $args_values(mathjax)
251         if {[file exist [file join $possible_mathjax_loc $mathjax_js_name]]} {
252           set MATHJAX_LOCATION $args_values(mathjax)
253           puts "$MATHJAX_LOCATION"
254         } else {
255           puts "Warning: $mathjax_js_name is not found in $possible_mathjax_loc."
256           puts "         MathJax will be used from $MATHJAX_LOCATION"
257         }
258       } else {
259         puts "Warning: MathJax is not used with pdf and will be ignored."
260       }
261     } else {
262       puts "\nWrong argument: $arg_n"
263       OCCDoc_PrintHelpMessage
264       return -1
265     }
266   }
267
268   # Check the existence of the necessary tools
269   set DOXYGEN_PATH  ""
270   set GRAPHVIZ_PATH ""
271   set INKSCAPE_PATH ""
272   set PDFLATEX_PATH ""
273   set HHC_PATH      ""
274
275   OCCDoc_DetectNecessarySoftware $DOXYGEN_PATH $GRAPHVIZ_PATH $INKSCAPE_PATH $HHC_PATH $PDFLATEX_PATH
276
277   if {$DOXYGEN_PATH == ""} {
278     puts " Aborting..."
279     return -1
280   }
281
282   if {"$::tcl_platform(platform)" == "windows"} {
283     if { ($GEN_MODE == "CHM_ONLY") && ($HHC_PATH == "") } {
284       puts " Aborting..."
285       return -1
286     }
287   }
288
289   if { ($PDFLATEX_PATH == "") && ($GEN_MODE == "PDF_ONLY") } {
290     puts " Aborting..."
291     return -1
292   }
293
294   # If we do not specify list for docfiles with -m argument,
295   # we assume that we have to generate all docfiles
296   if { [llength $DOCFILES] == 0 } {
297     if { $GEN_MODE != "PDF_ONLY" } {
298       set DOCFILES $available_docfiles
299     } else {
300       set DOCFILES $available_pdf
301     }
302   }
303
304   puts ""
305
306   # Clean logfiles
307   set DOXYLOG [OCCDoc_GetRootDir]/doc/doxygen_warnings_and_errors.log
308   set PDFLOG  [OCCDoc_GetRootDir]/doc/pdflatex_warnings_and_errors.log
309
310   file delete -force $PDFLOG
311   file delete -force $DOXYLOG
312   
313   # Start main activities
314   if { $GEN_MODE != "PDF_ONLY" } {
315     OCCDoc_Main $DOC_TYPE $DOCFILES $MODULES $GEN_MODE $VERB_MODE $SEARCH_MODE $MATHJAX_LOCATION $GENERATE_PRODUCTS_REFMAN $DOXYGEN_PATH $GRAPHVIZ_PATH $INKSCAPE_PATH $HHC_PATH
316   } else {
317     puts "Generating OCCT User Guides in PDF format...\n"
318     foreach pdf $DOCFILES {
319
320       puts "Info: Processing file $pdf\n"
321
322       # Some values are hardcoded because they are related only to PDF generation
323       OCCDoc_Main "OVERVIEW" [list $pdf] {} "PDF_ONLY" $VERB_MODE "none" $MATHJAX_LOCATION "NO" $DOXYGEN_PATH $GRAPHVIZ_PATH $INKSCAPE_PATH $HHC_PATH
324     }
325     puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generation completed."
326     puts "\nPDF files are generated in \n[file normalize [OCCDoc_GetRootDir]/doc/pdf]"
327   }
328 }
329
330 # Main procedure for documents compilation
331 proc OCCDoc_Main {docType {docfiles {}} {modules {}} generatorMode verboseMode searchMode mathjaxLocation generateProductsRefman DOXYGEN_PATH GRAPHVIZ_PATH INKSCAPE_PATH HHC_PATH} {
332
333   global available_docfiles
334   global available_pdf
335
336   set PRODPATH   ""
337   if { [string compare -nocase $generateProductsRefman "YES"] == 0 } {
338     set PRODPATH "$::env(PRODROOT)"
339   }
340
341   set ROOTDIR    [OCCDoc_GetRootDir $PRODPATH]
342   set INDIR      [OCCDoc_GetDoxDir]
343   set OUTDIR     $ROOTDIR/doc
344   set PDFDIR     $OUTDIR/pdf
345   set UGDIR      $PDFDIR/user_guides
346   set DGDIR      $PDFDIR/dev_guides
347   set TAGFILEDIR $OUTDIR/refman
348   set HTMLDIR    $OUTDIR/overview/html
349   set LATEXDIR   $OUTDIR/overview/latex
350   set DOXYFILE   $OUTDIR/OCCT.cfg
351  
352   # Create or cleanup the output folders
353   if { [string compare -nocase $generateProductsRefman "YES"] != 0 } {
354     if { ![file exists $OUTDIR] } {
355       file mkdir $OUTDIR
356     } 
357     if { ![file exists $HTMLDIR] } {
358       file mkdir $HTMLDIR
359     }
360     if { ![file exists $PDFDIR] } {
361       file mkdir $PDFDIR
362     }
363     if { ![file exists $UGDIR] } {
364       file mkdir $UGDIR
365     }
366     if { ![file exists $DGDIR] } {
367       file mkdir $DGDIR
368     }
369     if { [file exists $LATEXDIR] } {
370       file delete -force $LATEXDIR
371     }
372     file mkdir $LATEXDIR
373   }
374   if { $docType == "REFMAN" } {
375     if { ![file exists $TAGFILEDIR] } {
376       file mkdir $TAGFILEDIR
377     }
378   }
379
380   # is MathJax HLink?
381   set mathjax_relative_location $mathjaxLocation
382   if { [file isdirectory "$mathjaxLocation"] } {
383     if { $generatorMode == "HTML_ONLY" } {
384       # related path
385       set mathjax_relative_location [OCCDoc_GetRelPath $HTMLDIR $mathjaxLocation]
386     } elseif { $generatorMode == "CHM_ONLY" } {
387       # absolute path
388       set mathjax_relative_location [file normalize $mathjaxLocation]
389     }
390   }
391
392   if { $generateProductsRefman == "YES" } {
393     set DOCDIR "$OUTDIR/refman"
394     puts "\nGenerating OCC Products Reference Manual\n"
395   } else {
396     if { $docType == "REFMAN"} {
397       set DOCDIR "$OUTDIR/refman"
398       puts "\nGenerating Open CASCADE Reference Manual\n"
399     } elseif { $docType == "OVERVIEW" } {
400       set DOCDIR "$OUTDIR/overview"
401       set FORMAT ""
402       if { ($generatorMode == "HTML_ONLY") || ($generatorMode == "CHM_ONLY") } {
403         if { $generatorMode == "HTML_ONLY" } { 
404           set FORMAT " in HTML format..."
405         } elseif { $generatorMode == "CHM_ONLY" } {
406           set FORMAT " in CHM format..."
407         }
408         puts "Generating OCCT User Guides$FORMAT\n"
409       }
410     } else {
411       puts "Error: Invalid documentation type: $docType. Can not process."
412       return -1
413     }
414   }
415
416   # Generate Doxyfile
417   puts "[clock format [clock seconds] -format {%Y-%m-%d %H:%M}] Generating Doxyfile..."
418
419   if { [OCCDoc_MakeDoxyfile $docType $DOCDIR $TAGFILEDIR $DOXYFILE $generatorMode $docfiles $modules $verboseMode $searchMode $HHC_PATH $mathjax_relative_location $GRAPHVIZ_PATH $PRODPATH] == -1 } {
420     return -1
421   }
422
423   # Run doxygen tool
424   set starttimestamp [clock format [clock seconds] -format {%Y-%m-%d %H:%M}]
425
426   if { ($generatorMode == "HTML_ONLY") || ($docType == "REFMAN") } {
427     puts "$starttimestamp Generating HTML files..."
428
429     # Copy index file to provide fast access to HTML documentation
430     file copy -force $INDIR/resources/index.html $DOCDIR/index.html
431   } elseif { $generatorMode == "CHM_ONLY" } {
432     puts "$starttimestamp Generating CHM file..."
433   } elseif { $generatorMode == "PDF_ONLY" } {
434     puts "$starttimestamp Generating PDF file..."
435   }
436
437   set DOXYLOG $OUTDIR/doxygen_warnings_and_errors.log
438   set RESULT [catch {exec $DOXYGEN_PATH $DOXYFILE >> $OUTDIR/doxygen_out.log} DOX_ERROR] 
439   if {$RESULT != 0} {
440     set NbErrors [regexp -all -line {^\s*[^\s]+} $DOX_ERROR]
441     if {$NbErrors > 0} {
442       puts "\nWarning: Doxygen reported $NbErrors messages."
443       puts "See log in $DOXYLOG\n"
444       set DOX_ERROR_FILE [open $DOXYLOG "a"]
445       if {$generatorMode == "PDF_ONLY"} {
446         puts $DOX_ERROR_FILE "\n===================================================="
447         puts $DOX_ERROR_FILE "Logfile for $docfiles"
448         puts $DOX_ERROR_FILE "====================================================\n"
449       }
450       puts $DOX_ERROR_FILE $DOX_ERROR
451       close $DOX_ERROR_FILE
452     }
453   }
454
455   # Close the Doxygen application
456   after 300
457
458   # Start Post Processing
459   set curtime [clock format [clock seconds] -format {%Y-%m-%d %H:%M}]
460   if { $docType == "REFMAN" } {
461     # Post Process generated HTML pages and draw dependency graphs
462     if {[OCCDoc_PostProcessor $DOCDIR] == 0} {
463       puts "$curtime Generation completed."
464       puts "\nInfo: doxygen log file is located in:"
465       puts "$OUTDIR/doxygen_out.log."
466       puts "\nReference Manual is generated in \n$DOCDIR"
467     }
468   } elseif { $docType == "OVERVIEW" } {
469     # Start PDF generation routine
470     if { $generatorMode == "PDF_ONLY" } {
471       set OS $::tcl_platform(platform)
472       if { $OS == "unix" } {
473         set PREFIX ".sh"
474       } elseif { $OS == "windows" } {
475         set PREFIX ".bat"
476       }
477
478       # Prepare a list of TeX files, generated by Doxygen
479       cd $LATEXDIR
480
481       set TEXFILES   [glob $LATEXDIR -type f -directory $LATEXDIR -tails "*.tex" ]
482       foreach path $TEXFILES {
483         if { [string compare -nocase $path $LATEXDIR] == 0 } {
484           set DEL_IDX [lsearch $TEXFILES $path]
485           if { $DEL_IDX != -1 } {
486             set TEXFILES [lreplace $TEXFILES $DEL_IDX $DEL_IDX]
487           }
488         }
489       }
490       set TEXFILES   [string map [list refman.tex ""] $TEXFILES]
491       if {$verboseMode == "YES"} {
492         puts "Info: Preprocessing generated TeX files..."
493       }
494       OCCDoc_ProcessTex $TEXFILES $LATEXDIR $verboseMode
495
496       if {$verboseMode == "YES"} {
497         puts "Info: Converting SVG images to PNG format..."
498       }
499
500       if { $INKSCAPE_PATH != "" } {
501         OCCDoc_ProcessSvg $LATEXDIR $verboseMode
502       } else {
503         puts "Warning: SVG images will be lost in PDF documents."
504       }
505
506       if {$verboseMode == "YES"} {
507         puts "Info: Generating PDF file from TeX files..."
508       }
509       foreach TEX $TEXFILES {
510         # Rewrite existing REFMAN.tex file...
511         set TEX [lindex [split $TEX "."] 0]
512
513         if {$verboseMode == "YES"} {
514           puts "Info: Generating PDF file from $TEX..."
515         }
516
517         OCCDoc_MakeRefmanTex $TEX $LATEXDIR $verboseMode $available_pdf
518
519         if {"$::tcl_platform(platform)" == "windows"} {
520           set is_win "yes"
521         } else {
522           set is_win "no"
523         }
524         if {$verboseMode == "YES"} {
525           # ...and use it to generate PDF from TeX...
526           if {$is_win == "yes"} {
527             puts "Info: Executing $LATEXDIR/make.bat..."
528           } else {
529             puts "Info: Executing $LATEXDIR/Makefile..."
530           }
531         }
532         set PDFLOG $OUTDIR/pdflatex_warnings_and_errors.log
533
534         if {"$is_win" == "yes"} {
535           set RESULT [catch {eval exec [auto_execok $LATEXDIR/make.bat] >> "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
536         } else {
537           set RESULT [catch {eval exec "make -f $LATEXDIR/Makefile" >> "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
538
539           # Small workaround for *nix stations
540           set prev_loc [pwd]
541           cd $LATEXDIR
542           set RESULT [catch {eval exec "pdflatex refman.tex" >> "$OUTDIR/pdflatex_out.log"} LaTeX_ERROR]
543           cd $prev_loc
544         }
545
546         if {$RESULT != 0} {
547           set NbErrors [regexp -all -line {^\s*[^\s]+} $LaTeX_ERROR]
548           if {$NbErrors > 0} {
549             puts "\nWarning: PDFLaTeX reported $NbErrors messages.\nSee log in $PDFLOG\n"
550             set LaTeX_ERROR_FILE [open $PDFLOG "a"]
551             puts $LaTeX_ERROR_FILE "\n===================================================="
552             puts $LaTeX_ERROR_FILE "Logfile of file $TEX:"
553             puts $LaTeX_ERROR_FILE "====================================================\n"
554             puts $LaTeX_ERROR_FILE $LaTeX_ERROR
555             close $LaTeX_ERROR_FILE
556           }
557         }
558
559         # ...and place it to the specific folder
560         if {![file exists "$LATEXDIR/refman.pdf"]} {
561           puts "Fatal: PDFLaTeX failed to create output file, stopping!"
562           return -1
563         }
564
565         set destFolder $PDFDIR
566         set parsed_string [split $TEX "_"]
567         if { [lsearch $parsed_string "tutorial"] != -1 } {
568           set TEX [string map [list occt__ occt_] $TEX]
569           set destFolder $PDFDIR
570         } elseif { [lsearch $parsed_string "user"] != -1 } {
571           set TEX [string map [list user_guides__ ""] $TEX]
572           set destFolder $UGDIR
573         } elseif { [lsearch $parsed_string "dev"]  != -1 } {
574           set TEX [string map [list dev_guides__ ""] $TEX]
575           set destFolder $DGDIR
576         }
577         file rename -force $LATEXDIR/refman.pdf "$destFolder/$TEX.pdf"
578
579       }
580     } elseif { $generatorMode == "CHM_ONLY" } {
581       file rename  $OUTDIR/overview.chm $OUTDIR/occt_overview.chm
582     }
583     cd $INDIR
584
585     if { $generatorMode == "HTML_ONLY" } {
586       puts "\nHTML documentation is generated in \n$DOCDIR"
587     }
588     if { $generatorMode == "CHM_ONLY" } {
589       puts "\nGenerated CHM documentation is in \n$OUTDIR/overview.chm"
590     }
591
592     puts ""
593   }
594
595   # Remove temporary Doxygen files
596   set deleteList [glob -nocomplain -type f "*.tmp"]
597   foreach file $deleteList {
598     file delete $file
599   }
600   return 0
601 }
602
603 # Generates Doxygen configuration file for Overview documentation
604 proc OCCDoc_MakeDoxyfile {docType outDir tagFileDir {doxyFileName} {generatorMode ""} {DocFilesList {}} {ModulesList {}} verboseMode searchMode hhcPath mathjaxLocation graphvizPath productsPath} {
605
606   set inputDir      [OCCDoc_GetDoxDir]
607   set TEMPLATES_DIR $inputDir/resources
608   set occt_version  [OCCDoc_DetectCasVersion]
609
610   # Delete existent doxyfile
611   file delete $doxyFileName
612
613   # Copy specific template to the target folder
614   if { $docType == "REFMAN" } {
615     file copy "$TEMPLATES_DIR/occt_rm.doxyfile" $doxyFileName
616   } elseif { $docType == "OVERVIEW" } {
617     if { $generatorMode == "HTML_ONLY" || $generatorMode == "CHM_ONLY" } {
618       file copy "$TEMPLATES_DIR/occt_ug_html.doxyfile" $doxyFileName
619     } elseif { $generatorMode == "PDF_ONLY"} {
620       file copy "$TEMPLATES_DIR/occt_ug_pdf.doxyfile" $doxyFileName
621     } else {
622       puts "Error: Unknown generation mode"
623       return -1
624     }
625   } else {
626     puts "Error: Cannot generate unknown document type"
627     return -1
628   }
629
630   set doxyFile [open $doxyFileName "a"]
631   # Write specific options
632   if { $docType == "REFMAN" } {
633
634     # Load lists of modules scripts
635     if { $productsPath == "" } {
636       set modules_scripts [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $productsPath]/OS/" *.tcl]
637     } else {
638       set modules_scripts [glob -nocomplain -type f -directory "[OCCDoc_GetSourceDir $productsPath]/VAS/" *.tcl]
639     }
640     if { [llength $modules_scripts] != 0} {
641       foreach module_file $modules_scripts {
642         source $module_file
643       }
644     }
645
646     set ALL_MODULES [OCCDoc_GetModulesList $productsPath]
647     if { [llength $ModulesList] == 0 } {
648       # by default take all modules
649       set modules $ALL_MODULES
650     } else {
651       set modules $ModulesList
652     }
653
654     # Detect invalid names of modules
655     foreach module $modules {
656       if { $module == "" } {
657         continue
658       }
659       if {[lsearch $ALL_MODULES $module] == -1 } {
660         puts "Error: No module $module is known. Aborting..."
661         return -1
662       }
663     }
664
665     # Set context
666     set one_module [expr [llength $modules] == 1]
667     if { $one_module } {
668       set title "OCCT [$modules:name]"
669       set name $modules
670     } else {
671       set title "Open CASCADE Technology"
672       set name OCCT
673     }
674
675     # Get list of header files in the specified modules
676     set filelist {}
677     foreach module $modules {
678       if { $module == "" } {
679         continue
680       }
681       foreach tk [$module:toolkits] {
682         foreach pk [split [OCCDoc_GetPackagesList [OCCDoc_Locate $tk $productsPath]]] {
683           if { [llength $pk] != "{}" } {
684             lappend filelist [OCCDoc_GetHeadersList "p" "$pk" "$productsPath"]
685           }
686         }
687       }
688     }
689
690     # Filter out files Handle_*.hxx and *.lxx
691     set hdrlist {}
692     foreach fileset $filelist {
693       set hdrset {}
694       foreach hdr $fileset {
695         if { ! [regexp {Handle_.*[.]hxx} $hdr] && ! [regexp {.*[.]lxx} $hdr] } {
696           lappend hdrset $hdr
697         }
698       }
699       lappend hdrlist $hdrset
700     }
701     set filelist $hdrlist
702
703     set doxyFile [open $doxyFileName "a"]
704   
705     puts $doxyFile "PROJECT_NAME           = \"$title\""
706     puts $doxyFile "PROJECT_NUMBER         = $occt_version"
707     puts $doxyFile "OUTPUT_DIRECTORY       = $outDir/."
708     puts $doxyFile "GENERATE_TAGFILE       = $outDir/${name}.tag"
709
710     if { [string tolower $searchMode] == "none" } {
711       puts $doxyFile "SEARCHENGINE           = NO"
712       puts $doxyFile "SERVER_BASED_SEARCH    = NO"
713       puts $doxyFile "EXTERNAL_SEARCH        = NO"
714     } else {
715       puts $doxyFile "SEARCHENGINE           = YES"
716       if { [string tolower $searchMode] == "local" } {
717         puts $doxyFile "SERVER_BASED_SEARCH    = NO"
718         puts $doxyFile "EXTERNAL_SEARCH        = NO"
719       } elseif { [string tolower $searchMode] == "server" } {
720         puts $doxyFile "SERVER_BASED_SEARCH    = YES"
721         puts $doxyFile "EXTERNAL_SEARCH        = NO"
722       } elseif { [string tolower $searchMode] == "external" } {
723         puts $doxyFile "SERVER_BASED_SEARCH    = YES"
724         puts $doxyFile "EXTERNAL_SEARCH        = YES"
725       } else {
726         puts "Error: Wrong search engine type: $searchMode."
727         close $doxyFile 
728         return -1
729       }
730     }
731
732     puts $doxyFile "DOTFILE_DIRS             = $outDir/html"
733     puts $doxyFile "DOT_PATH                 = $graphvizPath"
734     puts $doxyFile "INCLUDE_PATH             = [OCCDoc_GetSourceDir $productsPath]"
735     
736     # list of files to generate
737     set mainpage [OCCDoc_MakeMainPage $outDir $outDir/$name.dox $modules $productsPath]
738     puts $doxyFile ""
739     puts $doxyFile "INPUT    = $mainpage \\"
740     foreach header $filelist {
741       puts $doxyFile "               $header \\"
742     }
743
744     puts $doxyFile "MATHJAX_FORMAT         = HTML-CSS"
745     puts $doxyFile "MATHJAX_RELPATH        = ${mathjaxLocation}"
746
747     puts $doxyFile ""
748
749   } elseif { $docType == "OVERVIEW" } {
750
751     # Add common options for generation of Overview and User Guides
752     puts $doxyFile "PROJECT_NUMBER         = $occt_version"
753     puts $doxyFile "OUTPUT_DIRECTORY       = $outDir/."
754     puts $doxyFile "PROJECT_LOGO           = $inputDir/resources/occ_logo.png"
755
756     set PARAM_INPUT "INPUT                 ="
757     set PARAM_IMAGEPATH "IMAGE_PATH        = $inputDir/resources/ "
758     foreach docFile $DocFilesList {
759       set NEW_IMG_PATH "$inputDir/$docFile"
760       if { [string compare $NEW_IMG_PATH [OCCDoc_GetRootDir $productsPath]] != 0 } {
761         set img_string [file dirname $NEW_IMG_PATH]/images
762         if { [file exists $img_string] } {
763           append PARAM_IMAGEPATH " $img_string"
764         }
765       }
766       append PARAM_INPUT " " $inputDir/$docFile
767     }
768     puts $doxyFile $PARAM_INPUT
769     puts $doxyFile $PARAM_IMAGEPATH
770
771     # Add document type-specific options
772     if { $generatorMode == "HTML_ONLY"} {
773       # generate tree view
774       puts $doxyFile "GENERATE_TREEVIEW      = YES"
775
776       # Set a reference to a TAGFILE
777       if { $tagFileDir != "" } {
778         if {[file exists $tagFileDir/OCCT.tag] == 1} {
779           #set tagPath [OCCDoc_GetRelPath $tagFileDir $outDir/html]
780           set tagPath $tagFileDir
781           puts $doxyFile "TAGFILES               = $tagFileDir/OCCT.tag=../../refman/html"
782         }
783       }
784       # HTML Search engine options
785       if { [string tolower $searchMode] == "none" } {
786         puts $doxyFile "SEARCHENGINE           = NO"
787         puts $doxyFile "SERVER_BASED_SEARCH    = NO"
788         puts $doxyFile "EXTERNAL_SEARCH        = NO"
789       } else {
790         puts $doxyFile "SEARCHENGINE           = YES"
791         if { [string tolower $searchMode] == "local" } {
792           puts $doxyFile "SERVER_BASED_SEARCH    = NO"
793           puts $doxyFile "EXTERNAL_SEARCH        = NO"
794         } elseif { [string tolower $searchMode] == "server" } {
795           puts $doxyFile "SERVER_BASED_SEARCH    = YES"
796           puts $doxyFile "EXTERNAL_SEARCH        = NO"
797         } elseif { [string tolower $searchMode] == "external" } {
798           puts $doxyFile "SERVER_BASED_SEARCH    = YES"
799           puts $doxyFile "EXTERNAL_SEARCH        = YES"
800         } else {
801           puts "Error: Wrong search engine type: $searchMode."
802           close $doxyFile 
803           return -1
804         }
805       }
806     } elseif { $generatorMode == "CHM_ONLY"} {
807       # specific options for CHM file generation
808       puts $doxyFile "GENERATE_TREEVIEW      = NO"
809       puts $doxyFile "SEARCHENGINE           = NO"
810       puts $doxyFile "GENERATE_HTMLHELP      = YES"
811       puts $doxyFile "CHM_FILE               = ../../overview.chm"
812       puts $doxyFile "HHC_LOCATION           = \"$hhcPath\""
813       puts $doxyFile "DISABLE_INDEX          = YES"
814     }
815
816     # Formula options
817     puts $doxyFile "MATHJAX_RELPATH        = ${mathjaxLocation}"
818   }
819
820   close $doxyFile
821   return 0
822 }