0028840: Data Exchange - rewrite the STL Reader/Writer
[occt.git] / adm / genconfdeps.tcl
1 # =======================================================================
2 # Created on: 2012-01-26
3 # Created by: Kirill GAVRILOV
4 # Copyright (c) 2012 OPEN CASCADE SAS
5 #
6 # This file is part of Open CASCADE Technology software library.
7 #
8 # This library is free software; you can redistribute it and/or modify it under
9 # the terms of the GNU Lesser General Public License version 2.1 as published
10 # by the Free Software Foundation, with special exception defined in the file
11 # OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 # distribution for complete text of the license and disclaimer of any warranty.
13 #
14 # Alternatively, this file may be used under the terms of Open CASCADE
15 # commercial license or contractual agreement.
16
17 # =======================================================================
18 # Tools for search of third-party libraries and generation on environment
19 # customization script
20 # =======================================================================
21
22 set ARCH "64"
23
24 if { "$tcl_platform(platform)" == "unix" } {
25   set SYS_PATH_SPLITTER ":"
26   set SYS_LIB_PREFIX    "lib"
27   set SYS_EXE_SUFFIX    ""
28   if { "$tcl_platform(os)" == "Darwin" } {
29     set SYS_LIB_SUFFIX "dylib"
30   } else {
31     set SYS_LIB_SUFFIX "so"
32   }
33   set VCVER "gcc"
34   set VCVARS ""
35 } elseif { "$tcl_platform(platform)" == "windows" } {
36   set SYS_PATH_SPLITTER ";"
37   set SYS_LIB_PREFIX    ""
38   set SYS_LIB_SUFFIX    "lib"
39   set SYS_EXE_SUFFIX    ".exe"
40   set VCVER  "vc10"
41   set VCVARS ""
42 }
43
44 set SHORTCUT_HEADERS "ShortCut"
45
46 set PRODUCTS_PATH ""
47 set CSF_OPT_INC   [list]
48 set CSF_OPT_LIB32 [list]
49 set CSF_OPT_LIB64 [list]
50 set CSF_OPT_BIN32 [list]
51 set CSF_OPT_BIN64 [list]
52
53 if { "$tcl_platform(pointerSize)" == "4" } {
54   set ARCH "32"
55 }
56 if { [info exists ::env(ARCH)] } {
57   set ARCH "$::env(ARCH)"
58 }
59
60 if { [info exists ::env(SHORTCUT_HEADERS)] } {
61   set SHORTCUT_HEADERS "$::env(SHORTCUT_HEADERS)"
62   if { $SHORTCUT_HEADERS == "true" } {
63     set SHORTCUT_HEADERS "ShortCut"
64   }
65 }
66
67 # fetch environment variables (e.g. set by custom.sh or custom.bat) and set them as tcl variables with the same name
68 set THE_ENV_VARIABLES {HAVE_FREEIMAGE HAVE_FFMPEG HAVE_TBB HAVE_GLES2 HAVE_D3D HAVE_VTK HAVE_GL2PS HAVE_ZLIB HAVE_LIBLZMA HAVE_OPENCL CHECK_QT4 CHECK_JDK MACOSX_USE_GLX HAVE_RelWithDebInfo}
69 foreach anEnvIter $THE_ENV_VARIABLES {
70   set ${anEnvIter} "false"
71   if { [info exists ::env(${anEnvIter})] } {
72     set ${anEnvIter} "$::env(${anEnvIter})"
73   }
74 }
75 # do not export platform-specific variables
76 if { "$::tcl_platform(os)" == "Darwin" } {
77   set HAVE_GLES2 ""
78 } else {
79   set MACOSX_USE_GLX ""
80 }
81 if { "$tcl_platform(platform)" != "windows" } {
82   set HAVE_D3D ""
83   set HAVE_RelWithDebInfo ""
84 }
85 foreach anEnvIter {ARCH VCVER VCVARS PRODUCTS_PATH} {
86   if { [info exists ::env(${anEnvIter})] } {
87     set ${anEnvIter} "$::env(${anEnvIter})"
88   }
89 }
90
91 if { [info exists ::env(CSF_OPT_INC)] } {
92   set CSF_OPT_INC [split "$::env(CSF_OPT_INC)" $::SYS_PATH_SPLITTER]
93 }
94 if { [info exists ::env(CSF_OPT_LIB32)] } {
95   set CSF_OPT_LIB32 [split "$::env(CSF_OPT_LIB32)" $::SYS_PATH_SPLITTER]
96 }
97 if { [info exists ::env(CSF_OPT_LIB64)] } {
98   set CSF_OPT_LIB64 [split "$::env(CSF_OPT_LIB64)" $::SYS_PATH_SPLITTER]
99 }
100 if { [info exists ::env(CSF_OPT_BIN32)] } {
101   set CSF_OPT_BIN32 [split "$::env(CSF_OPT_BIN32)" $::SYS_PATH_SPLITTER]
102 }
103 if { [info exists ::env(CSF_OPT_BIN64)] } {
104   set CSF_OPT_BIN64 [split "$::env(CSF_OPT_BIN64)" $::SYS_PATH_SPLITTER]
105 }
106
107 # Search header file in $::CSF_OPT_INC and standard paths
108 proc wokdep:SearchHeader {theHeader} {
109   # search in custom paths
110   foreach anIncPath $::CSF_OPT_INC {
111     set aPath "${anIncPath}/${theHeader}"
112     if { [file exists "$aPath"] } {
113       return "$aPath"
114     }
115   }
116
117   # search in system
118   set aPath "/usr/include/${theHeader}"
119   if { [file exists "$aPath"] } {
120     return "$aPath"
121   }
122
123   if { "$::tcl_platform(os)" == "Linux" } {
124     if { "$::ARCH" == "64" } {
125       set aPath "/usr/include/x86_64-linux-gnu/${theHeader}"
126       if { [file exists "$aPath"] } {
127         return "$aPath"
128       }
129     } else {
130       set aPath "/usr/include/i386-linux-gnu/${theHeader}"
131       if { [file exists "$aPath"] } {
132         return "$aPath"
133       }
134     }
135   }
136
137   return ""
138 }
139
140 # Search library file in $::CSF_OPT_LIB* and standard paths
141 proc wokdep:SearchLib {theLib theBitness {theSearchPath ""}} {
142   if { "$theSearchPath" != "" } {
143     set aPath "${theSearchPath}/${::SYS_LIB_PREFIX}${theLib}.${::SYS_LIB_SUFFIX}"
144     if { [file exists "$aPath"] } {
145       return "$aPath"
146     } else {
147       return ""
148     }
149   }
150
151   # search in custom paths
152   foreach aLibPath [set ::CSF_OPT_LIB$theBitness] {
153     set aPath "${aLibPath}/${::SYS_LIB_PREFIX}${theLib}.${::SYS_LIB_SUFFIX}"
154     if { [file exists "$aPath"] } {
155       return "$aPath"
156     }
157   }
158
159   # search in system
160   if { "$::ARCH" == "$theBitness"} {
161     set aPath "/usr/lib/${::SYS_LIB_PREFIX}${theLib}.${::SYS_LIB_SUFFIX}"
162     if { [file exists "$aPath"] } {
163       return "$aPath"
164     }
165   }
166
167
168   if { "$::tcl_platform(os)" == "Linux" } {
169     if { "$theBitness" == "64" } {
170       set aPath "/usr/lib/x86_64-linux-gnu/lib${theLib}.so"
171       if { [file exists "$aPath"] } {
172         return "$aPath"
173       }
174     } else {
175       set aPath "/usr/lib/i386-linux-gnu/lib${theLib}.so"
176       if { [file exists "$aPath"] } {
177         return "$aPath"
178       }
179     }
180   }
181
182   return ""
183 }
184
185 # Search file in $::CSF_OPT_BIN* and standard paths
186 proc wokdep:SearchBin {theBin theBitness {theSearchPath ""}} {
187   if { "$theSearchPath" != "" } {
188     set aPath "${theSearchPath}/${theBin}"
189     if { [file exists "$aPath"] } {
190       return "$aPath"
191     } else {
192       return ""
193     }
194   }
195
196   # search in custom paths
197   foreach aBinPath [set ::CSF_OPT_BIN$theBitness] {
198     set aPath "${aBinPath}/${theBin}"
199     if { [file exists "$aPath"] } {
200       return "$aPath"
201     }
202   }
203
204   # search in system
205   if { "$::ARCH" == "$theBitness"} {
206     set aPath "/usr/bin/${theBin}"
207     if { [file exists "$aPath"] } {
208       return "$aPath"
209     }
210   }
211
212   return ""
213 }
214
215 # Detect compiler C-runtime version 'vc*' and architecture '32'/'64'
216 # to determine preferred path.
217 proc wokdep:Preferred {theList theCmpl theArch} {
218   if { [llength $theList] == 0 } {
219     return ""
220   }
221
222   # keep only two first digits in "vc141"
223   if { ! [regexp {^vc[0-9][0-9]} $theCmpl aCmpl] } {
224     set aCmpl $theCmpl
225   }
226
227   set aShortList {}
228   foreach aPath $theList {
229     if { [string first "$aCmpl" "$aPath"] != "-1" } {
230       lappend aShortList "$aPath"
231     }
232   }
233
234   if { [llength $aShortList] == 0 } {
235     #return [lindex $theList 0]
236     set aShortList $theList
237   }
238
239   set aVeryShortList {}
240   foreach aPath $aShortList {
241     if { [string first "$theArch" "$aPath"] != "-1" } {
242       lappend aVeryShortList "$aPath"
243     }
244   }
245   if { [llength $aVeryShortList] == 0 } {
246     return [lindex [lsort -decreasing $aShortList] 0]
247   }
248
249   return [lindex [lsort -decreasing $aVeryShortList] 0]
250 }
251
252 # Search library placement
253 proc wokdep:SearchStandardLibrary {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64 theName theCheckHeader theCheckLib theCheckFolders} {
254   upvar $theErrInc   anErrInc
255   upvar $theErrLib32 anErrLib32
256   upvar $theErrLib64 anErrLib64
257   upvar $theErrBin32 anErrBin32
258   upvar $theErrBin64 anErrBin64
259
260   set isFound "true"
261   set aHeaderPath [wokdep:SearchHeader "$theCheckHeader"]
262   if { "$aHeaderPath"  == "" } {
263     set hasHeader false
264     foreach aFolderIter $theCheckFolders {
265       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{$aFolderIter}*] "$::VCVER" "$::ARCH" ]
266       if { "$aPath" != "" && [file exists "$aPath/include/$theCheckHeader"] } {
267         lappend ::CSF_OPT_INC "$aPath/include"
268         set hasHeader true
269         break
270       }
271     }
272     if { !$hasHeader } {
273       lappend anErrInc "Error: '$theCheckHeader' not found ($theName)"
274       set isFound "false"
275     }
276   }
277
278   foreach anArchIter {64 32} {
279     set aLibPath [wokdep:SearchLib "$theCheckLib" "$anArchIter"]
280     if { "$aLibPath" == "" } {
281       set hasLib false
282       foreach aFolderIter $theCheckFolders {
283         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{$aFolderIter}*] "$::VCVER" "$anArchIter" ]
284         set aLibPath [wokdep:SearchLib "$theCheckLib" "$anArchIter" "$aPath/lib"]
285         if { "$aLibPath" != "" } {
286           lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
287           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
288           set hasLib true
289           break
290         }
291       }
292       if { !$hasLib } {
293         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}$theCheckLib.${::SYS_LIB_SUFFIX}' not found ($theName)"
294         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
295       }
296     }
297
298     if { "$::tcl_platform(platform)" == "windows" } {
299       set aDllPath [wokdep:SearchBin "$theCheckLib.dll" "$anArchIter"]
300       if { "$aDllPath" == "" } {
301         set hasDll false
302         foreach aFolderIter $theCheckFolders {
303           set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{$aFolderIter}*] "$::VCVER" "$anArchIter" ]
304           set aDllPath [wokdep:SearchBin "$theCheckLib.dll" "$anArchIter" "$aPath/bin"]
305           if { "$aDllPath" != "" } {
306             lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
307             set hasDll true
308             break
309           } else {
310             set aDllPath [wokdep:SearchBin "$theCheckLib.dll" "$anArchIter" "$aPath/lib"]
311             if { "$aDllPath" != "" } {
312               lappend ::CSF_OPT_BIN$anArchIter "$aPath/lib"
313               set hasDll true
314               break
315             }
316           }
317         }
318         if { !$hasDll } {
319           lappend anErrBin$anArchIter "Error: '$theCheckLib.dll' not found ($theName)"
320           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
321         }
322       }
323     }
324   }
325
326   return "$isFound"
327 }
328
329 # Search Tcl/Tk libraries placement
330 proc wokdep:SearchTclTk {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
331   upvar $theErrInc   anErrInc
332   upvar $theErrLib32 anErrLib32
333   upvar $theErrLib64 anErrLib64
334   upvar $theErrBin32 anErrBin32
335   upvar $theErrBin64 anErrBin64
336
337   set tclver_maj 8
338   set tclver_min 6
339   
340   set isFound "true"
341   set aTclHPath [wokdep:SearchHeader "tcl.h"]
342   set aTkHPath  [wokdep:SearchHeader "tk.h"]
343   if { "$aTclHPath" == "" || "$aTkHPath" == "" } {
344     if { [file exists "/usr/include/tcl8.6/tcl.h"]
345       && [file exists "/usr/include/tcl8.6/tk.h" ] } {
346       lappend ::CSF_OPT_INC "/usr/include/tcl8.6"
347       set aTclHPath "/usr/include/tcl8.6/tcl.h"
348     } else {
349       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tcl}*] "$::VCVER" "$::ARCH" ]
350       if { "$aPath" != "" && [file exists "$aPath/include/tcl.h"] && [file exists "$aPath/include/tk.h"] } {
351         lappend ::CSF_OPT_INC "$aPath/include"
352         set aTclHPath "$aPath/include/tcl.h"
353       } else {
354         lappend anErrInc "Error: 'tcl.h' or 'tk.h' not found (Tcl/Tk)"
355         set isFound "false"
356       }
357     }
358   }
359
360   # detect tcl version by parsing header file
361   if { $isFound } {
362     set fh [open $aTclHPath]
363     set tcl_h [read $fh]
364     close $fh
365     regexp {define\s+TCL_MAJOR_VERSION\s+([0-9]+)} $tcl_h dummy tclver_maj
366     regexp {define\s+TCL_MINOR_VERSION\s+([0-9]+)} $tcl_h dummy tclver_min
367   }
368
369   if { "$::tcl_platform(platform)" == "windows" } {
370     set aTclLibName "tcl${tclver_maj}${tclver_min}"
371     set aTkLibName  "tk${tclver_maj}${tclver_min}"
372   } else {
373     set aTclLibName "tcl${tclver_maj}.${tclver_min}"
374     set aTkLibName  "tk${tclver_maj}.${tclver_min}"
375   }
376
377   foreach anArchIter {64 32} {
378     set aTclLibPath [wokdep:SearchLib "$aTclLibName" "$anArchIter"]
379     set aTkLibPath  [wokdep:SearchLib "$aTkLibName"  "$anArchIter"]
380     if { "$aTclLibPath" == "" || "$aTkLibPath" == "" } {
381       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tcl}*] "$::VCVER" "$anArchIter" ]
382       set aTclLibPath [wokdep:SearchLib "$aTclLibName" "$anArchIter" "$aPath/lib"]
383       set aTkLibPath  [wokdep:SearchLib "$aTkLibName"  "$anArchIter" "$aPath/lib"]
384       if { "$aTclLibPath" != "" && "$aTkLibPath" != "" } {
385         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
386       } else {
387         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}${aTclLibName}.${::SYS_LIB_SUFFIX}' or '${::SYS_LIB_PREFIX}${aTkLibName}.${::SYS_LIB_SUFFIX}' not found (Tcl/Tk)"
388         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
389       }
390     }
391
392     if { "$::tcl_platform(platform)" == "windows" } {
393       set aTclDllPath [wokdep:SearchBin "${aTclLibName}.dll" "$anArchIter"]
394       set aTkDllPath  [wokdep:SearchBin "${aTkLibName}.dll"  "$anArchIter"]
395       if { "$aTclDllPath" == "" || "$aTkDllPath" == "" } {
396         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tcl}*] "$::VCVER" "$anArchIter" ]
397         set aTclDllPath [wokdep:SearchBin "${aTclLibName}.dll" "$anArchIter" "$aPath/bin"]
398         set aTkDllPath  [wokdep:SearchBin "${aTkLibName}.dll"  "$anArchIter" "$aPath/bin"]
399         if { "$aTclDllPath" != "" && "$aTkDllPath" != "" } {
400           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
401         } else {
402           lappend anErrBin$anArchIter "Error: '${aTclLibName}.dll' or '${aTkLibName}.dll' not found (Tcl/Tk)"
403           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
404         }
405       }
406     }
407   }
408
409   return "$isFound"
410 }
411
412 # Search FreeType library placement
413 proc wokdep:SearchFreeType {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
414   upvar $theErrInc   anErrInc
415   upvar $theErrLib32 anErrLib32
416   upvar $theErrLib64 anErrLib64
417   upvar $theErrBin32 anErrBin32
418   upvar $theErrBin64 anErrBin64
419
420   set isFound "true"
421   set aFtBuildPath [wokdep:SearchHeader "ft2build.h"]
422
423   if { "$aFtBuildPath" == "" } {
424     # TODO - use `freetype-config --cflags` instead
425     set aSysFreeType "/usr/include/freetype2"
426     if { [file exists "$aSysFreeType/ft2build.h"] } {
427       lappend ::CSF_OPT_INC "$aSysFreeType"
428     } elseif { [file exists "$aSysFreeType/freetype2/ft2build.h"] } {
429       lappend ::CSF_OPT_INC "$aSysFreeType/freetype2"
430     } else {
431       set aSysFreeType "/usr/X11/include/freetype2"
432       if { [file exists "$aSysFreeType/ft2build.h"] } {
433         lappend ::CSF_OPT_INC "/usr/X11/include"
434         lappend ::CSF_OPT_INC "$aSysFreeType"
435       } else {
436         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freetype}*] "$::VCVER" "$::ARCH" ]
437         if {"$aPath" != ""} {
438           if {[file exists "$aPath/include/ft2build.h"]} {
439             lappend ::CSF_OPT_INC "$aPath/include"
440           } elseif {[file exists "$aPath/include/freetype2/ft2build.h"]} {
441             lappend ::CSF_OPT_INC "$aPath/include/freetype2"
442           }
443         } else {
444           lappend anErrInc "Error: 'freetype.h' not found (FreeType2)"
445           set isFound "false"
446         }
447       }
448     }
449   }
450
451   # parse 'freetype-config --libs'
452   set aConfLibPath ""
453   if { [catch { set aConfLibs [exec freetype-config --libs] } ] == 0 } {
454     foreach aPath [split $aConfLibs " "] {
455       if { [string first "-L" "$aPath"] == 0 } {
456         set aConfLibPath [string range "$aPath" 2 [string length "$aPath"]]
457       }
458     }
459   }
460
461   foreach anArchIter {64 32} {
462     set aFtLibPath [wokdep:SearchLib "freetype" "$anArchIter"]
463     if { "$aFtLibPath" == "" } {
464       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freetype}*] "$::VCVER" "$anArchIter" ]
465       set aFtLibPath [wokdep:SearchLib "freetype" "$anArchIter" "$aPath/lib"]
466       if { "$aFtLibPath" != "" } {
467         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
468       } else {
469         set aFtLibPath [wokdep:SearchLib "freetype" "$anArchIter" "$aConfLibPath"]
470         if { "$aFtLibPath" != "" } {
471           lappend ::CSF_OPT_LIB$anArchIter "$aConfLibPath"
472         } else {
473           lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}freetype.${::SYS_LIB_SUFFIX}' not found (FreeType2)"
474           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
475         }
476       }
477     }
478     if { "$::tcl_platform(platform)" == "windows" } {
479       set aFtDllPath [wokdep:SearchBin "freetype.dll" "$anArchIter"]
480       if { "$aFtDllPath" == "" } {
481         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freetype}*] "$::VCVER" "$anArchIter" ]
482         set aFtDllPath [wokdep:SearchBin "freetype.dll" "$anArchIter" "$aPath/bin"]
483         if { "$aFtDllPath" != "" } {
484           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
485         } else {
486           set aFtDllPath [wokdep:SearchBin "freetype.dll" "$anArchIter" "$aPath/lib"]
487           if { "$aFtDllPath" != "" } {
488             lappend ::CSF_OPT_BIN$anArchIter "$aPath/lib"
489           } else {
490             lappend anErrBin$anArchIter "Error: 'freetype.dll' not found (FreeType2)"
491             if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
492           }
493         }
494       }
495     }
496   }
497
498   return "$isFound"
499 }
500
501 # Search FreeImage library placement
502 proc wokdep:SearchFreeImage {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
503   upvar $theErrInc   anErrInc
504   upvar $theErrLib32 anErrLib32
505   upvar $theErrLib64 anErrLib64
506   upvar $theErrBin32 anErrBin32
507   upvar $theErrBin64 anErrBin64
508
509   # binary distribution has another layout
510   set aFImageDist     "Dist"
511
512   set isFound "true"
513   set aFImageHPath [wokdep:SearchHeader "FreeImage.h"]
514   if { "$aFImageHPath" == "" } {
515     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freeimage}*] "$::VCVER" "$::ARCH" ]
516     if { "$aPath" != "" && [file exists "$aPath/include/FreeImage.h"] } {
517       lappend ::CSF_OPT_INC "$aPath/include"
518     } elseif { "$aPath" != "" && [file exists "$aPath/$aFImageDist/FreeImage.h"] } {
519       lappend ::CSF_OPT_INC "$aPath/$aFImageDist"
520     } else {
521       lappend anErrInc "Error: 'FreeImage.h' not found (FreeImage)"
522       set isFound "false"
523     }
524   }
525
526   foreach anArchIter {64 32} {
527     set aFImageLibPath [wokdep:SearchLib "freeimage"     "$anArchIter"]
528     if { "$aFImageLibPath" == "" } {
529       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freeimage}*] "$::VCVER" "$anArchIter" ]
530       set aFImageLibPath [wokdep:SearchLib "freeimage" "$anArchIter" "$aPath/lib"]
531       if { "$aFImageLibPath" != "" } {
532         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
533       } else {
534         set aFImageLibPath [wokdep:SearchLib "freeimage" "$anArchIter" "$aPath/$aFImageDist"]
535         if { "$aFImageLibPath" != "" } {
536           lappend ::CSF_OPT_LIB$anArchIter "$aPath/$aFImageDist"
537         } else {
538           lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}freeimage.${::SYS_LIB_SUFFIX}' not found (FreeImage)"
539           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
540         }
541       }
542     }
543     if { "$::tcl_platform(platform)" == "windows" } {
544       set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter"]
545       if { "$aFImageDllPath" == "" } {
546         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{freeimage}*] "$::VCVER" "$anArchIter" ]
547         set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/bin"]
548         if { "$aFImageDllPath" != "" } {
549           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
550         } else {
551           set aFImageDllPath [wokdep:SearchBin "freeimage.dll" "$anArchIter" "$aPath/$aFImageDist"]
552           if { "$aFImageDllPath" != "" } {
553             lappend ::CSF_OPT_BIN$anArchIter "$aPath/$aFImageDist"
554           } else {
555             lappend anErrBin$anArchIter "Error: 'freeimage.dll' is not found (FreeImage)"
556             if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
557           }
558         }
559       }
560     }
561   }
562
563   return "$isFound"
564 }
565
566 # Search FFmpeg framework placement
567 proc wokdep:SearchFFmpeg {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
568   upvar $theErrInc   anErrInc
569   upvar $theErrLib32 anErrLib32
570   upvar $theErrLib64 anErrLib64
571   upvar $theErrBin32 anErrBin32
572   upvar $theErrBin64 anErrBin64
573
574   set isFound "true"
575   set aFFmpegHPath [wokdep:SearchHeader "libavutil/avutil.h"]
576   if { "$aFFmpegHPath"  == "" } {
577     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{ffmpeg}*] "$::VCVER" "$::ARCH" ]
578     if { "$aPath" != "" && [file exists "$aPath/include/libavutil/avutil.h"] } {
579       lappend ::CSF_OPT_INC "$aPath/include"
580     } else {
581       lappend anErrInc "Error: 'libavutil/avutil.h' not found (FFmpeg)"
582       set isFound "false"
583     }
584   }
585
586   foreach anArchIter {64 32} {
587     set aFFmpegLibPath [wokdep:SearchLib "avutil" "$anArchIter"]
588     if { "$aFFmpegLibPath" == "" } {
589       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{ffmpeg}*] "$::VCVER" "$anArchIter" ]
590       set aFFmpegLibPath [wokdep:SearchLib "avutil" "$anArchIter" "$aPath/lib"]
591       if { "$aFFmpegLibPath" != "" } {
592         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
593         lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
594       } else {
595         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}avutil.${::SYS_LIB_SUFFIX}' not found (FFmpeg)"
596         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
597       }
598     }
599   }
600
601   return "$isFound"
602 }
603
604 # Search TBB library placement
605 proc wokdep:SearchTBB {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
606   upvar $theErrInc   anErrInc
607   upvar $theErrLib32 anErrLib32
608   upvar $theErrLib64 anErrLib64
609   upvar $theErrBin32 anErrBin32
610   upvar $theErrBin64 anErrBin64
611
612   # keep only two first digits in "vc141"
613   if { ! [regexp {^vc[0-9][0-9]} ${::VCVER} aVcLib] } {
614     set aVcLib ${::VCVER}
615   }
616
617   set isFound "true"
618   set aTbbHPath [wokdep:SearchHeader "tbb/scalable_allocator.h"]
619   if { "$aTbbHPath"  == "" } {
620     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tbb}*] "$::VCVER" "$::ARCH" ]
621     if { "$aPath" != "" && [file exists "$aPath/include/tbb/scalable_allocator.h"] } {
622       lappend ::CSF_OPT_INC "$aPath/include"
623     } else {
624       lappend anErrInc "Error: 'tbb/scalable_allocator.h' not found (Intel TBB)"
625       set isFound "false"
626     }
627   }
628
629   foreach anArchIter {64 32} {
630     set aSubDir "ia32"
631     if { "$anArchIter" == "64"} {
632       set aSubDir "intel64"
633     }
634
635     set aTbbLibPath [wokdep:SearchLib "tbb" "$anArchIter"]
636     if { "$aTbbLibPath" == "" } {
637       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tbb}*] $aVcLib "$anArchIter" ]
638       set aTbbLibPath [wokdep:SearchLib "tbb" "$anArchIter" "$aPath/lib/$aSubDir/$aVcLib"]
639       if { "$aTbbLibPath" == "" } {
640         # Set the path to the TBB library for Linux
641         if { "$::tcl_platform(platform)" != "windows" } {
642           set aSubDir "$aSubDir/cc4.1.0_libc2.4_kernel2.6.16.21"
643         }
644         set aTbbLibPath [wokdep:SearchLib "tbb" "$anArchIter" "$aPath/lib/$aSubDir"]
645         if { "$aTbbLibPath" != "" } {
646           lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib/$aSubDir"
647         }
648       } else {
649         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib/$aSubDir/$aVcLib"
650       }
651       if { "$aTbbLibPath" == "" } {
652         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}tbb.${::SYS_LIB_SUFFIX}' not found (Intel TBB)"
653         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
654       }
655     }
656     if { "$::tcl_platform(platform)" == "windows" } {
657       set aTbbDllPath [wokdep:SearchBin "tbb.dll" "$anArchIter"]
658       if { "$aTbbDllPath" == "" } {
659         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{tbb}*] $aVcLib "$anArchIter" ]
660         set aTbbDllPath [wokdep:SearchBin "tbb.dll" "$anArchIter" "$aPath/bin/$aSubDir/$aVcLib"]
661         if { "$aTbbDllPath" != "" } {
662           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin/$aSubDir/$aVcLib"
663         } else {
664           lappend anErrBin$anArchIter "Error: 'tbb.dll' not found (Intel TBB)"
665           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
666         }
667       }
668     }
669   }
670
671   return "$isFound"
672 }
673
674 # Search OpenCL library placement
675 proc wokdep:SearchOpenCL {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
676   upvar $theErrInc   anErrInc
677   upvar $theErrLib32 anErrLib32
678   upvar $theErrLib64 anErrLib64
679   upvar $theErrBin32 anErrBin32
680   upvar $theErrBin64 anErrBin64
681
682   set isFound "true"
683   if { "$::tcl_platform(os)" == "Darwin" } {
684     # OpenCL framework available since Mac OS X 16
685     return "$isFound"
686   }
687
688   set aCLHPath [wokdep:SearchHeader "CL/cl_gl.h"]
689   if { "$aCLHPath"  == "" } {
690     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{OpenCL}*] "$::VCVER" "$::ARCH" ]
691     if { "$aPath" != "" && [file exists "$aPath/include/CL/cl_gl.h"] } {
692       lappend ::CSF_OPT_INC "$aPath/include"
693     } else {
694       lappend anErrInc "Error: 'CL/cl_gl.h' not found (OpenCL)"
695       set isFound "false"
696     }
697   }
698
699   foreach anArchIter {64 32} {
700     set aCLLibPath [wokdep:SearchLib "OpenCL" "$anArchIter"]
701     if { "$aCLLibPath" == "" } {
702       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{OpenCL}*] "$::VCVER" "$anArchIter" ]
703       set aCLLibPath [wokdep:SearchLib "OpenCL" "$anArchIter" "$aPath/lib"]
704       if { "$aCLLibPath" != "" } {
705         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
706       } else {
707         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}OpenCL.${::SYS_LIB_SUFFIX}' not found (OpenCL)"
708         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
709       }
710     }
711   }
712
713   return "$isFound"
714 }
715
716 # Search EGL library placement
717 proc wokdep:SearchEGL {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
718   upvar $theErrInc   anErrInc
719   upvar $theErrLib32 anErrLib32
720   upvar $theErrLib64 anErrLib64
721   upvar $theErrBin32 anErrBin32
722   upvar $theErrBin64 anErrBin64
723
724   set isFound "true"
725   set aHeaderPath [wokdep:SearchHeader "EGL/egl.h"]
726   if { "$aHeaderPath"  == "" } {
727     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{EGL}*] "$::VCVER" "$::ARCH" ]
728     if { "$aPath" == "" || ![file exists "$aPath/include/EGL/egl.h"] } {
729       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$::ARCH" ]
730     }
731
732     if { "$aPath" != "" && [file exists "$aPath/include/EGL/egl.h"] } {
733       lappend ::CSF_OPT_INC "$aPath/include"
734     } else {
735       lappend anErrInc "Error: 'EGL/egl.h' not found (EGL)"
736       set isFound "false"
737     }
738   }
739
740   set aLibName "EGL"
741   if { "$::tcl_platform(platform)" == "windows" } {
742     # awkward exception
743     set aLibName "libEGL"
744   }
745
746   foreach anArchIter {64 32} {
747     set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter"]
748     if { "$aLibPath" == "" } {
749       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{EGL}*] "$::VCVER" "$anArchIter" ]
750       set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter" "$aPath/lib"]
751       if { "$aLibPath" == "" } {
752         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$anArchIter" ]
753         set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter" "$aPath/lib"]
754       }
755
756       if { "$aLibPath" != "" } {
757         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
758       } else {
759         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}${aLibName}.${::SYS_LIB_SUFFIX}' not found (EGL)"
760         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
761       }
762     }
763
764     if { "$::tcl_platform(platform)" == "windows" } {
765       set aDllPath [wokdep:SearchBin "libEGL.dll" "$anArchIter"]
766       if { "$aDllPath" == "" } {
767         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{EGL}*] "$::VCVER" "$anArchIter" ]
768         set aDllPath [wokdep:SearchBin "libEGL.dll" "$anArchIter" "$aPath/bin"]
769         if { "$aDllPath" == "" } {
770           set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$anArchIter" ]
771           set aDllPath [wokdep:SearchBin "libEGL.dll" "$anArchIter" "$aPath/bin"]
772         }
773
774         if { "$aDllPath" != "" } {
775           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
776         } else {
777           lappend anErrBin$anArchIter "Error: 'libEGL.dll' not found (EGL)"
778           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
779         }
780       }
781     }
782   }
783
784   return "$isFound"
785 }
786
787 # Search OpenGL ES 2.0 library placement
788 proc wokdep:SearchGLES {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
789   upvar $theErrInc   anErrInc
790   upvar $theErrLib32 anErrLib32
791   upvar $theErrLib64 anErrLib64
792   upvar $theErrBin32 anErrBin32
793   upvar $theErrBin64 anErrBin64
794
795   set isFound "true"
796   set aHeaderPath [wokdep:SearchHeader "GLES2/gl2.h"]
797   if { "$aHeaderPath"  == "" } {
798     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{GLES}*] "$::VCVER" "$::ARCH" ]
799     if { "$aPath" == "" || ![file exists "$aPath/include/GLES2/gl2.h"] } {
800       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$::ARCH" ]
801     }
802
803     if { "$aPath" != "" && [file exists "$aPath/include/GLES2/gl2.h"] } {
804       lappend ::CSF_OPT_INC "$aPath/include"
805     } else {
806       lappend anErrInc "Error: 'GLES2/gl2.h' not found (OpenGL ES 2.0)"
807       set isFound "false"
808     }
809   }
810
811   set aLibName "GLESv2"
812   if { "$::tcl_platform(platform)" == "windows" } {
813     # awkward exception
814     set aLibName "libGLESv2"
815   }
816
817   foreach anArchIter {64 32} {
818     set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter"]
819     if { "$aLibPath" == "" } {
820       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{GLES}*] "$::VCVER" "$anArchIter" ]
821       set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter" "$aPath/lib"]
822       if { "$aLibPath" == "" } {
823         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$anArchIter" ]
824         set aLibPath [wokdep:SearchLib "$aLibName" "$anArchIter" "$aPath/lib"]
825       }
826
827       if { "$aLibPath" != "" } {
828         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
829       } else {
830         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}${aLibName}.${::SYS_LIB_SUFFIX}' not found (OpenGL ES 2.0)"
831         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
832       }
833     }
834
835     if { "$::tcl_platform(platform)" == "windows" } {
836       set aDllPath [wokdep:SearchBin "libGLESv2.dll" "$anArchIter"]
837       if { "$aDllPath" == "" } {
838         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{EGL}*] "$::VCVER" "$anArchIter" ]
839         set aDllPath [wokdep:SearchBin "libGLESv2.dll" "$anArchIter" "$aPath/bin"]
840         if { "$aDllPath" == "" } {
841           set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{angle}*] "$::VCVER" "$anArchIter" ]
842           set aDllPath [wokdep:SearchBin "libGLESv2.dll" "$anArchIter" "$aPath/bin"]
843         }
844
845         if { "$aDllPath" != "" } {
846           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
847         } else {
848           lappend anErrBin$anArchIter "Error: 'libGLESv2.dll' not found (OpenGL ES 2.0)"
849           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
850         }
851       }
852     }
853   }
854
855   return "$isFound"
856 }
857
858 # Auxiliary function, gets VTK version to set default search directory
859 proc wokdep:VtkVersion { thePath } {
860   set aResult "6.1"
861
862   set aVtkRoot [lindex [regexp -all -inline {[0-9.]*} [file tail $thePath]] 0]
863   if { "$aVtkRoot" != "" } {
864     set aVtkRoot [regexp -inline {[0-9]*.[0-9]*} $aVtkRoot]
865     if { "$aVtkRoot" != "" } {
866     set aResult $aVtkRoot
867     }
868   }
869
870   return $aResult
871 }
872
873 # Search VTK library placement
874 proc wokdep:SearchVTK {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
875   upvar $theErrInc   anErrInc
876   upvar $theErrLib32 anErrLib32
877   upvar $theErrLib64 anErrLib64
878   upvar $theErrBin32 anErrBin32
879   upvar $theErrBin64 anErrBin64
880
881   set isFound "true"
882   
883   set aVtkPath ""
884   set aVtkIncPath [wokdep:SearchHeader "vtkConfigure.h"]
885   set aVtkVer [wokdep:VtkVersion $aVtkIncPath]
886   if { "$aVtkIncPath" == ""} {
887     set aPathList [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{VTK}*]
888     set aVtkPath [wokdep:Preferred "$aPathList" "$::VCVER" "$::ARCH" ]
889     if { "$aVtkPath" != "" && [file exists "$aVtkPath/include/vtk-[wokdep:VtkVersion $aVtkPath]/vtkConfigure.h"]} { 
890       set aVtkVer [wokdep:VtkVersion $aVtkPath]
891       lappend ::CSF_OPT_INC "$aVtkPath/include/vtk-[wokdep:VtkVersion $aVtkPath]"
892     } else { # try to search in all found paths
893       set isFound "false"
894       foreach anIt $aPathList {
895         if { [file exists "$anIt/include/vtk-[wokdep:VtkVersion $anIt]/vtkConfigure.h"] } {
896           set aVtkPath $anIt
897           set aVtkVer [wokdep:VtkVersion $aVtkPath]
898           lappend ::CSF_OPT_INC "$anIt/include/vtk-[wokdep:VtkVersion $anIt]"
899           set isFound "true"
900           break
901         }
902       }
903
904       # Bad case: we do not found vtkConfigure.h in all paths.
905       if { "$isFound" == "false"} {
906         lappend anErrInc "Error: 'vtkConfigure.h' not found (VTK)"
907         set isFound "false"
908       }
909     }
910   }
911
912   set aVtkLibPath ""
913   foreach anArchIter {64 32} {
914     set aVtkLibPath [wokdep:SearchLib "vtkCommonCore-$aVtkVer" "$anArchIter"]
915     if { "$aVtkLibPath" == "" } {
916       set aPathList [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{VTK}*]
917       set aPath [wokdep:Preferred $aPathList "$::VCVER" "$anArchIter" ]
918       set aVtkLibPath [wokdep:SearchLib "vtkCommonCore-$aVtkVer" "$anArchIter" "$aPath/lib"]
919       if { "$aVtkLibPath" != "" } {
920         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
921       } else {
922         set aPath [wokdep:SearchLib "vtkCommonCore-$aVtkVer" "$anArchIter" "$aVtkPath/lib"]
923         if { "$aPath" != "" } {
924           set aLibPath $aVtkIncPath
925           lappend ::CSF_OPT_LIB$anArchIter "$aLibPath/lib"
926         } else {
927           # The last chance: search /lib directory in all found paths
928           foreach anIt $aPathList {
929             set aVtkLibPath [wokdep:SearchLib "vtkCommonCore-$aVtkVer" "$anArchIter" "$anIt/lib"]
930             if { "$aVtkLibPath" != ""} {
931               lappend ::CSF_OPT_LIB$anArchIter "$anIt/lib"
932               break
933             }
934           }
935           if { "$aVtkLibPath" == "" } {
936             lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}vtkCommonCore-${aVtkVer}\.${::SYS_LIB_SUFFIX}' not found (VTK)"
937             if { "$::ARCH" == "$anArchIter" } {
938               set isFound "false"
939             }
940           }
941         }
942       }
943     }
944   }
945   
946     # Search binary path
947     if { "$::tcl_platform(platform)" == "windows" } {
948       foreach anArchIter {64 32} {
949         set aVtkBinPath [wokdep:SearchBin "vtkCommonCore-${aVtkVer}.dll" "$anArchIter"]
950         if { "$aVtkBinPath" == "" } {
951           set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{VTK}*] "$::VCVER" "$anArchIter" ]
952           set aVtkBinPath [wokdep:SearchBin "vtkCommonCore-${aVtkVer}.dll" "$anArchIter" "$aPath/bin"]
953           if { "$aVtkBinPath" != "" } { lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
954           } else {
955             set aVtkBinPath [wokdep:SearchBin "vtkCommonCore-${aVtkVer}.dll" "$anArchIter" "$aPath/lib"]
956             if { "$aVtkBinPath" != "" } { lappend ::CSF_OPT_BIN$anArchIter "$aPath/lib" } 
957           }
958         }
959       }
960       
961       # We didn't find preferred binary path => search through inc path or among all available VTK directories
962       if { "$aVtkBinPath" == "" } {
963         # Try to find in lib path
964         set aPath [wokdep:SearchBin "vtkCommonCore-${aVtkVer}.dll" "$anArchIter" "$aVtkLibPath/bin"]
965         if { "$aPath" != "" } { lappend ::CSF_OPT_BIN$anArchIter "$aVtkLibPath/bin"
966         } elseif { [wokdep:SearchBin "vtkCommonCore-${aVtkVer}.dll" "$anArchIter" "$aVtkLibPath/lib"] != "" } {
967           lappend ::CSF_OPT_BIN$anArchIter "$aVtkLibPath/lib"
968         } else {
969            lappend anErrBin$anArchIter "Error: 'vtkCommonCore-${aVtkVer}.dll' not found (VTK)"
970            set isFound "false"
971         }
972       }
973     }
974
975   return "$isFound"
976 }
977
978 # Search Qt4 libraries placement
979 proc wokdep:SearchQt4 {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
980   upvar $theErrInc   anErrInc
981   upvar $theErrLib32 anErrLib32
982   upvar $theErrLib64 anErrLib64
983   upvar $theErrBin32 anErrBin32
984   upvar $theErrBin64 anErrBin64
985
986   set isFound "true"
987   set aQMsgBoxHPath [wokdep:SearchHeader "QtGui/qmessagebox.h"]
988   if { "$aQMsgBoxHPath" == "" } {
989     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{qt4}*] "$::VCVER" "$::ARCH" ]
990     if { "$aPath" != "" && [file exists "$aPath/include/QtGui/qmessagebox.h"] } {
991       lappend ::CSF_OPT_INC "$aPath/include"
992       lappend ::CSF_OPT_INC "$aPath/include/Qt"
993       lappend ::CSF_OPT_INC "$aPath/include/QtGui"
994       lappend ::CSF_OPT_INC "$aPath/include/QtCore"
995     } else {
996       if { [file exists "/usr/include/qt4/QtGui/qmessagebox.h"] } {
997         lappend ::CSF_OPT_INC "/usr/include/qt4"
998         lappend ::CSF_OPT_INC "/usr/include/qt4/Qt"
999         lappend ::CSF_OPT_INC "/usr/include/qt4/QtGui"
1000         lappend ::CSF_OPT_INC "/usr/include/qt4/QtCore"
1001       } else {
1002         lappend anErrInc "Error: 'QtGui/qmessagebox.h' not found (Qt4)"
1003         set isFound "false"
1004       }
1005     }
1006   }
1007
1008   set aQtGuiLibName "QtGui"
1009   if { "$::tcl_platform(platform)" == "windows" } {
1010     set aQtGuiLibName "QtGui4"
1011   }
1012
1013   foreach anArchIter {64 32} {
1014     set aQMsgBoxLibPath [wokdep:SearchLib "${aQtGuiLibName}" "$anArchIter"]
1015     if { "$aQMsgBoxLibPath" == "" } {
1016       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{qt4}*] "$::VCVER" "$anArchIter" ]
1017       set aQMsgBoxLibPath [wokdep:SearchLib "${aQtGuiLibName}" "$anArchIter" "$aPath/lib"]
1018       if { "$aQMsgBoxLibPath" != "" } {
1019         lappend ::CSF_OPT_LIB$anArchIter "$aPath/lib"
1020       } else {
1021         lappend anErrLib$anArchIter "Error: '${::SYS_LIB_PREFIX}${aQtGuiLibName}.${::SYS_LIB_SUFFIX}' not found (Qt4)"
1022         if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
1023       }
1024     }
1025     if { "$::tcl_platform(platform)" == "windows" } {
1026       set aQMsgBoxDllPath [wokdep:SearchBin "QtGui4.dll" "$anArchIter"]
1027       if { "$aQMsgBoxDllPath" == "" } {
1028         set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{qt4}*] "$::VCVER" "$anArchIter" ]
1029         set aQMsgBoxDllPath [wokdep:SearchBin "QtGui4.dll" "$anArchIter" "$aPath/bin"]
1030         if { "$aQMsgBoxDllPath" != "" } {
1031           lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
1032         } else {
1033           lappend anErrBin$anArchIter "Error: 'QtGui4.dll' not found (Qt4)"
1034           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
1035         }
1036       }
1037     }
1038   }
1039
1040   return "$isFound"
1041 }
1042
1043 # Search JDK placement
1044 proc wokdep:SearchJDK {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
1045   upvar $theErrInc   anErrInc
1046   upvar $theErrLib32 anErrLib32
1047   upvar $theErrLib64 anErrLib64
1048   upvar $theErrBin32 anErrBin32
1049   upvar $theErrBin64 anErrBin64
1050
1051   set isFound "true"
1052   set aJniHPath   [wokdep:SearchHeader "jni.h"]
1053   set aJniMdHPath [wokdep:SearchHeader "jni_md.h"]
1054   if { "$aJniHPath" == "" || "$aJniMdHPath" == "" } {
1055     set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{jdk,java}*] "$::VCVER" "$::ARCH" ]
1056     if { "$aPath" != "" && [file exists "$aPath/include/jni.h"] } {
1057       lappend ::CSF_OPT_INC "$aPath/include"
1058       if { "$::tcl_platform(platform)" == "windows" } {
1059         lappend ::CSF_OPT_INC "$aPath/include/win32"
1060       } elseif { [file exists "$aPath/include/linux"] } {
1061         lappend ::CSF_OPT_INC "$aPath/include/linux"
1062       }
1063     } else {
1064       if { [file exists "/System/Library/Frameworks/JavaVM.framework/Home/include/jni.h"] } {
1065         lappend ::CSF_OPT_INC "/System/Library/Frameworks/JavaVM.framework/Home/include"
1066       } else {
1067         lappend anErrInc "Error: 'jni.h' or 'jni_md.h' not found (JDK)"
1068         set isFound "false"
1069       }
1070     }
1071   }
1072
1073   foreach anArchIter {64 32} {
1074     set aJavacPath [wokdep:SearchBin "javac${::SYS_EXE_SUFFIX}" "$anArchIter"]
1075     if { "$aJavacPath" == "" } {
1076       set aPath [wokdep:Preferred [glob -nocomplain -directory "$::PRODUCTS_PATH" -type d *{jdk,java}*] "$::VCVER" "$anArchIter" ]
1077       set aJavacPath [wokdep:SearchBin "javac${::SYS_EXE_SUFFIX}" "$anArchIter" "$aPath/bin"]
1078       if { "$aJavacPath" != "" } {
1079         lappend ::CSF_OPT_BIN$anArchIter "$aPath/bin"
1080       } else {
1081         if { "$::ARCH" == "$anArchIter" && [file exists "/System/Library/Frameworks/JavaVM.framework/Home/bin/javac${::SYS_EXE_SUFFIX}"] } {
1082           lappend ::CSF_OPT_BIN$anArchIter "/System/Library/Frameworks/JavaVM.framework/Home/bin"
1083         } else {
1084           lappend anErrBin$anArchIter "Error: 'javac${::SYS_EXE_SUFFIX}' not found (JDK)"
1085           if { "$::ARCH" == "$anArchIter"} { set isFound "false" }
1086         }
1087       }
1088     }
1089   }
1090
1091   return "$isFound"
1092 }
1093
1094 # Search X11 libraries placement
1095 proc wokdep:SearchX11 {theErrInc theErrLib32 theErrLib64 theErrBin32 theErrBin64} {
1096   upvar $theErrInc   anErrInc
1097   upvar $theErrLib32 anErrLib32
1098   upvar $theErrLib64 anErrLib64
1099   upvar $theErrBin32 anErrBin32
1100   upvar $theErrBin64 anErrBin64
1101
1102   set isFound "true"
1103   if { "$::tcl_platform(platform)" == "windows" || ( "$::tcl_platform(os)" == "Darwin" && "$::MACOSX_USE_GLX" != "true" ) } {
1104     return "$isFound"
1105   }
1106
1107   set aXmuLibPath [wokdep:SearchLib "Xmu" "$::ARCH"]
1108   if { "$aXmuLibPath" == "" } {
1109     set aXmuLibPath [wokdep:SearchLib "Xmu" "$::ARCH" "/usr/X11/lib"]
1110     if { "$aXmuLibPath" != "" } {
1111       #lappend ::CSF_OPT_LIB$::ARCH "/usr/X11/lib"
1112     } else {
1113       lappend anErrLib$::ARCH "Error: '${::SYS_LIB_PREFIX}Xmu.${::SYS_LIB_SUFFIX}' not found (X11)"
1114       set isFound "false"
1115     }
1116   }
1117
1118   return "$isFound"
1119 }
1120
1121 # Generate (override) custom environment file
1122 proc wokdep:SaveCustom {} {
1123   if { "$::tcl_platform(platform)" == "windows" } {
1124     set aCustomFilePath "./custom.bat"
1125     set aFile [open $aCustomFilePath "w"]
1126     puts $aFile "@echo off"
1127     puts $aFile "rem This environment file was generated by wok_depsgui.tcl script at [clock format [clock seconds] -format "%Y.%m.%d %H:%M"]"
1128
1129     puts $aFile ""
1130     puts $aFile "set VCVER=$::VCVER"
1131     puts $aFile "set ARCH=$::ARCH"
1132     puts $aFile "set VCVARS=$::VCVARS"
1133     puts $aFile "set SHORTCUT_HEADERS=$::SHORTCUT_HEADERS"
1134
1135     puts $aFile ""
1136     puts $aFile "set \"PRODUCTS_PATH=$::PRODUCTS_PATH\""
1137
1138     puts $aFile ""
1139     puts $aFile "rem Optional 3rd-parties switches"
1140     foreach anEnvIter $::THE_ENV_VARIABLES {
1141       set aName ${anEnvIter}
1142       set aValue [set ::${anEnvIter}]
1143       if { "$aValue" != "" } {
1144         puts $aFile "set ${aName}=$aValue"
1145       }
1146     }
1147
1148     set aStringInc [join $::CSF_OPT_INC $::SYS_PATH_SPLITTER]
1149     puts $aFile ""
1150     puts $aFile "rem Additional headers search paths"
1151     puts $aFile "set \"CSF_OPT_INC=$aStringInc\""
1152
1153     set aStringLib32 [join $::CSF_OPT_LIB32 $::SYS_PATH_SPLITTER]
1154     puts $aFile ""
1155     puts $aFile "rem Additional libraries (32-bit) search paths"
1156     puts $aFile "set \"CSF_OPT_LIB32=$aStringLib32\""
1157
1158     set aStringLib64 [join $::CSF_OPT_LIB64 $::SYS_PATH_SPLITTER]
1159     puts $aFile ""
1160     puts $aFile "rem Additional libraries (64-bit) search paths"
1161     puts $aFile "set \"CSF_OPT_LIB64=$aStringLib64\""
1162
1163     set aStringBin32 [join $::CSF_OPT_BIN32 $::SYS_PATH_SPLITTER]
1164     puts $aFile ""
1165     puts $aFile "rem Additional (32-bit) search paths"
1166     puts $aFile "set \"CSF_OPT_BIN32=$aStringBin32\""
1167
1168     set aStringBin64 [join $::CSF_OPT_BIN64 $::SYS_PATH_SPLITTER]
1169     puts $aFile ""
1170     puts $aFile "rem Additional (64-bit) search paths"
1171     puts $aFile "set \"CSF_OPT_BIN64=$aStringBin64\""
1172
1173     close $aFile
1174   } else {
1175     set aCustomFilePath "./custom.sh"
1176     set aFile [open $aCustomFilePath "w"]
1177     puts $aFile "#!/bin/bash"
1178     puts $aFile "# This environment file was generated by wok_depsgui.tcl script at [clock format [clock seconds] -format "%Y.%m.%d %H:%M"]"
1179
1180     puts $aFile ""
1181     puts $aFile "export ARCH=$::ARCH"
1182     puts $aFile "export SHORTCUT_HEADERS=$::SHORTCUT_HEADERS"
1183
1184     puts $aFile ""
1185     puts $aFile "export PRODUCTS_PATH=\"$::PRODUCTS_PATH\""
1186
1187     puts $aFile ""
1188     puts $aFile "# Optional 3rd-parties switches"
1189     foreach anEnvIter $::THE_ENV_VARIABLES {
1190       set aName ${anEnvIter}
1191       set aValue [set ::${anEnvIter}]
1192       if { "$aValue" != "" } {
1193         puts $aFile "export ${aName}=${aValue}"
1194       }
1195     }
1196
1197     set aStringInc [join $::CSF_OPT_INC $::SYS_PATH_SPLITTER]
1198     puts $aFile ""
1199     puts $aFile "# Additional headers search paths"
1200     puts $aFile "export CSF_OPT_INC=\"$aStringInc\""
1201
1202     set aStringLib$::ARCH [join [set ::CSF_OPT_LIB$::ARCH] $::SYS_PATH_SPLITTER]
1203     puts $aFile ""
1204     puts $aFile "# Additional libraries ($::ARCH-bit) search paths"
1205     puts $aFile "export CSF_OPT_LIB$::ARCH=\"[set aStringLib$::ARCH]\""
1206
1207     set aStringBin$::ARCH [join [set ::CSF_OPT_BIN$::ARCH] $::SYS_PATH_SPLITTER]
1208     puts $aFile ""
1209     puts $aFile "# Additional ($::ARCH-bit) search paths"
1210     puts $aFile "export CSF_OPT_BIN$::ARCH=\"[set aStringBin$::ARCH]\""
1211
1212     close $aFile
1213   }
1214
1215   puts "Configuration saved to file '$aCustomFilePath'"
1216 }