0026467: Configuration, genproj.tcl - restore generation of Code::Blocks and XCode...
[occt.git] / adm / genproj.tcl
1 # =======================================================================
2 # This script generates project files for different IDEs:
3 #      "vc7" "vc8" "vc9" "vc10" "vc11" "vc12" "cbp" "amk" "xcd"
4 #
5 # Example:
6 #      genproj -path=D:/occt -target=vc10
7 #      genproj -target=xcd -ios -static
8 # =======================================================================
9
10 set path ""
11 set fBranch ""
12 switch -exact -- "$tcl_platform(platform)" {
13   "windows" {set targetStation "wnt"}
14   "unix"    {set targetStation "lin"}
15 }
16
17 switch -exact -- "$tcl_platform(os)" {
18   "Darwin"  {set targetStation "mac"}
19 }
20
21 source "./adm/genconfdeps.tcl"
22
23 proc _get_options { platform type branch } {
24   global path
25   set res ""
26   if {[file exists "$path/adm/CMPLRS"]} {
27     set fd [open "$path/adm/CMPLRS" rb]
28     set opts [split [read $fd] "\n"]
29     close $fd
30     foreach line $opts {
31       if {[regexp "^${platform} ${type} ${branch} (.+)$" $line dummy res]} {
32         while {[regexp {\(([^\(\)]+) ([^\(\)]+) ([^\(\)]+)\)(.+)} $res dummy p t b oldres]} {
33           set res "[_get_options $p $t $b] $oldres"
34         }
35       }
36     }
37   }
38   return $res
39 }
40
41 proc _get_type { name } {
42   global path
43   if {[file exists "$path/adm/UDLIST"]} {
44     set fd [open "$path/adm/UDLIST" rb]
45     set UDLIST [split [read $fd] "\n"]
46     close $fd
47     foreach uitem $UDLIST {
48       set line [split $uitem]
49       if {[lindex $line 1] == "$name"} {
50         return [lindex $line 0]
51       }
52     }
53   }
54   return ""
55 }
56
57 proc _get_used_files { pk {inc true} {src true} } {
58   global path
59   set type [_get_type $pk]
60   set lret {}
61   set pk_path  "$path/src/$pk"
62   set FILES_path "$path/src/$pk/FILES"
63   set FILES {}
64   if {[file exists $FILES_path]} {
65     set fd [open $FILES_path rb]
66     set FILES [split [read $fd] "\n"]
67     close $fd
68   }
69   set FILES [lsearch -inline -all -not -exact $FILES ""]
70
71   set index -1
72   foreach line $FILES {
73     incr index
74     if {$inc && ([regexp {([^:\s]*\.[hgl]xx)$} $line dummy name] || [regexp {([^:\s]*\.h)$} $line dummy name]) && [file exists $pk_path/$name]} {
75       lappend lret "pubinclude $name $pk_path/$name"
76       continue
77     }
78     if {[regexp {:} $line]} {
79       regexp {[^:]*:+([^\s]*)} $line dummy line
80     }
81     regexp {([^\s]*)} $line dummy line
82     if {$src && [file exists $pk_path/$line]} {
83       lappend lret "source $line $pk_path/$line"
84     }
85   }
86   return $lret
87 }
88
89 # Wrapper-function to generate VS project files
90 proc genproj { args } {
91   global path targetStation
92   set aSupportedTargets { "vc7" "vc8" "vc9" "vc10" "vc11" "vc12" "cbp" "amk" "xcd" }
93   set anArgs $args
94
95   # Setting default IDE.
96   set anTarget ""
97   switch -exact -- "$targetStation" {
98     "wnt"   {set anTarget "$::env(VCVER)"}
99     "lin"   {set anTarget "amk"}
100     "mac"   {set anTarget "xcd"}
101   }
102
103   set isTargetDefault true
104   if { [set anIndex [lsearch -nocase $anArgs -target=*]] != -1 } {
105     regsub -nocase "\\-target=" [lindex $anArgs $anIndex] "" anTarget
106     set anArgs [removeAllOccurrencesOf -target=* $anArgs]
107     set isTargetDefault false
108   }
109
110   if { [set anIndex [lsearch -nocase $anArgs -path=*]] != -1} {
111     regsub -nocase "\\-path=" [lindex $anArgs $anIndex] "" path
112     set anArgs [removeAllOccurrencesOf -path=* $anArgs]
113     puts "Starting work with \"$path\""
114   }
115
116   if { [llength $anArgs] == 0 && $isTargetDefault == true } {
117     puts "the default \'$anTarget\' target has been applied"
118   }
119
120   set isHelpRequire false
121   if { [lsearch -nocase $anArgs -h] != -1} {
122     set anArgs [removeAllOccurrencesOf -h $anArgs]
123     set isHelpRequire true
124   }
125
126   if {$path == ""} {
127     set isHelpRequire true
128   }
129
130   set aLibType "dynamic"
131   if { [lsearch -nocase $anArgs "-static"] != -1} {
132     set anArgs [removeAllOccurrencesOf "-static" $anArgs]
133     set aLibType "static"
134     puts "static build has been selected"
135   } elseif { [lsearch -nocase $anArgs "-dynamic"] != -1} {
136     set anArgs [removeAllOccurrencesOf "-dynamic" $anArgs]
137     set aLibType "dynamic"
138     puts "dynamic build has been selected"
139   }
140
141   set aPlatform ""
142   if { [lsearch -nocase $anArgs "-ios"] != -1} {
143     set anArgs [removeAllOccurrencesOf "-ios" $anArgs]
144     set aPlatform "ios"
145   }
146
147   if { [lsearch -nocase $aSupportedTargets $anTarget] == -1} {
148     puts "the \'$anTarget\' is wrong TARGET"
149     set isHelpRequire true
150   }
151
152   if {[llength $anArgs] > 0} {
153     set isHelpRequire true
154
155     foreach anArg $anArgs {
156       puts "genproj: unrecognized option \'$anArg\'"
157     }
158   }
159
160   if {  $isHelpRequire == true } {
161     puts "usage: genproj \[ -target=<TARGET> \] \[ -path=<PATH> \]
162
163     PATH: 
164       path to the project
165
166     TARGET:
167       vc8   -  Visual Studio 2005
168       vc9   -  Visual Studio 2008
169       vc10  -  Visual Studio 2010
170       vc11  -  Visual Studio 2012
171       vc12  -  Visual Studio 2013
172       cbp   -  CodeBlocks
173       xcd   -  XCode
174       amk   -  AutoMake"
175       return
176   }
177
178   if {!$isTargetDefault} {
179     puts "the \'$anTarget\' target has been applied"
180   }
181   
182   if {"$anTarget" == "amk"} {
183     set targetStation "lin"
184   }
185   set anAdmPath "$path/adm"
186
187   OS:MKPRC "$anAdmPath" "$anTarget" "$aLibType" "$aPlatform"
188
189   genprojbat "$anAdmPath" "$anTarget"
190 }
191
192 proc genprojbat {thePath theIDE} {
193   global path
194   
195   set anOsIncPath "$path/src/OS"
196   set anOsRootPath "$path"
197
198   set aTargetPlatform "lin"
199   if { "$::tcl_platform(platform)" == "windows" } {
200     set aTargetPlatform "wnt"
201   }
202   
203   if {[regexp {(vc)[0-9]*$} $theIDE] == 1} {
204     set aTargetPlatform wnt
205   } elseif {"$theIDE" == "amk"} {
206     set aTargetPlatform lin
207   } elseif {"$theIDE" == "xcd"} {
208     set aTargetPlatform mac
209   }
210
211   set aTargetPlatformExt sh
212   if { "$aTargetPlatform" == "wnt" } {
213     set aTargetPlatformExt bat
214   }
215
216   set aBox [file normalize "$thePath/.."]
217
218   if {"$theIDE" != "cmake"} {
219     set anEnvTmplFile [open "$path/adm/templates/env.${aTargetPlatformExt}" "r"]
220     set anEnvTmpl [read $anEnvTmplFile]
221     close $anEnvTmplFile
222
223     set aCasRoot ""
224     if { [file normalize "$anOsRootPath"] != "$aBox" } {
225       set aCasRoot [relativePath "$aBox" "$anOsRootPath"]
226     }
227     set anOsIncPath [relativePath "$aBox" "$anOsRootPath"]
228
229     regsub -all -- {__CASROOT__}   $anEnvTmpl "$aCasRoot" anEnvTmpl
230
231     set anEnvFile [open "$aBox/env.${aTargetPlatformExt}" "w"]
232     puts $anEnvFile $anEnvTmpl
233     close $anEnvFile
234
235     file copy -force -- "$path/adm/templates/draw.${aTargetPlatformExt}" "$aBox/draw.${aTargetPlatformExt}"
236   }
237
238   if {[regexp {(vc)[0-9]*$} $theIDE] == 1} {
239     file copy -force -- "$path/adm/templates/msvc.bat" "$aBox/msvc.bat"
240   } else {
241     switch -exact -- "$theIDE" {
242       "cbp"   { file copy -force -- "$path/adm/templates/codeblocks.sh" "$aBox/codeblocks.sh" }
243       "xcd"   { file copy -force -- "$path/adm/templates/xcode.sh"      "$aBox/xcode.sh" }
244     }
245   }
246 }
247
248 ###### MSVC #############################################################33
249 proc removeAllOccurrencesOf { theObject theList } {
250   set aSortIndices [lsort -decreasing [lsearch -all -nocase $theList $theObject]]
251   foreach anIndex $aSortIndices {
252     set theList [lreplace $theList $anIndex $anIndex]
253   }
254   return $theList
255 }
256
257 set aTKNullKey "TKNull"
258 set THE_GUIDS_LIST($aTKNullKey) "{00000000-0000-0000-0000-000000000000}"
259
260 # Entry function to generate project files and solutions for IDE
261 proc OS:MKPRC { {theOutDir {}} {theIDE ""} {theLibType "dynamic"} {thePlatform ""} } {
262   global path targetStation
263   set aSupportedIDE { "vc7" "vc8" "vc9" "vc10" "vc11" "vc12" "cbp" "amk" "xcd" }
264
265   if { [lsearch $aSupportedIDE $theIDE] < 0 } {
266     puts stderr "WOK does not support generation of project files for the selected IDE: $theIDE\nSupported IDEs: [join ${aSupportedIDE} " "]"
267     return
268   }
269   
270   set anOutRoot $theOutDir
271   if { $anOutRoot == "" } {
272     error "Error : \"theOutDir\" is not initialized"
273   }
274
275   # Create output directory
276   set aWokStation "$targetStation"
277
278   if { [lsearch -exact {vc7 vc8 vc9 vc10 vc11 vc12} $theIDE] != -1 } {
279     set aWokStation "msvc"
280   }
281
282   set anOutDir "${anOutRoot}/${aWokStation}/${theIDE}"
283
284   # read map of already generated GUIDs
285   set aGuidsFilePath [file join $anOutDir "wok_${theIDE}_guids.txt"]
286   if [file exists "$aGuidsFilePath"] {
287     set aFileIn [open "$aGuidsFilePath" r]
288     set aFileDataRaw [read $aFileIn]
289     close $aFileIn
290     set aFileData [split $aFileDataRaw "\n"]
291     foreach aLine $aFileData {
292       set aLineSplt [split $aLine "="]
293       if { [llength $aLineSplt] == 2 } {
294         set ::THE_GUIDS_LIST([lindex $aLineSplt 0]) [lindex $aLineSplt 1]
295       }
296     }
297   }
298
299   # make list of modules and platforms
300   set aModules [OS:init]
301   if { "$thePlatform" == "ios" } {
302     set goaway [list Draw]
303     set aModules [osutils:juststation $goaway $aModules]
304   }
305
306   # generate one solution for all projects if complete OS or VAS is processed
307   set anAllSolution "OCCT"
308
309   wokUtils:FILES:mkdir $anOutDir
310   if { ![file exists $anOutDir] } {
311     puts stderr "Error: Could not create output directory \"$anOutDir\""
312     return
313   }
314
315   # create the out dir if it does not exist
316   if (![file isdirectory $path/inc]) {
317     puts "$path/inc folder does not exists and will be created"
318     wokUtils:FILES:mkdir $path/inc
319   }
320
321   # collect all required header files
322   puts "Collecting required header files into $path/inc ..."
323   osutils:collectinc $aModules $path/inc $targetStation
324
325   # Generating project files for the selected IDE
326   switch -exact -- "$theIDE" {
327     "vc7"   -
328     "vc8"   -
329     "vc9"   -
330     "vc10"   -
331     "vc11"   -
332     "vc12"  { OS:MKVC  $anOutDir $aModules $anAllSolution $theIDE }
333     "cbp"   { OS:MKCBP $anOutDir $aModules $anAllSolution }
334     "amk"   { OS:MKAMK $anOutDir $aModules "adm/${aWokStation}/${theIDE}"}
335     "xcd"   {
336       set ::THE_GUIDS_LIST($::aTKNullKey) "000000000000000000000000"
337       OS:MKXCD $anOutDir $aModules $anAllSolution $theLibType $thePlatform
338     }
339   }
340
341   # Store generated GUIDs map
342   set anOutFile [open "$aGuidsFilePath" "w"]
343   fconfigure $anOutFile -translation lf
344   foreach aKey [array names ::THE_GUIDS_LIST] {
345     set aValue $::THE_GUIDS_LIST($aKey)
346     puts $anOutFile "${aKey}=${aValue}"
347   }
348   close $anOutFile
349 }
350
351 # Function to generate Visual Studio solution and project files
352 proc OS:MKVC { theOutDir {theModules {}} {theAllSolution ""} {theVcVer "vc8"} } {
353
354   puts stderr "Generating VS project files for $theVcVer"
355
356   # generate projects for toolkits and separate solution for each module
357   foreach aModule $theModules {
358     OS:vcsolution $theVcVer $aModule $aModule $theOutDir ::THE_GUIDS_LIST
359     OS:vcproj     $theVcVer $aModule          $theOutDir ::THE_GUIDS_LIST
360   }
361
362   # generate single solution "OCCT" containing projects from all modules
363   if { "$theAllSolution" != "" } {
364     OS:vcsolution $theVcVer $theAllSolution $theModules $theOutDir ::THE_GUIDS_LIST
365   }
366
367   puts "The Visual Studio solution and project files are stored in the $theOutDir directory"
368 }
369
370 proc OS:init {{os {}}} {
371     global path
372     global env
373     global tcl_platform
374     
375     set askplat $os
376     if { "$os" == "" } {
377       set os $tcl_platform(os)
378     }
379
380     ;# Load list of OCCT modules and their definitions
381     source "$path/src/OS/Modules.tcl"
382     set Modules {}
383     foreach module [OS:Modules] {
384         set f "$path/src/OS/${module}.tcl"
385         if [file exists $f] {
386             source $f
387             lappend Modules $module
388         } else {
389             puts stderr "Definition file for module $module is not found in unit OS"
390         }
391     }
392
393     # Load list of products and their definitions
394 #    set Products [woklocate -p VAS:source:Products.tcl]
395     #if { "$Products" != "" } {
396         #source "$Products"
397         #foreach product [VAS:Products] {
398             #set f [woklocate -p VAS:source:${product}.tcl]
399             #if [file exists $f] {
400                 #source $f
401             #} else {
402                 #puts stderr "Definition file for product $product is not found in unit VAS"
403             #}
404         #}
405     #}
406
407     return $Modules
408 }
409
410 # topological sort. returns a list {  {a h} {b g} {c f} {c h} {d i}  } => { d a b c i g f h }
411 proc wokUtils:EASY:tsort { listofpairs } {
412     foreach x $listofpairs {
413         set e1 [lindex $x 0]
414         set e2 [lindex $x 1]
415         if ![info exists pcnt($e1)] {
416             set pcnt($e1) 0
417         }
418         if ![ info exists pcnt($e2)] {
419             set pcnt($e2) 1
420         } else {
421             incr pcnt($e2)
422         }
423         if ![info exists scnt($e1)] {
424             set scnt($e1) 1
425         } else {
426             incr scnt($e1)
427         }
428         set l {}
429         if [info exists slist($e1)] {
430             set l $slist($e1)
431         }
432         lappend l $e2
433         set slist($e1) $l
434     }
435     set nodecnt 0
436     set back 0
437     foreach node [array names pcnt] {
438         incr nodecnt
439         if { $pcnt($node) == 0 } {
440             incr back
441             set q($back) $node
442         }
443         if ![info exists scnt($node)] {
444             set scnt($node) 0
445         }
446     }
447     set res {}
448     for {set front 1} { $front <= $back } { incr front } {
449         lappend res [set node $q($front)]
450         for {set i 1} {$i <= $scnt($node) } { incr i } {
451             set ll $slist($node)
452             set j [expr {$i - 1}]
453             set u [expr { $pcnt([lindex $ll $j]) - 1 }]
454             if { [set pcnt([lindex $ll $j]) $u] == 0 } {
455                 incr back
456                 set q($back) [lindex $ll $j]
457             }
458         }
459     }
460     if { $back != $nodecnt } {
461         puts stderr "input contains a cycle"
462         return {}
463     } else {
464         return $res
465     }
466 }
467
468 proc wokUtils:LIST:Purge { l } {
469     set r {}
470      foreach e $l {
471          if ![info exist tab($e)] {
472              lappend r $e
473              set tab($e) {}
474          } 
475      }
476      return $r
477 }
478
479 # Read file pointed to by path
480 # 1. sort = 1 tri 
481 # 2. trim = 1 plusieurs blancs => 1 seul blanc
482 # 3. purge= not yet implemented.
483 # 4. emptl= dont process blank lines
484 proc wokUtils:FILES:FileToList { path {sort 0} {trim 0} {purge 0} {emptl 1} } {
485     if ![ catch { set id [ open $path r ] } ] {
486         set l  {}
487         while {[gets $id line] >= 0 } {
488             if { $trim } {
489                 regsub -all {[ ]+} $line " " line
490             }
491             if { $emptl } {
492                 if { [string length ${line}] != 0 } {
493                     lappend l $line
494                 }
495             } else {
496                 lappend l $line
497             }
498         }
499         close $id
500         if { $sort } {
501             return [lsort $l]
502         } else {
503             return $l
504         }
505     } else {
506         return {}
507     }
508 }
509
510 # retorn the list of executables in module.
511 proc OS:executable { module } {
512     set lret {}
513     foreach XXX  [${module}:ressources] {
514         if { "[lindex $XXX 1]" == "x" } {
515             lappend lret [lindex $XXX 2]
516         }
517     }
518     return $lret
519 }
520
521 # Topological sort of toolkits in tklm
522 proc osutils:tk:sort { tklm } {
523   set tkby2 {}
524   foreach tkloc $tklm {
525     set lprg [wokUtils:LIST:Purge [osutils:tk:close $tkloc]]
526     foreach tkx  $lprg {
527       if { [lsearch $tklm $tkx] != -1 } {
528         lappend tkby2 [list $tkx $tkloc]
529       } else {
530         lappend tkby2 [list $tkloc {}]
531       }
532     }
533   }
534   set lret {}
535   foreach e [wokUtils:EASY:tsort $tkby2] {
536     if { $e != {} } {
537       lappend lret $e
538     }
539   }
540   return $lret
541 }
542
543 #  close dependencies of ltk. (full wok pathes of toolkits)
544 # The CURRENT WOK LOCATION MUST contains ALL TOOLKITS required.
545 # (locate not performed.)
546 proc osutils:tk:close { ltk } {
547   set result {}
548   set recurse {}
549   foreach dir $ltk {
550     set ids [LibToLink $dir]
551     set eated [osutils:tk:eatpk $ids]
552     set result [concat $result $eated]
553     set ids [LibToLink $dir]
554     set result [concat $result $ids]
555
556     foreach file $eated {
557       set kds "$path/src/$file/EXTERNLIB"
558       if { [osutils:tk:eatpk $kds] !=  {} } {
559         lappend recurse $file
560       }
561     }
562   }
563   if { $recurse != {} } {
564     set result [concat $result [osutils:tk:close $recurse]]
565   }
566   return $result
567 }
568
569 proc osutils:tk:eatpk { EXTERNLIB  } {
570   set l [wokUtils:FILES:FileToList $EXTERNLIB]
571   set lret  {}
572   foreach str $l {
573     if ![regexp -- {(CSF_[^ ]*)} $str csf] {
574       lappend lret $str
575     }
576   }
577   return $lret
578 }
579 # Define libraries to link using only EXTERNLIB file
580
581 proc LibToLink {theTKit} {
582   global path
583   regexp {^.*:([^:]+)$} $theTKit dummy theTKit
584   set type [_get_type $theTKit]
585   if {$type != "t" && $type != "x"} {
586     return
587   }
588   set aToolkits {}
589   set anExtLibList [osutils:tk:eatpk "$path/src/$theTKit/EXTERNLIB"]
590   foreach anExtLib $anExtLibList {
591     set aFullPath [LocateRecur $anExtLib]
592     if { "$aFullPath" != "" && [_get_type $anExtLib] == "t" } {
593       lappend aToolkits $anExtLib
594     }
595   }
596   return $aToolkits
597 }
598 # Search unit recursively
599
600 proc LocateRecur {theName} {
601   global path
602   set theNamePath "$path/src/$theName"
603   if {[file isdirectory $theNamePath]} {
604     return $theNamePath
605   }
606   return ""
607 }
608
609 proc OS:genGUID { {theIDE "vc"} } {
610   if { "$theIDE" == "vc" } {
611     set p1 "[format %07X [expr { int(rand() * 268435456) }]][format %X [expr { int(rand() * 16) }]]"
612     set p2 "[format %04X [expr { int(rand() * 6536) }]]"
613     set p3 "[format %04X [expr { int(rand() * 6536) }]]"
614     set p4 "[format %04X [expr { int(rand() * 6536) }]]"
615     set p5 "[format %06X [expr { int(rand() * 16777216) }]][format %06X [expr { int(rand() * 16777216) }]]"
616     return "{$p1-$p2-$p3-$p4-$p5}"
617   } else {
618     set p1 "[format %04X [expr { int(rand() * 6536) }]]"
619     set p2 "[format %04X [expr { int(rand() * 6536) }]]"
620     set p3 "[format %04X [expr { int(rand() * 6536) }]]"
621     set p4 "[format %04X [expr { int(rand() * 6536) }]]"
622     set p5 "[format %04X [expr { int(rand() * 6536) }]]"
623     set p6 "[format %04X [expr { int(rand() * 6536) }]]"
624     return "$p1$p2$p3$p4$p5$p6"
625   }
626 }
627
628 # collect all include file that required for theModules in theOutDir
629 proc osutils:collectinc {theModules theIncPath theTargetStation} {
630   global path
631
632   set aCasRoot [file normalize $path]
633   set anIncPath [file normalize $theIncPath]
634
635   if {![file isdirectory $aCasRoot]} {
636     puts "OCCT directory is not defined correctly: $aCasRoot"
637     return
638   }
639
640   set anUsedToolKits {}
641   foreach aModule $theModules {
642     foreach aToolKit [${aModule}:toolkits] {
643       lappend anUsedToolKits $aToolKit
644
645       foreach aDependency [LibToLink $aToolKit] {
646         lappend anUsedToolKits $aDependency
647       }
648     }
649     foreach anExecutable [OS:executable ${aModule}] {
650       lappend anUsedToolKits $anExecutable
651
652       foreach aDependency [LibToLink $anExecutable] {
653         lappend anUsedToolKits $aDependency
654       }
655     }
656   }
657   lsort -unique $anUsedToolKits
658
659   set anUnits {}
660   foreach anUsedToolKit $anUsedToolKits {
661     set anUnits [concat $anUnits [osutils:tk:units $anUsedToolKit]]
662   }
663   lsort -unique $anUnits
664
665   if { [info exists ::env(SHORTCUT_HEADERS)] && 
666        $::env(SHORTCUT_HEADERS) == "true" } {
667     # template preparation
668     if { ![file exists $aCasRoot/adm/templates/header.in] } {
669       puts "template file does not exist: $aCasRoot/adm/templates/header.in"
670       return
671     }
672     set aHeaderTmpl [wokUtils:FILES:FileToString $aCasRoot/adm/templates/header.in]
673
674     # relative anIncPath in connection with aCasRoot/src
675     set aFromBuildIncToSrcPath [relativePath "$anIncPath" "$aCasRoot/src"]
676
677     # create and copy short-cut header files
678     foreach anUnit $anUnits {
679       set aHFiles [glob -nocomplain -dir $aCasRoot/src/$anUnit "*.h"]
680       foreach aHeaderFile [concat [glob -nocomplain -dir $aCasRoot/src/$anUnit "*.\[hgl\]xx"] $aHFiles] {
681         set aHeaderFileName [file tail $aHeaderFile]
682
683         regsub -all -- {@OCCT_HEADER_FILE@} $aHeaderTmpl "$aFromBuildIncToSrcPath/$anUnit/$aHeaderFileName" aShortCutHeaderFileContent
684
685         if {[file exists "$theIncPath/$aHeaderFileName"] && [file readable "$theIncPath/$aHeaderFileName"]} {
686           set fp [open "$theIncPath/$aHeaderFileName" r]
687           set aHeaderContent [read $fp]
688           close $fp
689
690           # minus eof
691           set aHeaderLenght  [expr [string length $aHeaderContent] - 1]
692
693           if {$aHeaderLenght == [string length $aShortCutHeaderFileContent]} {
694             # remove eof from string
695             set aHeaderContent [string range $aHeaderContent 0 [expr $aHeaderLenght - 1]]
696
697             if {[string compare $aShortCutHeaderFileContent $aHeaderContent] == 0} {
698               continue
699             }
700           }
701         }
702
703         set aShortCutHeaderFile [open "$theIncPath/$aHeaderFileName" "w"]
704         fconfigure $aShortCutHeaderFile -translation lf
705         puts $aShortCutHeaderFile $aShortCutHeaderFileContent
706         close $aShortCutHeaderFile
707       }
708     }  
709   } else {
710     set nbcopied 0
711     foreach anUnit $anUnits {
712       set aHFiles [glob -nocomplain -dir $aCasRoot/src/$anUnit "*.h"]
713       foreach aHeaderFile [concat [glob -nocomplain -dir $aCasRoot/src/$anUnit "*.\[hgl\]xx"] $aHFiles] {
714         set aHeaderFileName [file tail $aHeaderFile]
715
716         # copy file only if target does not exist or is older than original
717         set torig [file mtime $aHeaderFile]
718         if { ! [file isfile $anIncPath/$aHeaderFileName] } {
719           set tcopy 0
720         } else {
721           set tcopy [file mtime $anIncPath/$aHeaderFileName]
722         }
723         if { $tcopy < $torig } {
724           incr nbcopied
725           file copy -force $aHeaderFile $anIncPath/$aHeaderFileName
726         } elseif { $tcopy != $torig } {
727           puts "Warning: file $anIncPath/$aHeaderFileName is newer than $aHeaderFile, not changed!"
728         }
729       }
730     }
731     puts "Info: $nbcopied files updated"
732   }
733 }
734
735 # Generate header for VS solution file
736 proc osutils:vcsolution:header { vcversion } {
737   if { "$vcversion" == "vc7" } {
738     append var \
739       "Microsoft Visual Studio Solution File, Format Version 8.00\n"
740   } elseif { "$vcversion" == "vc8" } {
741     append var \
742       "Microsoft Visual Studio Solution File, Format Version 9.00\n" \
743       "# Visual Studio 2005\n"
744   } elseif { "$vcversion" == "vc9" } {
745     append var \
746       "Microsoft Visual Studio Solution File, Format Version 10.00\n" \
747       "# Visual Studio 2008\n"
748   } elseif { "$vcversion" == "vc10" } {
749     append var \
750       "Microsoft Visual Studio Solution File, Format Version 11.00\n" \
751       "# Visual Studio 2010\n"
752   } elseif { "$vcversion" == "vc11" } {
753     append var \
754       "Microsoft Visual Studio Solution File, Format Version 12.00\n" \
755       "# Visual Studio 2012\n"
756   } elseif { "$vcversion" == "vc12" } {
757     append var \
758       "Microsoft Visual Studio Solution File, Format Version 13.00\n" \
759       "# Visual Studio 2013\n"
760   } else {
761     puts stderr "Error: Visual Studio version $vcversion is not supported by this function!"
762   }
763   return $var
764 }
765 # Returns extension (without dot) for project files of given version of VC
766
767 proc osutils:vcproj:ext { vcversion } {
768   if { "$vcversion" == "vc7" || "$vcversion" == "vc8" || "$vcversion" == "vc9" } {
769     return "vcproj"
770   } elseif { "$vcversion" == "vc10" || "$vcversion" == "vc11" || "$vcversion" == "vc12" } {
771     return "vcxproj"
772   } else {
773     puts stderr "Error: Visual Studio version $vc is not supported by this function!"
774   }
775 }
776 # Generate start of configuration section of VS solution file
777
778 proc osutils:vcsolution:config:begin { vcversion } {
779   if { "$vcversion" == "vc7" } {
780     append var \
781       "Global\n" \
782       "\tGlobalSection(SolutionConfiguration) = preSolution\n" \
783       "\t\tDebug = Debug\n" \
784       "\t\tRelease = Release\n" \
785       "\tEndGlobalSection\n" \
786       "\tGlobalSection(ProjectConfiguration) = postSolution\n"
787   } elseif { "$vcversion" == "vc8" || "$vcversion" == "vc9" ||
788              "$vcversion" == "vc10" || "$vcversion" == "vc11" ||
789              "$vcversion" == "vc12" } {
790     append var \
791       "Global\n" \
792       "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n" \
793       "\t\tDebug|Win32 = Debug|Win32\n" \
794       "\t\tRelease|Win32 = Release|Win32\n" \
795       "\t\tDebug|x64 = Debug|x64\n" \
796       "\t\tRelease|x64 = Release|x64\n" \
797       "\tEndGlobalSection\n" \
798       "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n"
799   } else {
800     puts stderr "Error: Visual Studio version $vcversion is not supported by this function!"
801   }
802   return $var
803 }
804 # Generate part of configuration section of VS solution file describing one project
805
806 proc osutils:vcsolution:config:project { vcversion guid } {
807   if { "$vcversion" == "vc7" } {
808     append var \
809       "\t\t$guid.Debug.ActiveCfg = Debug|Win32\n" \
810       "\t\t$guid.Debug.Build.0 = Debug|Win32\n" \
811       "\t\t$guid.Release.ActiveCfg = Release|Win32\n" \
812       "\t\t$guid.Release.Build.0 = Release|Win32\n"
813   } elseif { "$vcversion" == "vc8" || "$vcversion" == "vc9" ||
814              "$vcversion" == "vc10" || "$vcversion" == "vc11" ||
815              "$vcversion" == "vc12" } {
816     append var \
817       "\t\t$guid.Debug|Win32.ActiveCfg = Debug|Win32\n" \
818       "\t\t$guid.Debug|Win32.Build.0 = Debug|Win32\n" \
819       "\t\t$guid.Release|Win32.ActiveCfg = Release|Win32\n" \
820       "\t\t$guid.Release|Win32.Build.0 = Release|Win32\n" \
821       "\t\t$guid.Debug|x64.ActiveCfg = Debug|x64\n" \
822       "\t\t$guid.Debug|x64.Build.0 = Debug|x64\n" \
823       "\t\t$guid.Release|x64.ActiveCfg = Release|x64\n" \
824       "\t\t$guid.Release|x64.Build.0 = Release|x64\n"
825   } else {
826     puts stderr "Error: Visual Studio version $vcversion is not supported by this function!"
827   }
828   return $var
829 }
830 # Generate start of configuration section of VS solution file
831
832 proc osutils:vcsolution:config:end { vcversion } {
833   if { "$vcversion" == "vc7" } {
834     append var \
835       "\tEndGlobalSection\n" \
836       "\tGlobalSection(ExtensibilityGlobals) = postSolution\n" \
837       "\tEndGlobalSection\n" \
838       "\tGlobalSection(ExtensibilityAddIns) = postSolution\n" \
839       "\tEndGlobalSection\n"
840   } elseif { "$vcversion" == "vc8" || "$vcversion" == "vc9" ||
841              "$vcversion" == "vc10" || "$vcversion" == "vc11" ||
842              "$vcversion" == "vc12" } {
843     append var \
844       "\tEndGlobalSection\n" \
845       "\tGlobalSection(SolutionProperties) = preSolution\n" \
846       "\t\tHideSolutionNode = FALSE\n" \
847       "\tEndGlobalSection\n"
848   } else {
849     puts stderr "Error: Visual Studio version $vcversion is not supported by this function!"
850   }
851   return $var
852 }
853 # generate Visual Studio solution file
854 # if module is empty, generates one solution for all known modules
855
856 proc OS:vcsolution { theVcVer theSolName theModules theOutDir theGuidsMap } {
857   global path
858   upvar $theGuidsMap aGuidsMap
859
860   # collect list of projects to be created
861   set aProjects {}
862   set aDependencies {}
863   foreach aModule $theModules {
864     # toolkits
865     foreach aToolKit [osutils:tk:sort [${aModule}:toolkits]] {
866       lappend aProjects $aToolKit
867       lappend aProjectsInModule($aModule) $aToolKit
868       lappend aDependencies [LibToLink $aToolKit]
869     }
870     # executables, assume one project per cxx file...
871     foreach aUnit [OS:executable ${aModule}] {
872       set aUnitLoc $aUnit
873       set src_files [_get_used_files $aUnit false]
874       set aSrcFiles {}
875       foreach s $src_files {
876         regexp {source ([^\s]+)} $s dummy name
877         lappend aSrcFiles $name
878       }
879       foreach aSrcFile $aSrcFiles {
880         set aFileExtension [file extension $aSrcFile]
881         if { $aFileExtension == ".cxx" } {
882           set aPrjName [file rootname $aSrcFile]
883           lappend aProjects $aPrjName
884           lappend aProjectsInModule($aModule) $aPrjName
885           if {[file isdirectory $path/src/$aUnitLoc]} {
886             lappend aDependencies [LibToLinkX $aUnitLoc [file rootname $aSrcFile]]
887           } else {
888             lappend aDependencies {}
889           }
890         }
891       }
892     }
893   }
894
895 # generate GUIDs for projects (unless already known)
896   foreach aProject $aProjects {
897     if { ! [info exists aGuidsMap($aProject)] } {
898       set aGuidsMap($aProject) [OS:genGUID]
899     }
900   }
901
902   # generate solution file
903 #  puts "Generating Visual Studio ($theVcVer) solution file for $theSolName ($aProjects)"
904   append aFileBuff [osutils:vcsolution:header $theVcVer]
905
906   # GUID identifying group projects in Visual Studio
907   set VC_GROUP_GUID "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
908
909   # generate group projects -- one per module
910   if { "$theVcVer" != "vc7" && [llength "$theModules"] > 1 } {
911     foreach aModule $theModules {
912       if { ! [info exists aGuidsMap(_$aModule)] } {
913         set aGuidsMap(_$aModule) [OS:genGUID]
914       }
915       set aGuid $aGuidsMap(_$aModule)
916       append aFileBuff "Project(\"${VC_GROUP_GUID}\") = \"$aModule\", \"$aModule\", \"$aGuid\"\nEndProject\n"
917     }
918   }
919
920   # extension of project files
921   set aProjExt [osutils:vcproj:ext $theVcVer]
922
923   # GUID identifying C++ projects in Visual Studio
924   set VC_CPP_GUID "{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}"
925
926   # generate normal projects
927   set aProjsNb [llength $aProjects]
928   for {set aProjId 0} {$aProjId < $aProjsNb} {incr aProjId} {
929     set aProj [lindex $aProjects $aProjId]
930     set aGuid $aGuidsMap($aProj)
931     append aFileBuff "Project(\"${VC_CPP_GUID}\") = \"$aProj\", \"$aProj.${aProjExt}\", \"$aGuid\"\n"
932     # write projects dependencies information (vc7 to vc9)
933     set aDepGuids ""
934     foreach aDepLib [lindex $aDependencies $aProjId] {
935       if { $aDepLib != $aProj && [lsearch $aProjects $aDepLib] != "-1" } {
936         set depGUID $aGuidsMap($aDepLib)
937         append aDepGuids "\t\t$depGUID = $depGUID\n"
938       }
939     }
940     if { "$aDepGuids" != "" } {
941       append aFileBuff "\tProjectSection(ProjectDependencies) = postProject\n"
942       append aFileBuff "$aDepGuids"
943       append aFileBuff "\tEndProjectSection\n"
944     }
945     append aFileBuff "EndProject\n"
946   }
947
948   # generate configuration section
949   append aFileBuff [osutils:vcsolution:config:begin $theVcVer]
950   foreach aProj $aProjects {
951     append aFileBuff [osutils:vcsolution:config:project $theVcVer $aGuidsMap($aProj)]
952   }
953   append aFileBuff [osutils:vcsolution:config:end $theVcVer]
954
955   # write information of grouping of projects by module
956   if { "$theVcVer" != "vc7" && [llength "$theModules"] > 1 } {
957     append aFileBuff "  GlobalSection(NestedProjects) = preSolution\n"
958     foreach aModule $theModules {
959       if { ! [info exists aProjectsInModule($aModule)] } { continue }
960       foreach aProject $aProjectsInModule($aModule) {
961         append aFileBuff "              $aGuidsMap($aProject) = $aGuidsMap(_$aModule)\n"
962       }
963     }
964     append aFileBuff "  EndGlobalSection\n"
965   }
966
967   # final word (footer)
968   append aFileBuff "EndGlobal"
969
970   # write solution
971   set aFile [open [set fdsw [file join $theOutDir ${theSolName}.sln]] w]
972   fconfigure $aFile -translation crlf
973   puts $aFile $aFileBuff
974   close $aFile
975   return [file join $theOutDir ${theSolName}.sln]
976 }
977 # Generate Visual Studio projects for specified version
978
979 proc OS:vcproj { theVcVer theModules theOutDir theGuidsMap } {
980   upvar $theGuidsMap aGuidsMap
981
982   set aProjectFiles {}
983
984   foreach aModule $theModules {
985     foreach aToolKit [${aModule}:toolkits] {
986       lappend aProjectFiles [osutils:vcproj  $theVcVer $theOutDir $aToolKit     aGuidsMap]
987     }
988     foreach anExecutable [OS:executable ${aModule}] {
989       lappend aProjectFiles [osutils:vcprojx $theVcVer $theOutDir $anExecutable aGuidsMap]
990     }
991   }
992   return $aProjectFiles
993 }
994 # generate template name and load it for given version of Visual Studio and platform
995
996 proc osutils:vcproj:readtemplate {vc isexec} {
997   set ext $vc
998   set what "$vc"
999   if { $isexec } {
1000     set ext "${ext}x"
1001     set what "$what executable"
1002   }
1003   return [osutils:readtemplate $ext "MS VC++ project ($what)"]
1004 }
1005
1006 proc osutils:readtemplate {ext what} {
1007   global env
1008   global path
1009   set loc "$path/adm/templates/template.$ext"
1010   return [wokUtils:FILES:FileToString $loc]
1011 }
1012 # Read a file in a string as is.
1013
1014 proc wokUtils:FILES:FileToString { fin } {
1015     if { [catch { set in [ open $fin r ] } errin] == 0 } {
1016         set strin [read $in [file size $fin]]
1017         close $in
1018         return $strin
1019     } else {
1020         return {}
1021     }
1022 }
1023 # List extensions of compilable files in OCCT
1024
1025 proc osutils:compilable { } {
1026   global targetStation
1027   set aWokStation "$targetStation"
1028   if { "$aWokStation" == "mac" } {
1029     return [list .c .cxx .cpp .mm]
1030   }
1031   return [list .c .cxx .cpp]
1032 }
1033
1034 proc osutils:commonUsedTK { theToolKit } {
1035   global path
1036   set anUsedToolKits [list]
1037   set aDepToolkits [LibToLink $theToolKit]
1038   foreach tkx $aDepToolkits {
1039     if {[_get_type $tkx] == "t"} {
1040       lappend anUsedToolKits "${tkx}"
1041     }
1042   }
1043   return $anUsedToolKits
1044 }
1045
1046 # Return the list of name *CSF_ in a EXTERNLIB description of a toolkit
1047 proc osutils:tk:csfInExternlib { EXTERNLIB } {
1048   set l [wokUtils:FILES:FileToList $EXTERNLIB]
1049   set lret  {STLPort}
1050   foreach str $l {
1051     if [regexp -- {(CSF_[^ ]*)} $str csf] {
1052       lappend lret $csf
1053     }
1054   }
1055   return $lret
1056 }
1057
1058 # @param theCsfLibsMap - libraries  map
1059 # @param theCsfFrmsMap - frameworks map, OS X specific
1060 proc osutils:csfList { theOS theCsfLibsMap theCsfFrmsMap } {
1061   upvar $theCsfLibsMap aLibsMap
1062   upvar $theCsfFrmsMap aFrmsMap
1063
1064   unset theCsfLibsMap
1065   unset theCsfFrmsMap
1066
1067   if { "$theOS" == "wnt" } {
1068     #  WinAPI libraries
1069     set aLibsMap(CSF_kernel32)     "kernel32.lib"
1070     set aLibsMap(CSF_advapi32)     "advapi32.lib"
1071     set aLibsMap(CSF_gdi32)        "gdi32.lib"
1072     set aLibsMap(CSF_user32)       "user32.lib"
1073     set aLibsMap(CSF_glu32)        "glu32.lib"
1074     set aLibsMap(CSF_opengl32)     "opengl32.lib"
1075     set aLibsMap(CSF_wsock32)      "wsock32.lib"
1076     set aLibsMap(CSF_netapi32)     "netapi32.lib"
1077     set aLibsMap(CSF_AviLibs)      "ws2_32.lib vfw32.lib"
1078     set aLibsMap(CSF_OpenGlLibs)   "opengl32.lib glu32.lib"
1079
1080     set aLibsMap(CSF_QT)           "QtCore4.lib QtGui4.lib"
1081
1082     # VTK
1083     set aCsfMap(CSF_VTK)         [osutils:vtkCsf "wnt"]
1084   } else {
1085     set aLibsMap(CSF_FREETYPE)     "freetype"
1086     if { "$theOS" == "mac" } {
1087       set aLibsMap(CSF_objc)       "objc"
1088       set aFrmsMap(CSF_Appkit)     "Appkit"
1089       set aFrmsMap(CSF_IOKit)      "IOKit"
1090       set aFrmsMap(CSF_OpenGlLibs) "OpenGL"
1091       set aFrmsMap(CSF_TclLibs)    "Tcl"
1092       set aFrmsMap(CSF_TclTkLibs)  "Tk"
1093     } else {
1094       set aLibsMap(CSF_ThreadLibs) "pthread rt"
1095       set aLibsMap(CSF_OpenGlLibs) "GLU GL"
1096       set aLibsMap(CSF_TclLibs)    "tcl8.6"
1097       set aLibsMap(CSF_TclTkLibs)  "X11 tk8.6"
1098       set aLibsMap(CSF_XwLibs)     "X11 Xext Xmu Xi"
1099       set aLibsMap(CSF_MotifLibs)  "X11"
1100     }
1101
1102     # optional 3rd-parties
1103     if { "$::HAVE_TBB" == "true" } {
1104       set aLibsMap(CSF_TBB)        "tbb tbbmalloc"
1105     }
1106     if { "$::HAVE_FREEIMAGE" == "true" } {
1107       set aLibsMap(CSF_FreeImagePlus)  "freeimage"
1108     }
1109     if { "$::HAVE_GL2PS" == "true" } {
1110       set aLibsMap(CSF_GL2PS)      "gl2ps"
1111     }
1112     if { "$::HAVE_VTK" == "true" } {
1113       set aCsfMap(CSF_VTK)         [osutils:vtkCsf "unix"]
1114     }
1115   }
1116 }
1117
1118 # Returns string of library dependencies for generation of Visual Studio project or make lists.
1119 proc osutils:vtkCsf {{theOS ""}} {
1120   set aVtkVer "6.1"
1121
1122   set aLibSuffix ""
1123   set aPathSplitter ":"
1124   
1125   if {"$theOS" == "wnt"} {
1126     set aPathSplitter ";"
1127     set aLibSuffix ".lib"
1128   }
1129
1130   set anOptIncs [split $::env(CSF_OPT_INC) "$aPathSplitter"]
1131   foreach anIncItem $anOptIncs {
1132     if {[regexp -- "vtk-(.*)$" [file tail $anIncItem] dummy aFoundVtkVer]} {
1133       set aVtkVer $aFoundVtkVer
1134     }
1135   }
1136
1137   set aLibArray [list vtkCommonCore vtkCommonDataModel vtkCommonExecutionModel vtkCommonMath vtkCommonTransforms vtkRenderingCore \
1138                       vtkRenderingOpenGL  vtkFiltersGeneral vtkIOCore vtkIOImage vtkImagingCore vtkInteractionStyle]
1139
1140   # Additional suffices for the libraries
1141   set anIdx 0
1142   foreach anItem $aLibArray {
1143     lset aLibArray $anIdx $anItem-$aVtkVer$aLibSuffix
1144     incr anIdx
1145   }
1146
1147   return [join $aLibArray " "]
1148 }
1149
1150 # @param theLibsList   - dependencies (libraries  list)
1151 # @param theFrameworks - dependencies (frameworks list, OS X specific)
1152 proc osutils:usedOsLibs { theToolKit theOS theLibsList theFrameworks } {
1153   global path
1154   upvar $theLibsList   aLibsList
1155   upvar $theFrameworks aFrameworks
1156   set aLibsList   [list]
1157   set aFrameworks [list]
1158
1159   osutils:csfList $theOS aLibsMap aFrmsMap
1160
1161   foreach aCsfElem [osutils:tk:csfInExternlib "$path/src/${theToolKit}/EXTERNLIB"] {
1162     if [info exists aLibsMap($aCsfElem)] {
1163       foreach aLib [split "$aLibsMap($aCsfElem)"] {
1164         if { [lsearch $aLibsList $aLib] == "-1" } {
1165           lappend aLibsList $aLib
1166         }
1167       }
1168     }
1169     if [info exists aFrmsMap($aCsfElem)] {
1170       foreach aFrm [split "$aFrmsMap($aCsfElem)"] {
1171         if { [lsearch $aFrameworks $aFrm] == "-1" } {
1172           lappend aFrameworks $aFrm
1173         }
1174       }
1175     }
1176   }
1177 }
1178
1179 # Returns liste of UD in a toolkit. tkloc is a full path wok.
1180 proc osutils:tk:units { tkloc } {
1181   global path
1182   set l {}
1183   set PACKAGES "$path/src/$tkloc/PACKAGES"
1184   foreach u [wokUtils:FILES:FileToList $PACKAGES] {
1185     if {[file isdirectory "$path/src/$u"]} {
1186       lappend l $u
1187     }
1188   }
1189   if { $l == {} } {
1190     ;#puts stderr "Warning. No devunit included in $tkloc"
1191   }
1192   return $l
1193 }
1194
1195 proc osutils:justwnt { listloc } {
1196   # ImageUtility is required for support for old (<6.5.4) versions of OCCT
1197   set goaway [list Xdps Xw  ImageUtility WOKUnix]
1198   return [osutils:juststation $goaway $listloc]
1199 }
1200
1201 # remove from listloc OpenCascade units indesirables on NT
1202 proc osutils:juststation {goaway listloc} {
1203   global path
1204   set lret {}
1205   foreach u $listloc {
1206     if {([file isdirectory "$path/src/$u"] && [lsearch $goaway $u] == -1 )
1207      || (![file isdirectory "$path/src/$u"] && [lsearch $goaway $u] == -1 ) } {
1208       lappend lret $u
1209     }
1210   }
1211   return $lret
1212 }
1213
1214 # intersect3 - perform the intersecting of two lists, returning a list containing three lists.
1215 # The first list is everything in the first list that wasn't in the second,
1216 # the second list contains the intersection of the two lists, the third list contains everything
1217 # in the second list that wasn't in the first.
1218 proc osutils:intersect3 {list1 list2} {
1219   set la1(0) {} ; unset la1(0)
1220   set lai(0) {} ; unset lai(0)
1221   set la2(0) {} ; unset la2(0)
1222   foreach v $list1 {
1223     set la1($v) {}
1224   }
1225   foreach v $list2 {
1226     set la2($v) {}
1227   }
1228   foreach elem [concat $list1 $list2] {
1229     if {[info exists la1($elem)] && [info exists la2($elem)]} {
1230       unset la1($elem)
1231       unset la2($elem)
1232       set lai($elem) {}
1233     }
1234   }
1235   list [lsort [array names la1]] [lsort [array names lai]] [lsort [array names la2]]
1236 }
1237
1238 # Prepare relative path
1239 proc relativePath {thePathFrom thePathTo} {
1240   if { [file isdirectory "$thePathFrom"] == 0 } {
1241     return ""
1242   }
1243
1244   set aPathFrom [file normalize "$thePathFrom"]
1245   set aPathTo   [file normalize "$thePathTo"]
1246
1247   set aCutedPathFrom "${aPathFrom}/dummy"
1248   set aRelatedDeepPath ""
1249
1250   while { "$aCutedPathFrom" != [file normalize "$aCutedPathFrom/.."] } {
1251     set aCutedPathFrom [file normalize "$aCutedPathFrom/.."]
1252     # does aPathTo contain aCutedPathFrom?
1253     regsub -all $aCutedPathFrom $aPathTo "" aPathFromAfterCut
1254     if { "$aPathFromAfterCut" != "$aPathTo" } { # if so
1255       if { "$aCutedPathFrom" == "$aPathFrom" } { # just go higher, for example, ./somefolder/someotherfolder
1256         set aPathTo ".${aPathTo}"
1257       } elseif { "$aCutedPathFrom" == "$aPathTo" } { # remove the last "/"
1258         set aRelatedDeepPath [string replace $aRelatedDeepPath end end ""]
1259       }
1260       regsub -all $aCutedPathFrom $aPathTo $aRelatedDeepPath aPathToAfterCut
1261       regsub -all "//" $aPathToAfterCut "/" aPathToAfterCut
1262       return $aPathToAfterCut
1263     }
1264     set aRelatedDeepPath "$aRelatedDeepPath../"
1265
1266   }
1267
1268   return $thePathTo
1269 }
1270
1271 proc wokUtils:EASY:bs1 { s } {
1272     regsub -all {/} $s {\\} r
1273     return $r
1274 }
1275
1276 # Returs for a full path the liste of n last directory part
1277 # n = 1 => tail
1278 # n = 2 => dir/file.c
1279 # n = 3 => sdir/dir/file.c
1280 # etc..
1281 proc wokUtils:FILES:wtail { f n } {
1282     set ll [expr [llength [set lif [file split $f]]] -$n]
1283     return [join [lrange $lif $ll end] /]
1284 }
1285
1286 # Generate entry for one source file in Visual Studio 10 project file
1287 proc osutils:vcxproj:file { vcversion file params } {
1288   append text "    <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $file 3]]\">\n"
1289   if { $params != "" } {
1290     append text "      <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Debug|Win32\'\">[string trim ${params}]  %(AdditionalOptions)</AdditionalOptions>\n"
1291   }
1292
1293   if { $params != "" } {
1294     append text "      <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Release|Win32\'\">[string trim ${params}]  %(AdditionalOptions)</AdditionalOptions>\n"
1295   }
1296
1297   if { $params != "" } {
1298     append text "      <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Debug|x64\'\">[string trim ${params}]  %(AdditionalOptions)</AdditionalOptions>\n"
1299   }
1300
1301   if { $params != "" } {
1302     append text "      <AdditionalOptions Condition=\"\'\$(Configuration)|\$(Platform)\'==\'Release|x64\'\">[string trim ${params}]  %(AdditionalOptions)</AdditionalOptions>\n"
1303   }
1304
1305   append text "    </ClCompile>\n"
1306   return $text
1307 }
1308
1309 # Generate Visual Studio 2010 project filters file
1310 proc osutils:vcxproj:filters { dir proj theFilesMap } {
1311   upvar $theFilesMap aFilesMap
1312
1313   # header
1314   append text "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1315   append text "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
1316
1317   # list of "filters" (units)
1318   append text "  <ItemGroup>\n"
1319   append text "    <Filter Include=\"Source files\">\n"
1320   append text "      <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1321   append text "    </Filter>\n"
1322   foreach unit $aFilesMap(units) {
1323     append text "    <Filter Include=\"Source files\\${unit}\">\n"
1324     append text "      <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1325     append text "    </Filter>\n"
1326   }
1327   append text "  </ItemGroup>\n"
1328
1329   # list of files
1330   append text "  <ItemGroup>\n"
1331   foreach unit $aFilesMap(units) {
1332     foreach file $aFilesMap($unit) {
1333       append text "    <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $file 3]]\">\n"
1334       append text "      <Filter>Source files\\${unit}</Filter>\n"
1335       append text "    </ClCompile>\n"
1336     }
1337   }
1338   append text "  </ItemGroup>\n"
1339
1340   # end
1341   append text "</Project>"
1342
1343   # write file
1344   set fp [open [set fvcproj [file join $dir ${proj}.vcxproj.filters]] w]
1345   fconfigure $fp -translation crlf
1346   puts $fp $text
1347   close $fp
1348
1349   return ${proj}.vcxproj.filters
1350 }
1351
1352 # Generate Visual Studio 2011 project filters file
1353 proc osutils:vcx1proj:filters { dir proj theFilesMap } {
1354   upvar $theFilesMap aFilesMap
1355
1356   # header
1357   append text "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
1358   append text "<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n"
1359
1360   # list of "filters" (units)
1361   append text "  <ItemGroup>\n"
1362   append text "    <Filter Include=\"Source files\">\n"
1363   append text "      <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1364   append text "    </Filter>\n"
1365   foreach unit $aFilesMap(units) {
1366     append text "    <Filter Include=\"Source files\\${unit}\">\n"
1367     append text "      <UniqueIdentifier>[OS:genGUID]</UniqueIdentifier>\n"
1368     append text "    </Filter>\n"
1369   }
1370   append text "  </ItemGroup>\n"
1371
1372   # list of files
1373   append text "  <ItemGroup>\n"
1374   foreach unit $aFilesMap(units) {
1375     foreach file $aFilesMap($unit) {
1376       append text "    <ClCompile Include=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $file 3]]\">\n"
1377       append text "      <Filter>Source files\\${unit}</Filter>\n"
1378       append text "    </ClCompile>\n"
1379     }
1380   }
1381   append text "  </ItemGroup>\n"
1382
1383   append text "  <ItemGroup>\n"
1384   append text "    <ResourceCompile Include=\"${proj}.rc\" />"
1385   append text "  </ItemGroup>\n"
1386
1387   # end
1388   append text "</Project>"
1389
1390   # write file
1391   set fp [open [set fvcproj [file join $dir ${proj}.vcxproj.filters]] w]
1392   fconfigure $fp -translation crlf
1393   puts $fp $text
1394   close $fp
1395
1396   return ${proj}.vcxproj.filters
1397 }
1398
1399 # Generate RC file content for ToolKit from template
1400 proc osutils:readtemplate:rc {theOutDir theToolKit} {
1401   global path
1402   set aLoc "$path/adm/templates/template_dll.rc"
1403   set aBody [wokUtils:FILES:FileToString $aLoc]
1404   regsub -all -- {__TKNAM__} $aBody $theToolKit aBody
1405
1406   set aFile [open "${theOutDir}/${theToolKit}.rc" "w"]
1407   fconfigure $aFile -translation lf
1408   puts $aFile $aBody
1409   close $aFile
1410   return "${theOutDir}/${theToolKit}.rc"
1411 }
1412
1413 # Generate Visual Studio project file for ToolKit
1414 proc osutils:vcproj { theVcVer theOutDir theToolKit theGuidsMap {theProjTmpl {} } } {
1415   if { $theProjTmpl == {} } {set theProjTmpl [osutils:vcproj:readtemplate $theVcVer 0]}
1416
1417   set l_compilable [osutils:compilable]
1418   regsub -all -- {__TKNAM__} $theProjTmpl $theToolKit theProjTmpl
1419
1420   upvar $theGuidsMap aGuidsMap
1421   if { ! [info exists aGuidsMap($theToolKit)] } {
1422     set aGuidsMap($theToolKit) [OS:genGUID]
1423   }
1424   regsub -all -- {__PROJECT_GUID__} $theProjTmpl $aGuidsMap($theToolKit) theProjTmpl
1425
1426   set aCommonUsedTK [list]
1427   foreach tkx [osutils:commonUsedTK  $theToolKit] {
1428     lappend aCommonUsedTK "${tkx}.lib"
1429   }
1430
1431   osutils:usedOsLibs $theToolKit "wnt" aLibs aFrameworks
1432   set aUsedToolKits [concat $aCommonUsedTK $aLibs]
1433
1434   # correct names of referred third-party libraries that are named with suffix
1435   # depending on VC version
1436   regsub -all -- {vc[0-9]+} $aUsedToolKits $theVcVer aUsedToolKits
1437
1438   # and put this list to project file
1439   #puts "$theToolKit requires  $aUsedToolKits"
1440   if { "$theVcVer" == "vc10" || "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1441     set aUsedToolKits [join $aUsedToolKits {;}]
1442   }
1443   regsub -all -- {__TKDEP__} $theProjTmpl $aUsedToolKits theProjTmpl
1444
1445   set anIncPaths "..\\..\\..\\inc"
1446   set aTKDefines ""
1447   set aFilesSection ""
1448   set aVcFilesX(units) ""
1449   set listloc [osutils:tk:units $theToolKit]
1450   set resultloc [osutils:justwnt $listloc]
1451   if [array exists written] { unset written }
1452   #puts "\t1 [wokparam -v %CMPLRS_CXX_Options [w_info -f]] father"
1453   #puts "\t2 [wokparam -v %CMPLRS_CXX_Options] branch"
1454   #puts "\t1 [wokparam -v %CMPLRS_C_Options [w_info -f]] father"
1455   #puts "\t2 [wokparam -v %CMPLRS_C_Options] branch"
1456   set fxloparamfcxx [lindex [osutils:intersect3 [_get_options wnt cmplrs_cxx f] [_get_options wnt cmplrs_cxx b]] 2]
1457   set fxloparamfc   [lindex [osutils:intersect3 [_get_options wnt cmplrs_c f] [_get_options wnt cmplrs_c b]] 2]
1458   set fxloparam ""
1459   foreach fxlo $resultloc {
1460     set xlo $fxlo
1461     set aSrcFiles [osutils:tk:files $xlo osutils:compilable 0]
1462         set fxlo_cmplrs_options_cxx [_get_options wnt cmplrs_cxx $fxlo]
1463     if {$fxlo_cmplrs_options_cxx == ""} {
1464       set fxlo_cmplrs_options_cxx [_get_options wnt cmplrs_cxx b]
1465     }
1466         set fxlo_cmplrs_options_c [_get_options wnt cmplrs_c $fxlo]
1467     if {$fxlo_cmplrs_options_c == ""} {
1468       set fxlo_cmplrs_options_c [_get_options wnt cmplrs_c b]
1469     }
1470     set fxloparam "$fxloparam [lindex [osutils:intersect3 [_get_options wnt cmplrs_cxx b] $fxlo_cmplrs_options_cxx] 2]"
1471     set fxloparam "$fxloparam [lindex [osutils:intersect3 [_get_options wnt cmplrs_c b] $fxlo_cmplrs_options_c] 2]"
1472         #puts "\t3 [wokparam -v %CMPLRS_CXX_Options] branch CXX "
1473         #puts "\t4 [wokparam -v %CMPLRS_CXX_Options $fxlo] $fxlo  CXX"
1474         #puts "\t5 [wokparam -v %CMPLRS_C_Options] branch C"
1475         #puts "\t6 [wokparam -v %CMPLRS_C_Options   $fxlo] $fxlo  C"
1476     set needparam ""
1477     foreach partopt $fxloparam {
1478       if {[string first "-I" $partopt] == "0"} {
1479         # this is an additional includes search path
1480         continue
1481       }
1482       set needparam "$needparam $partopt"
1483     }
1484
1485     # Format of projects in vc10 and vc11 is different from vc7-9
1486     if { "$theVcVer" == "vc10" || "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1487       foreach aSrcFile [lsort $aSrcFiles] {
1488         if { ![info exists written([file tail $aSrcFile])] } {
1489           set written([file tail $aSrcFile]) 1
1490           append aFilesSection [osutils:vcxproj:file $theVcVer $aSrcFile $needparam]
1491         } else {
1492           puts "Warning : in vcproj more than one occurences for [file tail $aSrcFile]"
1493         }
1494         if { ! [info exists aVcFilesX($xlo)] } { lappend aVcFilesX(units) $xlo }
1495         lappend aVcFilesX($xlo) $aSrcFile
1496       }
1497     } else {
1498       append aFilesSection "\t\t\t<Filter\n"
1499       append aFilesSection "\t\t\t\tName=\"${xlo}\"\n"
1500       append aFilesSection "\t\t\t\t>\n"
1501       foreach aSrcFile [lsort $aSrcFiles] {
1502         if { ![info exists written([file tail $aSrcFile])] } {
1503           set written([file tail $aSrcFile]) 1
1504           append aFilesSection [osutils:vcproj:file $theVcVer $aSrcFile $needparam]
1505         } else {
1506           puts "Warning : in vcproj more than one occurences for [file tail $aSrcFile]"
1507         }
1508       }
1509       append aFilesSection "\t\t\t</Filter>\n"
1510     }
1511
1512     # macros
1513     append aTKDefines ";__${xlo}_DLL"
1514     # common includes
1515 #    append anIncPaths ";..\\..\\..\\src\\${xlo}"
1516   }
1517
1518   regsub -all -- {__TKINC__}  $theProjTmpl $anIncPaths theProjTmpl
1519   regsub -all -- {__TKDEFS__} $theProjTmpl $aTKDefines theProjTmpl
1520   regsub -all -- {__FILES__}  $theProjTmpl $aFilesSection theProjTmpl
1521
1522   # write file
1523   set aFile [open [set aVcFiles [file join $theOutDir ${theToolKit}.[osutils:vcproj:ext $theVcVer]]] w]
1524   fconfigure $aFile -translation crlf
1525   puts $aFile $theProjTmpl
1526   close $aFile
1527
1528   # write filters file for vc10 and vc11
1529   if { "$theVcVer" == "vc10" } {
1530     lappend aVcFiles [osutils:vcxproj:filters $theOutDir $theToolKit aVcFilesX]
1531   } elseif { "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1532     lappend aVcFiles [osutils:vcx1proj:filters $theOutDir $theToolKit aVcFilesX]
1533   }
1534
1535   # write resource file
1536   lappend aVcFiles [osutils:readtemplate:rc $theOutDir $theToolKit]
1537
1538   return $aVcFiles
1539 }
1540
1541 # for a unit returns a map containing all its file in the current
1542 # workbench
1543 # local = 1 only local files
1544 proc osutils:tk:loadunit { loc map } {
1545   #puts $loc
1546   upvar $map TLOC
1547   catch { unset TLOC }
1548   set lfiles [_get_used_files $loc]
1549   foreach f $lfiles {
1550     #puts "\t$f"
1551     set t [lindex $f 0]
1552     set p [lindex $f 2]
1553     if [info exists TLOC($t)] {
1554       set l $TLOC($t)
1555       lappend l $p
1556       set TLOC($t) $l
1557     } else {
1558       set TLOC($t) $p
1559     }
1560   }
1561   return
1562 }
1563
1564 # Returns the list of all compilable files name in a toolkit, or devunit of any type
1565 # Call unit filter on units name to accept or reject a unit
1566 # Tfiles lists for each unit the type of file that can be compiled.
1567 proc osutils:tk:files { tkloc  {l_compilable {} } {justail 1} {unitfilter {}} } {
1568   global path
1569   set Tfiles(source,nocdlpack)     {source pubinclude}
1570   set Tfiles(source,toolkit)       {}
1571   set Tfiles(source,executable)    {source pubinclude}
1572   set listloc [concat [osutils:tk:units $tkloc] $tkloc]
1573   #puts " listloc = $listloc"
1574   if { $l_compilable == {} } {
1575     set l_comp [list .c .cxx .cpp]
1576   } else {
1577     set l_comp [$l_compilable]
1578   }
1579   if { $unitfilter == {} } {
1580     set resultloc $listloc
1581   } else {
1582     set resultloc [$unitfilter $listloc]
1583   }
1584   set lret {}
1585   foreach loc $resultloc {
1586     set utyp [_get_type $loc]
1587     #puts "\"$utyp\" \"$loc\""
1588     switch $utyp {
1589          "t" { set utyp "toolkit" }
1590          "n" { set utyp "nocdlpack" }
1591          "x" { set utyp "executable" }
1592     }
1593     if [array exists map] { unset map }
1594     osutils:tk:loadunit $loc map
1595     #puts " loc = $loc === > [array names map]"
1596     set LType $Tfiles(source,${utyp})
1597     foreach typ [array names map] {
1598       if { [lsearch $LType $typ] == -1 } {
1599         unset map($typ)
1600       }
1601     }
1602     foreach type [array names map] {
1603       #puts $type
1604       foreach f $map($type) {
1605         #puts $f
1606         if { [lsearch $l_comp [file extension $f]] != -1 } {
1607           if { $justail == 1 } {
1608             if {$type == "source"} {
1609               if {[lsearch $lret "@top_srcdir@/src/$loc/[file tail $f]"] == -1} {
1610                 lappend lret @top_srcdir@/src/$loc/[file tail $f]
1611               }
1612             }
1613           } else {
1614             lappend lret $f
1615           }
1616         }
1617       }
1618     }
1619   }
1620   return $lret
1621 }
1622
1623 # Generate Visual Studio project file for executable
1624 proc osutils:vcprojx { theVcVer theOutDir theToolKit theGuidsMap {theProjTmpl {} } } {
1625   global path
1626   set aVcFiles {}
1627   foreach f [osutils:tk:files $theToolKit osutils:compilable 0] {
1628     if { $theProjTmpl == {} } {
1629       set aProjTmpl [osutils:vcproj:readtemplate $theVcVer 1]
1630     } else {
1631       set aProjTmpl $theProjTmpl
1632     }
1633     set aProjName [file rootname [file tail $f]]
1634     set l_compilable [osutils:compilable]
1635     regsub -all -- {__XQTNAM__} $aProjTmpl $aProjName aProjTmpl
1636
1637     upvar $theGuidsMap aGuidsMap
1638     if { ! [info exists aGuidsMap($aProjName)] } {
1639       set aGuidsMap($aProjName) [OS:genGUID]
1640     }
1641     regsub -all -- {__PROJECT_GUID__} $aProjTmpl $aGuidsMap($aProjName) aProjTmpl
1642
1643     set aCommonUsedTK [list]
1644     foreach tkx [osutils:commonUsedTK  $theToolKit] {
1645       lappend aCommonUsedTK "${tkx}.lib"
1646     }
1647
1648     osutils:usedOsLibs $theToolKit "wnt" aLibs aFrameworks
1649     set aUsedToolKits [concat $aCommonUsedTK $aLibs]
1650
1651     # correct names of referred third-party libraries that are named with suffix
1652     # depending on VC version
1653     regsub -all -- {vc[0-9]+} $aUsedToolKits $theVcVer aUsedToolKits
1654
1655 #    puts "$aProjName requires  $aUsedToolKits"
1656     if { "$theVcVer" == "vc10" || "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1657       set aUsedToolKits [join $aUsedToolKits {;}]
1658     }
1659     regsub -all -- {__TKDEP__} $aProjTmpl $aUsedToolKits aProjTmpl
1660
1661     set aFilesSection ""
1662     set aVcFilesX(units) ""
1663
1664     if { ![info exists written([file tail $f])] } {
1665       set written([file tail $f]) 1
1666
1667       if { "$theVcVer" == "vc10" || "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1668         append aFilesSection [osutils:vcxproj:file $theVcVer $f ""]
1669         if { ! [info exists aVcFilesX($theToolKit)] } { lappend aVcFilesX(units) $theToolKit }
1670         lappend aVcFilesX($theToolKit) $f
1671       } else {
1672         append aFilesSection "\t\t\t<Filter\n"
1673         append aFilesSection "\t\t\t\tName=\"$theToolKit\"\n"
1674         append aFilesSection "\t\t\t\t>\n"
1675         append aFilesSection [osutils:vcproj:file $theVcVer $f ""]
1676         append aFilesSection "\t\t\t</Filter>"
1677       }
1678     } else {
1679       puts "Warning : in vcproj there are than one occurences for [file tail $f]"
1680     }
1681     #puts "$aProjTmpl $aFilesSection"
1682     set aTKDefines ";__${theToolKit}_DLL"
1683     set anIncPaths "..\\..\\..\\inc"
1684     regsub -all -- {__TKINC__}  $aProjTmpl $anIncPaths    aProjTmpl
1685     regsub -all -- {__TKDEFS__} $aProjTmpl $aTKDefines    aProjTmpl
1686     regsub -all -- {__FILES__}  $aProjTmpl $aFilesSection aProjTmpl
1687     regsub -all -- {__CONF__}   $aProjTmpl Application    aProjTmpl
1688
1689     regsub -all -- {__XQTEXT__} $aProjTmpl "exe" aProjTmpl
1690
1691     set aFile [open [set aVcFilePath [file join $theOutDir ${aProjName}.[osutils:vcproj:ext $theVcVer]]] w]
1692     fconfigure $aFile -translation crlf
1693     puts $aFile $aProjTmpl
1694     close $aFile
1695
1696     set aCommonSettingsFile "$aVcFilePath.user"
1697     lappend aVcFiles $aVcFilePath
1698
1699     # write filters file for vc10
1700     if { "$theVcVer" == "vc10" || "$theVcVer" == "vc11" || "$theVcVer" == "vc12" } {
1701       lappend aVcFiles [osutils:vcxproj:filters $theOutDir $aProjName aVcFilesX]
1702     }
1703
1704     set aCommonSettingsFileTmpl ""
1705     if { "$theVcVer" == "vc9" } {
1706       set aCommonSettingsFileTmpl "$path/adm/templates/vcproj.user.vc9x"
1707     } elseif { "$theVcVer" == "vc10" } {
1708       set aCommonSettingsFileTmpl "$path/adm/templates/vcxproj.user.vc10x"
1709     } elseif { "$theVcVer" == "vc11" } {
1710       set aCommonSettingsFileTmpl "$path/adm/templates/vcxproj.user.vc11x"
1711     } elseif { "$theVcVer" == "vc12" } {
1712       set aCommonSettingsFileTmpl "$path/adm/templates/vcxproj.user.vc12x"
1713     }
1714     if { "$aCommonSettingsFileTmpl" != "" } {
1715       file copy -force -- "$aCommonSettingsFileTmpl" "$aCommonSettingsFile"
1716       lappend aVcFiles "$aCommonSettingsFile"
1717     }
1718   }
1719   return $aVcFiles
1720 }
1721
1722 # Generate entry for one source file in Visual Studio 7 - 9 project file
1723 proc osutils:vcproj:file { theVcVer theFile theOptions } {
1724   append aText "\t\t\t\t<File\n"
1725   append aText "\t\t\t\t\tRelativePath=\"..\\..\\..\\[wokUtils:EASY:bs1 [wokUtils:FILES:wtail $theFile 3]]\">\n"
1726   if { $theOptions == "" } {
1727     append aText "\t\t\t\t</File>\n"
1728     return $aText
1729   }
1730
1731   append aText "\t\t\t\t\t<FileConfiguration\n"
1732   append aText "\t\t\t\t\t\tName=\"Release\|Win32\">\n"
1733   append aText "\t\t\t\t\t\t<Tool\n"
1734   append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
1735   append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
1736   foreach aParam $theOptions {
1737     append aText "$aParam "
1738   }
1739   append aText "\"\n"
1740   append aText "\t\t\t\t\t\t/>\n"
1741   append aText "\t\t\t\t\t</FileConfiguration>\n"
1742
1743   append aText "\t\t\t\t\t<FileConfiguration\n"
1744   append aText "\t\t\t\t\t\tName=\"Debug\|Win32\">\n"
1745   append aText "\t\t\t\t\t\t<Tool\n"
1746   append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
1747   append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
1748   foreach aParam $theOptions {
1749     append aText "$aParam "
1750   }
1751   append aText "\"\n"
1752   append aText "\t\t\t\t\t\t/>\n"
1753   append aText "\t\t\t\t\t</FileConfiguration>\n"
1754   if { "$theVcVer" == "vc7" } {
1755     append aText "\t\t\t\t</File>\n"
1756     return $aText
1757   }
1758
1759   append aText "\t\t\t\t\t<FileConfiguration\n"
1760   append aText "\t\t\t\t\t\tName=\"Release\|x64\">\n"
1761   append aText "\t\t\t\t\t\t<Tool\n"
1762   append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
1763   append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
1764   foreach aParam $theOptions {
1765     append aText "$aParam "
1766   }
1767   append aText "\"\n"
1768   append aText "\t\t\t\t\t\t/>\n"
1769   append aText "\t\t\t\t\t</FileConfiguration>\n"
1770
1771   append aText "\t\t\t\t\t<FileConfiguration\n"
1772   append aText "\t\t\t\t\t\tName=\"Debug\|x64\">\n"
1773   append aText "\t\t\t\t\t\t<Tool\n"
1774   append aText "\t\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n"
1775   append aText "\t\t\t\t\t\t\tAdditionalOptions=\""
1776   foreach aParam $theOptions {
1777     append aText "$aParam "
1778   }
1779   append aText "\"\n"
1780   append aText "\t\t\t\t\t\t/>\n"
1781   append aText "\t\t\t\t\t</FileConfiguration>\n"
1782
1783   append aText "\t\t\t\t</File>\n"
1784   return $aText
1785 }
1786
1787 ### AUTOMAKE ###############################################################################
1788 proc OS:MKAMK { theOutDir {theModules {}} theSubPath} {
1789   global path
1790   wokUtils:FILES:mkdir $theOutDir
1791
1792   foreach aModule $theModules {
1793     foreach aToolKit [$aModule:toolkits] {
1794       puts " toolkit: $aToolKit ==> $path/src/$aToolKit/EXTERNLIB"
1795       wokUtils:FILES:rmdir $theOutDir/$aToolKit
1796       wokUtils:FILES:mkdir $theOutDir/$aToolKit
1797       osutils:tk:mkam $theOutDir/$aToolKit $aToolKit
1798     }
1799     foreach anExecutable [OS:executable $aModule] {
1800       wokUtils:FILES:rmdir $theOutDir/$anExecutable
1801       wokUtils:FILES:mkdir $theOutDir/$anExecutable
1802       osutils:tk:mkamx $theOutDir/$anExecutable $anExecutable
1803     }
1804   }
1805   osutils:am:adm $theOutDir $theModules
1806   osutils:am:root $path $theSubPath $theModules
1807
1808   puts "The automake files are stored in the $theOutDir directory"
1809 }
1810
1811 proc wokUtils:FILES:rmdir { d } {
1812     global env
1813     global tcl_platform tcl_version  
1814     regsub -all {\.[^.]*} $tcl_version "" major
1815     if { $major == 8 } {
1816         file delete -force $d
1817     } else {
1818         if { "$tcl_platform(platform)" == "unix" } {
1819             catch { exec rm -rf $d}
1820         } else {
1821             
1822         }
1823     }
1824     return 
1825 }
1826
1827 proc wokUtils:FILES:mkdir { d } {
1828     global tcl_version
1829     regsub -all {\.[^.]*} $tcl_version "" major
1830     if { $major == 8 } {
1831         file mkdir $d
1832     } else {
1833         if ![file exists $d] {
1834             if { "[info command mkdir]" == "mkdir" } {
1835                 mkdir -path $d
1836             } else {
1837                 puts stderr "wokUtils:FILES:mkdir : Error unable to find a mkdir command."
1838             }
1839         }
1840     }
1841     if [file exists $d] {
1842         return $d
1843     } else {
1844         return {}
1845     }
1846 }
1847
1848 # "Nice letter: %s" { a b c } => {Nice letter: %a}  {Nice letter: %b} ..
1849 # as a string without backslash
1850 proc wokUtils:EASY:FmtSimple1 { fmt l {backslh 1} } {
1851     foreach e $l {
1852         if { $backslh } {
1853             append str [format $fmt $e] "\n"
1854         } else {
1855             append str [format $fmt $e]
1856         }
1857     }
1858     return $str
1859 }
1860
1861 # edit_last is performed ONCE fmt has been applied.
1862 proc wokUtils:EASY:FmtString2 { fmt l {yes_for_last 0} {edit_last {}} } {
1863     set ldeb [lrange $l 0 [expr [llength $l] -2]]
1864     set last [lrange $l end end]
1865     foreach e $ldeb {
1866         append str [format $fmt $e $e] " \\" "\n"
1867     }
1868
1869     if {$edit_last != {} } {
1870         set slast [$edit_last [format $fmt $last $last]]
1871     } else {
1872         set slast [format $fmt $last $last]
1873     }
1874
1875     if { $yes_for_last } {
1876         append str $slast " \\" "\n" 
1877     } else {
1878         append str $slast "\n"
1879     }
1880
1881     return $str
1882 }
1883
1884 # { a.x b.c c.v } => { a b c}
1885 proc wokUtils:LIST:sanspoint { l } {
1886     set rr {}
1887     foreach x $l {
1888         lappend rr [file root $x]
1889     }
1890     return $rr
1891 }
1892
1893 # remove from listloc OpenCascade units indesirables on Unix
1894 proc osutils:justunix { listloc } {
1895   if { "$::tcl_platform(os)" == "Darwin" } {
1896     set goaway [list Xw WNT]
1897   } else {
1898     set goaway [list WNT]
1899   }
1900   return [osutils:juststation $goaway $listloc]
1901 }
1902
1903 # remove ":" from last item of dependencies list in target VPATH of Makefile.am
1904 proc osutils:am:__VPATH__lastoccur { str } {
1905   if { [regsub {:$} $str "" u] != 0 } {
1906     return $u
1907   }
1908 }
1909
1910 #  ((((((((((((( Formats in Makefile.am )))))))))))))
1911 # Used to replace the string __VPATH__ in Makefile.am
1912 # l is the list of the units in a toolkit.
1913 proc osutils:am:__VPATH__ { l } {
1914   set fmt "@top_srcdir@/src/%s:"
1915   return [wokUtils:EASY:FmtString2 $fmt $l 0 osutils:am:__VPATH__lastoccur]
1916 }
1917
1918 # Used to replace the string __INCLUDES__ in Makefile.am
1919 # l is the list of packages in a toolkit.
1920 proc osutils:am:__INCLUDES__ { l } {
1921   set fmt "-I@top_srcdir@/src/%s"
1922   return [wokUtils:EASY:FmtString2 $fmt $l]
1923 }
1924
1925 # Used to replace the string __LIBADD__ in Makefile.am
1926 # l is the toolkit closure list of a toolkit.
1927 proc osutils:am:__LIBADD__ { theIncToolkits {final 0} } {
1928   global path
1929   global fBranch
1930   set aFatherModules ""
1931   set aCurrentWorkBench [file tail $path]
1932   if { $fBranch != "" } {
1933     set fd [open $fBranch/adm/UDLIST rb]
1934     set fileContent [split [read $fd] "\n"]
1935     close $fd
1936     set ftoolkits [lsearch -all -inline $fileContent "t *"]
1937     foreach ft $ftoolkits {
1938       set aFatherModules "$aFatherModules [string range $ft 2 end]"
1939     }
1940   }
1941   set aLibString ""
1942   foreach aIncToolkit $theIncToolkits {
1943     if { [lsearch [split $aFatherModules " "] $aIncToolkit] != -1} {
1944       append aLibString " \\\n-l$aIncToolkit"
1945     } else {
1946       append aLibString " \\\n../$aIncToolkit/lib$aIncToolkit.la"
1947     }
1948   }
1949   return $aLibString
1950 }
1951
1952 # Used to replace the string __SOURCES__ in Makefile.am
1953 # l is the list of all compilable files in a toolkit.
1954 proc osutils:am:__SOURCES__ { l } {
1955   set fmt "%s"
1956   return [wokUtils:EASY:FmtString1 $fmt $l]
1957 }
1958
1959 proc osutils:am:__CXXFLAG__ { l } {
1960   set fmt "%s"
1961   return [wokUtils:EASY:FmtString1 $fmt [osutils:am:PkCXXOption $l]]
1962 }
1963
1964 proc osutils:am:PkCXXOption { ppk } {
1965   global path
1966   #puts "\t 1 [lindex [wokparam -e  %CMPLRS_CXX_Options [wokcd]] 0]"
1967   set CXXCOMMON [_get_options lin cmplrs_cxx b]
1968   #puts "\t 2 [wokparam -v %CMPLRS_CXX_Options [w_info -f]]"
1969   #puts "\t 3 [wokparam -v %CMPLRS_CXX_Options]"
1970   set FoundFlag "[lindex [osutils:intersect3 [split [_get_options lin cmplrs_cxx f]] [split [_get_options lin cmplrs_cxx b]] ] 2]"
1971   foreach pk $ppk {
1972     #puts $pk
1973         if {![file isdirectory $path/src/$pk]} {
1974           continue
1975         }
1976     set src_files [_get_used_files $pk false]
1977     set only_src_files {}
1978     foreach s $src_files { 
1979       regexp {source ([^\s]+)} $s dummy name
1980       lappend only_src_files $name
1981     }
1982     if {[lsearch $only_src_files ${pk}_CMPLRS.edl] != "-1"} {
1983       set pk_cmplrs_cxx [_get_options lin cmplrs_cxx $pk]
1984       if {$pk_cmplrs_cxx == ""} {
1985             set pk_cmplrs_cxx [_get_options lin cmplrs_cxx b]
1986           }
1987       set CXXStr  $pk_cmplrs_cxx
1988           #puts "\t 4 [wokparam -e %CMPLRS_CXX_Options [woklocate -u $pk]] $pk"
1989       set LastIndex [expr {[string length $CXXCOMMON ] - 1}]
1990       if {[string equal $CXXCOMMON [string range $CXXStr 0 $LastIndex]]} {
1991         set CXXOption " "
1992       } else {
1993         set CXXOption [string range $CXXStr 0 [expr {[string last $CXXCOMMON $CXXStr] - 1}]]
1994       }
1995       if {$CXXOption != " " && $CXXOption != "" && $CXXOption != "  " && $CXXOption != "   "} {
1996         set FoundList [split $CXXOption " "]
1997         foreach elem $FoundList {
1998           if {$elem != ""} {
1999             if {[string first "-I" $elem] == "-1"  } {
2000               if {[string first $elem $FoundFlag] == "-1"} {
2001                 set FoundFlag "$FoundFlag $elem"
2002               }
2003             }
2004           }
2005         }
2006       }
2007     }
2008   }
2009   return $FoundFlag
2010 }
2011
2012 # Create in dir the Makefile.am associated with toolkit tkloc.
2013 # Returns the full path of the created file.
2014 proc osutils:tk:mkam { dir tkloc } {
2015   global path
2016   set pkgs $path/src/${tkloc}/PACKAGES
2017   if { ![file exists $pkgs] } {
2018     puts stderr "osutils:tk:mkam : Error. File PACKAGES not found for toolkit $tkloc."
2019     return {}
2020   }
2021
2022   set tmplat [osutils:readtemplate mam "Makefile.am"]
2023   set lpkgs  [osutils:justunix [wokUtils:FILES:FileToList $pkgs]]
2024   set close  [wokUtils:LIST:Purge [osutils:tk:close $tkloc]]
2025   set lsrc   [lsort [osutils:tk:files $tkloc osutils:compilable 1 osutils:justunix]]
2026   set lobj   [wokUtils:LIST:sanspoint $lsrc]
2027
2028   set lcsf   [osutils:tk:csfInExternlib $path/src/${tkloc}/EXTERNLIB]
2029
2030   set final 0
2031   set externinc ""
2032   set externlib ""
2033   if { $lcsf != {} } {
2034     set final 1
2035     set fmtinc "\$(%s_INCLUDES) "
2036     set fmtlib "\$(%s_LIB) "
2037     set externinc [wokUtils:EASY:FmtSimple1 $fmtinc $lcsf 0]
2038     set externlib [wokUtils:EASY:FmtSimple1 $fmtlib $lcsf 0]
2039   }
2040
2041   regsub -all -- {__TKNAM__} $tmplat $tkloc tmplat
2042   set vpath [osutils:am:__VPATH__ $lpkgs]
2043   regsub -all -- {__VPATH__} $tmplat $vpath tmplat
2044   set inclu [osutils:am:__INCLUDES__ $lpkgs]
2045   regsub -all -- {__INCLUDES__} $tmplat $inclu tmplat
2046   if { $close != {} } {
2047     set libadd [osutils:am:__LIBADD__ $close $final]
2048   } else {
2049     set libadd ""
2050   }
2051   regsub -all -- {__LIBADD__} $tmplat $libadd tmplat
2052   set source [osutils:am:__SOURCES__ $lsrc]
2053   regsub -all -- {__SOURCES__} $tmplat $source tmplat
2054   regsub -all -- {__EXTERNINC__} $tmplat $externinc tmplat
2055   set CXXFl [osutils:am:__CXXFLAG__ $lpkgs]
2056   regsub -all -- {__CXXFLAG__} $tmplat $CXXFl tmplat
2057   set CFl [osutils:am:__CFLAG__ $lpkgs]
2058   regsub -all -- {__CFLAG__} $tmplat $CFl tmplat
2059
2060   regsub -all -- {__EXTERNLIB__} $tmplat $externlib tmplat
2061
2062   wokUtils:FILES:StringToFile $tmplat [set fmam [file join $dir Makefile.am]]
2063   return [list $fmam]
2064 }
2065
2066 # Write a string in a file
2067 proc wokUtils:FILES:StringToFile { str path } {
2068     if { [catch { set out [ open $path w ] } errout] == 0 } {
2069         puts -nonewline $out $str
2070         close $out
2071         return 1
2072     } else {
2073         return {}
2074     }
2075 }
2076
2077 # Create in dir the Makefile.am associated with toolkit tkloc.
2078 # Returns the full path of the created file.
2079 proc osutils:tk:mkamx { dir tkloc } {
2080   global path
2081   set src_files [_get_used_files $tkloc false]
2082   set only_src_files {}
2083   foreach s $src_files { 
2084     regexp {source ([^\s]+)} $s dummy name
2085     lappend only_src_files $name
2086   }
2087   if { [lsearch $only_src_files ${tkloc}_WOKSteps.edl] != "-1"} {
2088     set pkgs "$path/src/${tkloc}/EXTERNLIB"
2089     if { $pkgs == {} } {
2090       puts stderr "osutils:tk:mkamx : Error. File EXTERNLIB not found for executable $tkloc."
2091       #return {}
2092     }
2093     set tmplat [osutils:readtemplate mamx "Makefile.am (executable)"]
2094     set close  [wokUtils:LIST:Purge [osutils:tk:close $tkloc]]
2095     set lsrc   [lsort [osutils:tk:files $tkloc osutils:compilable 1 osutils:justunix]]
2096     set lobj   [wokUtils:LIST:sanspoint $lsrc]
2097     set CXXList {}
2098     foreach SourceFile $only_src_files {
2099       if {[file extension $SourceFile] == ".cxx"} {
2100         lappend CXXList [file rootname $SourceFile]
2101       }
2102     }
2103     set pkgs [LibToLinkX $tkloc [lindex $CXXList 0]]
2104     set lpkgs  [osutils:justunix [wokUtils:FILES:FileToList $pkgs]]
2105     puts "pkgs $pkgs"
2106     #set lcsf   [osutils:tk:csfInExternlib [woklocate -p ${tkloc}:source:EXTERNLIB [wokcd]]]
2107
2108     set lcsf {}
2109     foreach tk $pkgs {
2110       foreach element [osutils:tk:csfInExternlib "$path/src/${tk}/EXTERNLIB"] {
2111         if {[lsearch $lcsf $element] == "-1"} {
2112           set lcsf [concat $lcsf $element]
2113         }
2114       }
2115     }
2116     set final 0
2117     set externinc ""
2118     set externlib ""
2119     if { $lcsf != {} } {
2120       set final 1
2121       set fmtinc "\$(%s_INCLUDES) "
2122       set fmtlib "\$(%s_LIB) "
2123       set externinc [wokUtils:EASY:FmtSimple1 $fmtinc $lcsf 0]
2124       set externlib [wokUtils:EASY:FmtSimple1 $fmtlib $lcsf 0]
2125     }
2126     regsub -all -- {__XQTNAM__} $tmplat $tkloc tmplat
2127     set tmplat "$tmplat \nlib_LTLIBRARIES="
2128     foreach entity $CXXList {
2129       set tmplat "$tmplat lib${entity}.la"
2130     }
2131     set tmplat "$tmplat\n"
2132     set inclu [osutils:am:__INCLUDES__ $lpkgs]
2133     regsub -all -- {__INCLUDES__} $tmplat $inclu tmplat
2134     if { $pkgs != {} } {
2135       set libadd [osutils:am:__LIBADD__ $pkgs $final]
2136     } else {
2137       set libadd ""
2138     }
2139     regsub -all -- {__LIBADD__} $tmplat $libadd tmplat
2140     set source [osutils:am:__SOURCES__ $CXXList]
2141     regsub -all -- {__SOURCES__} $tmplat $source tmplat
2142     regsub -all -- {__EXTERNINC__} $tmplat $externinc tmplat
2143     foreach entity $CXXList {
2144       set tmplat "$tmplat lib${entity}_la_SOURCES = @top_srcdir@/src/${tkloc}/${entity}.cxx \n"
2145     }
2146     foreach entity $CXXList {
2147       set tmplat "$tmplat lib${entity}_la_LIBADD = $libadd $externlib \n"
2148     }
2149     wokUtils:FILES:StringToFile $tmplat [set fmam [file join $dir Makefile.am]]
2150
2151     unset tmplat
2152
2153     return [list $fmam]
2154
2155   } else {
2156     set pkgs "$path/src/${tkloc}/EXTERNLIB"
2157     if { $pkgs == {} } {
2158       puts stderr "osutils:tk:mkamx : Error. File EXTERNLIB not found for executable $tkloc."
2159       #return {}
2160     }
2161     set tmplat [osutils:readtemplate mamx "Makefile.am (executable)"]
2162     set close  [wokUtils:LIST:Purge [osutils:tk:close $tkloc]]
2163     set lsrc   [lsort [osutils:tk:files $tkloc osutils:compilable 1 osutils:justunix]]
2164     set lobj   [wokUtils:LIST:sanspoint $lsrc]
2165     set CXXList {}
2166     foreach SourceFile $only_src_files {
2167       if {[file extension $SourceFile] == ".cxx"} {
2168         lappend CXXList [file rootname $SourceFile]
2169       }
2170     }
2171     set pkgs [LibToLinkX $tkloc [lindex $CXXList 0]]
2172     set lpkgs  [osutils:justunix [wokUtils:FILES:FileToList $pkgs]]
2173     set lcsf   [osutils:tk:csfInExternlib "$path/src/${tkloc}/EXTERNLIB"]
2174
2175     set lcsf {}
2176     foreach tk $pkgs {
2177       foreach element [osutils:tk:csfInExternlib "$path/src/${tk}/EXTERNLIB"] {
2178         if {[lsearch $lcsf $element] == "-1"} {
2179           set lcsf [concat $lcsf $element]
2180         }
2181       }
2182     }
2183     set final 0
2184     set externinc ""
2185     set externlib ""
2186     if { $lcsf != {} } {
2187       set final 1
2188       set fmtinc "\$(%s_INCLUDES) "
2189       set fmtlib "\$(%s_LIB) "
2190       set externinc [wokUtils:EASY:FmtSimple1 $fmtinc $lcsf 0]
2191       set externlib [wokUtils:EASY:FmtSimple1 $fmtlib $lcsf 0]
2192     }
2193     regsub -all -- {__XQTNAM__} $tmplat $tkloc tmplat
2194     set tmplat "$tmplat \nbin_PROGRAMS="
2195     foreach entity $CXXList {
2196       set tmplat "${tmplat} ${entity}"
2197     }
2198
2199     set tmplat "${tmplat}\n"
2200     set inclu [osutils:am:__INCLUDES__ $lpkgs]
2201     regsub -all -- {__INCLUDES__} $tmplat $inclu tmplat
2202     if { $pkgs != {} } {
2203       set libadd [osutils:am:__LIBADD__ $pkgs $final]
2204     } else {
2205       set libadd ""
2206     }
2207     set source [osutils:am:__SOURCES__ $CXXList]
2208     regsub -all -- {__SOURCES__} $tmplat $source tmplat
2209     regsub -all -- {__EXTERNINC__} $tmplat $externinc tmplat
2210     foreach entity $CXXList {
2211       set tmplat "$tmplat ${entity}_SOURCES = @top_srcdir@/src/${tkloc}/${entity}.cxx \n"
2212     }
2213     foreach entity $CXXList {
2214       set tmplat "$tmplat ${entity}_LDADD = $libadd $externlib \n"
2215     }
2216     wokUtils:FILES:StringToFile $tmplat [set fmam [file join $dir Makefile.am]]
2217
2218     return [list $fmam]
2219   }
2220 }
2221
2222 # Create in dir the Makefile.am in $dir directory.
2223 # Returns the full path of the created file.
2224 proc osutils:am:adm { dir {lesmodules {}} } {
2225   set amstring "srcdir = @srcdir@\n\n"
2226   set subdirs "SUBDIRS ="
2227   set vpath "VPATH = @srcdir@ ${dir}: "
2228   set make ""
2229   set phony ".PHONY:"
2230   foreach theModule $lesmodules {
2231     set units [osutils:tk:sort [$theModule:toolkits]]
2232     set units [concat $units [OS:executable $theModule]]
2233     append amstring "${theModule}_PKGS ="
2234     append vpath "\\\n"
2235     foreach unit $units {
2236       append amstring " ${unit}"
2237       append vpath "${dir}/${unit}: "
2238     }
2239     set up ${theModule}
2240     if { [info procs ${theModule}:alias] != "" } {
2241       set up [${theModule}:alias]
2242     }
2243     set up [string toupper ${up}]
2244     append amstring "\n\nif ENABLE_${up}\n"
2245     append amstring "  ${theModule}_DIRS = \$(${theModule}_PKGS)\n"
2246     append amstring "else\n"
2247     append amstring "  ${theModule}_DIRS = \n"
2248     append amstring "endif\n\n"
2249     append subdirs " \$(${theModule}_DIRS)"
2250     append make "${theModule}:\n"
2251     append make "\tfor d in \$(${theModule}_PKGS); do \\\n"
2252     append make "\t\tcd \$\$d; \$(MAKE) \$(AM_MAKEFLAGS) lib\$\$d.la; cd ..; \\\n"
2253     append make "\tdone\n\n"
2254     append phony " ${theModule}"
2255   }
2256   append amstring "$subdirs\n\n"
2257   append amstring "$vpath\n\n"
2258   append amstring $make
2259   append amstring $phony
2260   wokUtils:FILES:StringToFile $amstring [set fmam [file join $dir Makefile.am]]
2261   return [list $fmam]
2262 }
2263
2264 # retourne la liste de dependances de module.
2265 proc OS:lsdep { m } {
2266     set res {}
2267     set l [${m}:depends]
2268     if { $l != {} } {
2269         set res [concat $res $l]
2270         foreach h $l {
2271             set res [concat $res [OS:lsdep ${h}]]
2272         }
2273     }
2274     return $res
2275 }
2276
2277 # Create in dir the Makefile.am and configure.ac in CASROOT directory.
2278 # Returns the full path of the created file.
2279 proc osutils:am:root { dir theSubPath {lesmodules {}} } {
2280   global path
2281   set amstring "srcdir = @srcdir@\n\n"
2282   append amstring "SUBDIRS = ${theSubPath}\n\n"
2283   append amstring "VPATH = @srcdir@ @top_srcdir@/${theSubPath}: @top_srcdir@/${theSubPath}:\n\n"
2284
2285   set phony ".PHONY:"
2286
2287   set acstring [osutils:readtemplate ac "Makefile.am"]
2288   set enablestr ""
2289   set confstr ""
2290   set condstr ""
2291   set repstr ""
2292   set acconfstr ""
2293
2294   set exelocal "install-exec-local:\n"
2295   append exelocal "\t"
2296   append exelocal {$(INSTALL) -d $(prefix)/$(platform)}
2297   append exelocal "\n"
2298   foreach d {bin lib} {
2299     append exelocal "\t"
2300     append exelocal "if \[ -e \$(prefix)/${d} -a ! -e \$(prefix)/\$(platform)/${d} \]; then \\\n"
2301     append exelocal "\t\tcd \$(prefix)/\$(platform) && ln -s ../${d} ${d}; \\\n"
2302     append exelocal "\tfi\n"
2303   }
2304   append exelocal "\t"
2305   append exelocal {buildd=`pwd`; cd $(top_srcdir); sourced=`pwd`; cd $(prefix); installd=`pwd`; cd $$buildd;}
2306   append exelocal " \\\n"
2307   append exelocal "\t"
2308   append exelocal {if [ "$$installd" != "$$sourced" ]; then}
2309   append exelocal " \\\n"
2310   append exelocal "\t\t"
2311   append exelocal {$(INSTALL) -d $(prefix)/src;}
2312   append exelocal " \\\n"
2313   append exelocal "\t\t"
2314   append exelocal {cp -frL $(top_srcdir)/src $(prefix);}
2315   append exelocal " \\\n"
2316   append exelocal "\t\t"
2317   append exelocal {cp -frL $$buildd/config.h $(prefix);}
2318   append exelocal " \\\n"
2319   append exelocal "\t\tfor d in "
2320
2321   foreach theModule $lesmodules {
2322     append amstring "${theModule}_PKGS ="
2323     foreach r [${theModule}:ressources] {
2324       if { "[lindex $r 1]" == "r" } {
2325         append amstring " [lindex $r 2]"
2326       }
2327     }
2328     set up ${theModule}
2329     if { [info procs ${theModule}:alias] != "" } {
2330       set up [${theModule}:alias]
2331     }
2332     set up [string toupper ${up}]
2333     set lower ${theModule}
2334     if { [info procs ${theModule}:alias] != "" } {
2335       set lower [${theModule}:alias]
2336     }
2337     set lower [string tolower ${lower}]
2338
2339     append amstring "\n\nif ENABLE_${up}\n"
2340     append amstring "  ${theModule}_DIRS = \$(${theModule}_PKGS)\n"
2341     append amstring "else\n"
2342     append amstring "  ${theModule}_DIRS = \n"
2343     append amstring "endif\n\n"
2344     append amstring "${theModule}:\n"
2345     append amstring "\tcd \$(top_builddir)/${theSubPath} && \$(MAKE) \$(AM_MAKEFLAGS) ${theModule}\n\n"
2346     append phony " ${theModule}"
2347
2348     append exelocal " \$(${theModule}_DIRS)"
2349
2350     append enablestr "AC_ARG_ENABLE(\[${lower}\],\n"
2351     append enablestr "  \[AS_HELP_STRING(\[--disable-${lower}\],\[Disable ${theModule} components\])\],\n"
2352     append enablestr "  \[ENABLE_${up}=\${enableval}\],\[ENABLE_${up}=yes\])\n"
2353
2354     set deplist [OS:lsdep ${theModule}]
2355     set acdeplist {}
2356     if { [info procs ${theModule}:acdepends] != "" } {
2357       set acdeplist [${theModule}:acdepends]
2358     }
2359
2360     if { [llength $deplist] > 0 || [llength $acdeplist] > 0} {
2361       append confstr "if test \"xyes\" = \"x\$ENABLE_${up}\"; then\n"
2362     } else {
2363       append confstr "if test \"xyes\" != \"x\$ENABLE_${up}\"; then\n"
2364     }
2365     foreach dep $deplist {
2366       set dup ${dep}
2367       if { [info procs ${dep}:alias] != "" } {
2368         set dup [${dep}:alias]
2369       }
2370       set dup [string toupper ${dup}]
2371       append confstr "  if test \"xyes\" = \"x\$ENABLE_${up}\" -a \"xyes\" != \"x\$ENABLE_${dup}\"; then\n"
2372       append confstr "    AC_MSG_NOTICE(\[Disabling ${theModule}: not building ${dep} component\])\n"
2373       append confstr "    DISABLE_${up}_REASON=\"(${dep} component disabled)\"\n"
2374       append confstr "    ENABLE_${up}=no\n"
2375       append confstr "  fi\n"
2376     }
2377     foreach dep $acdeplist {
2378       append confstr "  if test \"xyes\" = \"x\$ENABLE_${up}\" -a \"xyes\" != \"x\$HAVE_${dep}\"; then\n"
2379       append confstr "    AC_MSG_NOTICE(\[Disabling ${theModule}: ${dep} not found\])\n"
2380       append confstr "    DISABLE_${up}_REASON=\"(${dep} not found)\"\n"
2381       append confstr "    ENABLE_${up}=no\n"
2382       append confstr "  fi\n"
2383     }
2384     if { [llength $deplist] > 0 || [llength $acdeplist] > 0 } {
2385       append confstr "else\n"
2386     }
2387     append confstr "  DISABLE_${up}_REASON=\"(Disabled)\"\n"
2388     append confstr "fi\n"
2389
2390     append condstr "AM_CONDITIONAL(\[ENABLE_${up}\], \[test \"xyes\" = \"x\$ENABLE_${up}\"\])\n"
2391     append repstr [format "echo \"%-*s  \$ENABLE_${up} \$DISABLE_${up}_REASON\"" 26 ${theModule}]
2392     append repstr "\n"
2393
2394     set units [$theModule:toolkits]
2395     set units [concat $units [OS:executable $theModule]]
2396     foreach unit $units {
2397       append acconfstr "${theSubPath}/${unit}/Makefile \\\n"
2398     }
2399   }
2400
2401   append exelocal "; do \\\n"
2402   append exelocal "\t\t\t"
2403   append exelocal {$(INSTALL) -d $(prefix)/src/$$d;}
2404   append exelocal " \\\n"
2405   append exelocal "\t\t\t"
2406   append exelocal {cp -frL $(top_srcdir)/src/$$d $(prefix)/src;}
2407   append exelocal " \\\n"
2408   append exelocal "\t\tdone; \\\n"
2409   append exelocal "\tfi\n"
2410   append exelocal "\t"
2411   append exelocal {if [ -e $(prefix)/src/config.h ]; then}
2412   append exelocal " \\\n"
2413   append exelocal "\t\t"
2414   append exelocal {unlink $(prefix)/src/config.h;}
2415   append exelocal " \\\n"
2416   append exelocal "\tfi\n"
2417   append exelocal "\t"
2418   append exelocal {cd $(prefix)/src && ln -s ../config.h config.h}
2419   append exelocal "\n"
2420   append exelocal "\t"
2421   append exelocal {cd $(top_srcdir) && cp *.sh $(prefix)}
2422   append exelocal "\n"
2423   append exelocal "\n"
2424
2425   append amstring $exelocal
2426   append amstring $phony
2427
2428   regsub -all -- {__ENABLEMODULES__} $acstring $enablestr acstring
2429   regsub -all -- {__CONFMODULES__} $acstring $confstr acstring
2430   regsub -all -- {__CONDMODULES__} $acstring $condstr acstring
2431   regsub -all -- {__REPMODULES__} $acstring $repstr acstring
2432   regsub -all -- {__ACCONFMODULES__} $acstring $acconfstr acstring
2433
2434   wokUtils:FILES:StringToFile $amstring [set fmam [file join $dir Makefile.am]]
2435   wokUtils:FILES:StringToFile $acstring [set fmam [file join $dir configure.ac]]
2436   file copy -force -- [file join $path/adm/templates build_configure] [file join $dir build_configure]
2437   file copy -force -- [file join $path/adm/templates acinclude.m4] [file join $dir acinclude.m4]
2438   file copy -force -- [file join $path/adm/templates custom.sh.in] [file join $dir custom.sh.in]
2439   return [list $fmam]
2440 }
2441
2442 proc wokUtils:EASY:FmtString1 { fmt l {yes_for_last 0} {edit_last {}} } {
2443     set ldeb [lrange $l 0 [expr [llength $l] -2]]
2444     set last [lrange $l end end]
2445     foreach e $ldeb {
2446         append str [format $fmt $e] " \\" "\n"
2447     }
2448
2449     if {$edit_last != {} } {
2450         set slast [$edit_last [format $fmt $last]]
2451     } else {
2452         set slast [format $fmt $last]
2453     }
2454
2455     if { $yes_for_last } {
2456         append str $slast " \\" "\n" 
2457     } else {
2458         append str $slast "\n"
2459     }
2460     return $str
2461 }
2462
2463 # Used to replace the string __CFLAG__ in Makefile.am
2464 # l is the list of all compilable files in a toolkit.
2465 proc osutils:am:__CFLAG__ { l } {
2466   set fmt "%s"
2467   return [wokUtils:EASY:FmtString1 $fmt [osutils:am:PkCOption $l]]
2468 }
2469
2470 proc osutils:am:PkCOption { ppk } {
2471   global path
2472   #puts "\t\t $ppk"
2473   #puts "\t 5 [lindex [wokparam -e  %CMPLRS_C_Options [wokcd]] 0]"
2474   set CCOMMON [_get_options lin cmplrs_c b]
2475   #puts "\t 6 [lindex [wokparam -v %CMPLRS_C_Options [w_info -f]] 0]"
2476   set FoundFlag "[lindex [osutils:intersect3 [split [_get_options lin cmplrs_c f]] [split [_get_options lin cmplrs_c b]]] 2]"
2477   foreach pk $ppk {
2478     if {![file isdirectory $path/src/$pk]} {
2479           continue
2480         }
2481         set src_files [_get_used_files $pk false]
2482     set only_src_files {}
2483     foreach s $src_files {
2484       regexp {source ([^\s]+)} $s dummy name
2485       lappend only_src_files $name
2486     }
2487     if {[lsearch $src_files ${pk}_CMPLRS.edl] != "-1"} {
2488           #puts "\t 7 [lindex [wokparam -e %CMPLRS_C_Options [woklocate -u $pk]] 0] $pk"
2489       set aPkList   [split "[_get_options lin cmplrs_c $pk]" " "]
2490       set aCcomList [split "$CCOMMON" " "]
2491
2492       foreach aPkItem $aPkList {
2493         if { [lsearch aCcomList $aPkItem] != -1 } {
2494           if {[string first "-I" $aPkItem] == "-1"  } {
2495             set FoundFlag "$FoundFlag $aPkItem"
2496           }
2497         }
2498       }
2499     }
2500   }
2501   return $FoundFlag
2502 }
2503
2504 proc osutils:tksrcfiles { theUnits  theRelatedPath {theCompatible {}} } {
2505   set aTKSrcFiles [list]
2506
2507   if [array exists written] { unset written }
2508   foreach anUnit $theUnits {
2509     set xlo       $anUnit
2510     set aSrcFiles [osutils:tk:files $xlo osutils:compilable 0]
2511
2512     if { $theCompatible != {} } {
2513       set aSrcFiles [osutils:tk:files $xlo $theCompatible 0]
2514     }
2515
2516     foreach aSrcFile [lsort $aSrcFiles] {
2517       if { ![info exists written([file tail $aSrcFile])] } {
2518         set written([file tail $aSrcFile]) 1
2519         lappend aTKSrcFiles "${theRelatedPath}/[wokUtils:FILES:wtail $aSrcFile 3]"
2520       } else {
2521         puts "Warning : more than one occurences for [file tail $aSrcFile]"
2522       }
2523     }
2524   }
2525
2526   return $aTKSrcFiles
2527 }
2528
2529 proc osutils:mm_compilable { } {
2530   return [list .mm]
2531 }
2532
2533 proc osutils:tkdefs { theUnits } {
2534   set aTKDefines [list]
2535
2536   foreach anUnit $theUnits {
2537     lappend aTKDefines "__${anUnit}_DLL"
2538   }
2539
2540   return $aTKDefines
2541 }
2542
2543 proc osutils:fileGroupName { theSrcFile } {
2544   set path [file dirname [file normalize ${theSrcFile}]]
2545   regsub -all [file normalize "${path}/.."] ${path} "" aGroupName
2546
2547   return $aGroupName
2548 }
2549
2550
2551 ####### CODEBLOCK ###################################################################
2552 # Function to generate Code Blocks workspace and project files
2553 proc OS:MKCBP { theOutDir {theModules {}} {theAllSolution ""} } {
2554   puts stderr "Generating project files for Code Blocks"
2555
2556   # Generate projects for toolkits and separate workspace for each module
2557   foreach aModule $theModules {
2558     OS:cworkspace $aModule $aModule $theOutDir
2559     OS:cbp        $aModule          $theOutDir
2560   }
2561
2562   # Generate single workspace "OCCT" containing projects from all modules
2563   if { "$theAllSolution" != "" } {
2564     OS:cworkspace $theAllSolution $theModules $theOutDir
2565   }
2566
2567   puts "The Code Blocks workspace and project files are stored in the $theOutDir directory"
2568 }
2569
2570 # Generate Code Blocks projects
2571 proc OS:cbp { theModules theOutDir } {
2572   set aProjectFiles {}
2573   foreach aModule $theModules {
2574     foreach aToolKit [${aModule}:toolkits] {
2575       lappend aProjectFiles [osutils:cbptk $theOutDir $aToolKit ]
2576     }
2577     foreach anExecutable [OS:executable ${aModule}] {
2578       lappend aProjectFiles [osutils:cbpx  $theOutDir $anExecutable]
2579     }
2580   }
2581   return $aProjectFiles
2582 }
2583
2584 # Generate Code::Blocks project file for ToolKit
2585 proc osutils:cbptk { theOutDir theToolKit } {
2586   set aUsedToolKits [list]
2587   set aFrameworks   [list]
2588   set anIncPaths    [list]
2589   set aTKDefines    [list]
2590   set aTKSrcFiles   [list]
2591
2592   osutils:tkinfo "../../.." $theToolKit aUsedToolKits aFrameworks anIncPaths aTKDefines aTKSrcFiles
2593
2594   return [osutils:cbp $theOutDir $theToolKit $aTKSrcFiles $aUsedToolKits $aFrameworks $anIncPaths $aTKDefines]
2595 }
2596
2597 # Generates Code Blocks workspace.
2598 proc OS:cworkspace { theSolName theModules theOutDir } {
2599   global path
2600   set aWsFilePath "${theOutDir}/${theSolName}.workspace"
2601   set aFile [open $aWsFilePath "w"]
2602   set isActiveSet 0
2603   puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
2604   puts $aFile "<CodeBlocks_workspace_file>"
2605   puts $aFile "\t<Workspace title=\"${theSolName}\">"
2606
2607   # collect list of projects to be created
2608   foreach aModule $theModules {
2609     # toolkits
2610     foreach aToolKit [osutils:tk:sort [${aModule}:toolkits]] {
2611       set aDependencies [LibToLink $aToolKit]
2612       if { [llength $aDependencies] == 0 } {
2613         puts $aFile "\t\t<Project filename=\"${aToolKit}.cbp\" />"
2614       } else {
2615         puts $aFile "\t\t<Project filename=\"${aToolKit}.cbp\" >"
2616         foreach aDepTk $aDependencies {
2617           puts $aFile "\t\t\t<Depends filename=\"${aDepTk}.cbp\" />"
2618         }
2619         puts $aFile "\t\t</Project>"
2620       }
2621     }
2622
2623     # executables, assume one project per cxx file...
2624     foreach aUnit [OS:executable ${aModule}] {
2625       set aUnitLoc $aUnit
2626       set src_files [_get_used_files $aUnit false]
2627       set aSrcFiles {}
2628       foreach s $src_files { 
2629         regexp {source ([^\s]+)} $s dummy name
2630         lappend aSrcFiles $name
2631       }
2632       foreach aSrcFile $aSrcFiles {
2633         set aFileExtension [file extension $aSrcFile]
2634         if { $aFileExtension == ".cxx" } {
2635           set aPrjName [file rootname $aSrcFile]
2636           set aDependencies [list]
2637           if {[file isdirectory $path/src/$aUnitLoc]} {
2638             set aDependencies [LibToLinkX $aUnitLoc [file rootname $aSrcFile]]
2639           }
2640           set anActiveState ""
2641           if { $isActiveSet == 0 } {
2642             set anActiveState " active=\"1\""
2643             set isActiveSet 1
2644           }
2645           if { [llength $aDependencies] == 0 } {
2646             puts $aFile "\t\t<Project filename=\"${aPrjName}.cbp\"${anActiveState}/>"
2647           } else {
2648             puts $aFile "\t\t<Project filename=\"${aPrjName}.cbp\"${anActiveState}>"
2649             foreach aDepTk $aDependencies {
2650               puts $aFile "\t\t\t<Depends filename=\"${aDepTk}.cbp\" />"
2651             }
2652             puts $aFile "\t\t</Project>"
2653           }
2654         }
2655       }
2656     }
2657   }
2658
2659   puts $aFile "\t</Workspace>"
2660   puts $aFile "</CodeBlocks_workspace_file>"
2661   close $aFile
2662
2663   return $aWsFilePath
2664 }
2665
2666 # Generate Code::Blocks project file for Executable
2667 proc osutils:cbpx { theOutDir theToolKit } {
2668   global path targetStation
2669   set aWokStation "$targetStation"
2670   set aWokArch    "$::env(ARCH)"
2671
2672   set aCbpFiles {}
2673   foreach aSrcFile [osutils:tk:files $theToolKit osutils:compilable 0] {
2674     # collect list of referred libraries to link with
2675     set aUsedToolKits [list]
2676     set aFrameworks   [list]
2677     set anIncPaths    [list]
2678     set aTKDefines    [list]
2679     set aTKSrcFiles   [list]
2680     set aProjName [file rootname [file tail $aSrcFile]]
2681
2682     osutils:usedOsLibs $theToolKit "$aWokStation" aUsedToolKits aFrameworks
2683     set aDepToolkits [LibToLinkX $theToolKit $aProjName]
2684     foreach tkx $aDepToolkits {
2685       if {[_get_type $tkx] == "t"} {
2686         lappend aUsedToolKits "${tkx}"
2687       }
2688       if {[lsearch [glob -tails -directory "$path/src" -types d *] $tkx] == "-1"} {
2689         lappend aUsedToolKits "${tkx}"
2690       }
2691     }
2692
2693     set WOKSteps_exec_link [_get_options lin WOKSteps_exec_link $theToolKit]
2694     if { [regexp {WOKStep_DLLink} $WOKSteps_exec_link] || [regexp {WOKStep_Libink} $WOKSteps_exec_link] } {
2695       set isExecutable "false"
2696     } else {
2697       set isExecutable "true"
2698     }
2699
2700     if { ![info exists written([file tail $aSrcFile])] } {
2701       set written([file tail $aSrcFile]) 1
2702       lappend aTKSrcFiles $aSrcFile
2703     } else {
2704       puts "Warning : in cbp there are more than one occurences for [file tail $aSrcFile]"
2705     }
2706
2707     # macros for correct DLL exports
2708     if { "$aWokStation" == "wnt" } {
2709       lappend aTKDefines "__${theToolKit}_DLL"
2710     }
2711
2712     # common include paths
2713     lappend anIncPaths "../../../inc"
2714
2715     # extra macros
2716     lappend aTKDefines "CSFDB"
2717     if { "$aWokStation" == "wnt" } {
2718       lappend aTKDefines "WNT"
2719       lappend aTKDefines "_CRT_SECURE_NO_DEPRECATE"
2720     } else {
2721       if { "$aWokStation" == "lin" } {
2722         lappend aTKDefines "LIN"
2723       }
2724       lappend aTKDefines "OCC_CONVERT_SIGNALS"
2725       #lappend aTKDefines "_GNU_SOURCE=1"
2726     }
2727
2728     lappend aCbpFiles [osutils:cbp $theOutDir $aProjName $aTKSrcFiles $aUsedToolKits $aFrameworks $anIncPaths $aTKDefines $isExecutable]
2729   }
2730
2731   return $aCbpFiles
2732 }
2733
2734 proc osutils:optinal_libs { } {
2735   return [list tbb.lib tbbmalloc.lib FreeImage.lib FreeImagePlus.lib gl2ps.lib]
2736 }
2737
2738 # This function intended to generate Code::Blocks project file
2739 # @param theOutDir     - output directory to place project file
2740 # @param theProjName   - project name
2741 # @param theSrcFiles   - list of source files
2742 # @param theLibsList   - dependencies (libraries  list)
2743 # @param theFrameworks - dependencies (frameworks list, Mac OS X specific)
2744 # @param theIncPaths   - header search paths
2745 # @param theDefines    - compiler macro definitions
2746 # @param theIsExe      - flag to indicate executable / library target
2747 proc osutils:cbp { theOutDir theProjName theSrcFiles theLibsList theFrameworks theIncPaths theDefines {theIsExe "false"} } {
2748   global targetStation
2749   set aWokStation "$targetStation"
2750   set aWokArch    "$::env(ARCH)"
2751
2752   set aCbpFilePath "${theOutDir}/${theProjName}.cbp"
2753   set aFile [open $aCbpFilePath "w"]
2754   puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>"
2755   puts $aFile "<CodeBlocks_project_file>"
2756   puts $aFile "\t<FileVersion major=\"1\" minor=\"6\" />"
2757   puts $aFile "\t<Project>"
2758   puts $aFile "\t\t<Option title=\"$theProjName\" />"
2759   puts $aFile "\t\t<Option pch_mode=\"2\" />"
2760   if { "$aWokStation" == "wnt" } {
2761     puts $aFile "\t\t<Option compiler=\"msvc8\" />"
2762   } else {
2763     puts $aFile "\t\t<Option compiler=\"gcc\" />"
2764   }
2765   puts $aFile "\t\t<Build>"
2766
2767   # Release target configuration
2768   puts $aFile "\t\t\t<Target title=\"Release\">"
2769   if { "$theIsExe" == "true" } {
2770     puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/bin/${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2771     puts $aFile "\t\t\t\t<Option type=\"1\" />"
2772   } else {
2773     if { "$aWokStation" == "wnt" } {
2774       puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/lib/${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2775     } else {
2776       puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/lib/lib${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2777     }
2778     puts $aFile "\t\t\t\t<Option type=\"3\" />"
2779   }
2780   puts $aFile "\t\t\t\t<Option object_output=\"../../../${aWokStation}/cbp/obj\" />"
2781   if { "$aWokStation" == "wnt" } {
2782     puts $aFile "\t\t\t\t<Option compiler=\"msvc8\" />"
2783   } else {
2784     puts $aFile "\t\t\t\t<Option compiler=\"gcc\" />"
2785   }
2786   puts $aFile "\t\t\t\t<Option createDefFile=\"1\" />"
2787   puts $aFile "\t\t\t\t<Option createStaticLib=\"1\" />"
2788
2789   # compiler options per TARGET (including defines)
2790   puts $aFile "\t\t\t\t<Compiler>"
2791   if { "$aWokStation" == "wnt" } {
2792     puts $aFile "\t\t\t\t\t<Add option=\"-MD\" />"
2793     puts $aFile "\t\t\t\t\t<Add option=\"-arch:SSE2\" />"
2794     puts $aFile "\t\t\t\t\t<Add option=\"-EHsc\" />"
2795     puts $aFile "\t\t\t\t\t<Add option=\"-O2\" />"
2796     puts $aFile "\t\t\t\t\t<Add option=\"-W4\" />"
2797     puts $aFile "\t\t\t\t\t<Add option=\"-MP\" />"
2798   } else {
2799     puts $aFile "\t\t\t\t\t<Add option=\"-O2\" />"
2800     puts $aFile "\t\t\t\t\t<Add option=\"-mmmx\" />"
2801     puts $aFile "\t\t\t\t\t<Add option=\"-msse\" />"
2802     puts $aFile "\t\t\t\t\t<Add option=\"-msse2\" />"
2803     puts $aFile "\t\t\t\t\t<Add option=\"-mfpmath=sse\" />"
2804   }
2805   foreach aMacro $theDefines {
2806     puts $aFile "\t\t\t\t\t<Add option=\"-D${aMacro}\" />"
2807   }
2808   puts $aFile "\t\t\t\t\t<Add option=\"-DNDEBUG\" />"
2809   puts $aFile "\t\t\t\t\t<Add option=\"-DNo_Exception\" />"
2810
2811   puts $aFile "\t\t\t\t</Compiler>"
2812
2813   puts $aFile "\t\t\t\t<Linker>"
2814   puts $aFile "\t\t\t\t\t<Add directory=\"../../../${aWokStation}/cbp/lib\" />"
2815   if { "$aWokStation" == "mac" && [ lsearch $theLibsList X11 ] >= 0} {
2816     puts $aFile "\t\t\t\t\t<Add directory=\"/usr/X11/lib\" />"
2817   }
2818   puts $aFile "\t\t\t\t\t<Add option=\"\$(CSF_OPT_LNK${aWokArch})\" />"
2819   puts $aFile "\t\t\t\t</Linker>"
2820
2821   puts $aFile "\t\t\t</Target>"
2822
2823   # Debug target configuration
2824   puts $aFile "\t\t\t<Target title=\"Debug\">"
2825   if { "$theIsExe" == "true" } {
2826     puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/bind/${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2827     puts $aFile "\t\t\t\t<Option type=\"1\" />"
2828   } else {
2829     if { "$aWokStation" == "wnt" } {
2830       puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/libd/${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2831     } else {
2832       puts $aFile "\t\t\t\t<Option output=\"../../../${aWokStation}/cbp/libd/lib${theProjName}\" prefix_auto=\"1\" extension_auto=\"1\" />"
2833     }
2834     puts $aFile "\t\t\t\t<Option type=\"3\" />"
2835   }
2836   puts $aFile "\t\t\t\t<Option object_output=\"../../../${aWokStation}/cbp/objd\" />"
2837   if { "$aWokStation" == "wnt" } {
2838     puts $aFile "\t\t\t\t<Option compiler=\"msvc8\" />"
2839   } else {
2840     puts $aFile "\t\t\t\t<Option compiler=\"gcc\" />"
2841   }
2842   puts $aFile "\t\t\t\t<Option createDefFile=\"1\" />"
2843   puts $aFile "\t\t\t\t<Option createStaticLib=\"1\" />"
2844
2845   # compiler options per TARGET (including defines)
2846   puts $aFile "\t\t\t\t<Compiler>"
2847   if { "$aWokStation" == "wnt" } {
2848     puts $aFile "\t\t\t\t\t<Add option=\"-MDd\" />"
2849     puts $aFile "\t\t\t\t\t<Add option=\"-arch:SSE2\" />"
2850     puts $aFile "\t\t\t\t\t<Add option=\"-EHsc\" />"
2851     puts $aFile "\t\t\t\t\t<Add option=\"-Od\" />"
2852     puts $aFile "\t\t\t\t\t<Add option=\"-Zi\" />"
2853     puts $aFile "\t\t\t\t\t<Add option=\"-W4\" />"
2854     puts $aFile "\t\t\t\t\t<Add option=\"-MP\" />"
2855   } else {
2856     puts $aFile "\t\t\t\t\t<Add option=\"-O0\" />"
2857     puts $aFile "\t\t\t\t\t<Add option=\"-g\" />"
2858     puts $aFile "\t\t\t\t\t<Add option=\"-mmmx\" />"
2859     puts $aFile "\t\t\t\t\t<Add option=\"-msse\" />"
2860     puts $aFile "\t\t\t\t\t<Add option=\"-msse2\" />"
2861     puts $aFile "\t\t\t\t\t<Add option=\"-mfpmath=sse\" />"
2862   }
2863   foreach aMacro $theDefines {
2864     puts $aFile "\t\t\t\t\t<Add option=\"-D${aMacro}\" />"
2865   }
2866   puts $aFile "\t\t\t\t\t<Add option=\"-D_DEBUG\" />"
2867   puts $aFile "\t\t\t\t\t<Add option=\"-DDEB\" />"
2868   puts $aFile "\t\t\t\t</Compiler>"
2869
2870   puts $aFile "\t\t\t\t<Linker>"
2871   puts $aFile "\t\t\t\t\t<Add directory=\"../../../${aWokStation}/cbp/libd\" />"
2872   if { "$aWokStation" == "mac" && [ lsearch $theLibsList X11 ] >= 0} {
2873     puts $aFile "\t\t\t\t\t<Add directory=\"/usr/X11/lib\" />"
2874   }
2875   puts $aFile "\t\t\t\t\t<Add option=\"\$(CSF_OPT_LNK${aWokArch}D)\" />"
2876   puts $aFile "\t\t\t\t</Linker>"
2877
2878   puts $aFile "\t\t\t</Target>"
2879
2880   puts $aFile "\t\t</Build>"
2881
2882   # COMMON compiler options
2883   puts $aFile "\t\t<Compiler>"
2884   puts $aFile "\t\t\t<Add option=\"-Wall\" />"
2885   puts $aFile "\t\t\t<Add option=\"-fexceptions\" />"
2886   puts $aFile "\t\t\t<Add option=\"-fPIC\" />"
2887   puts $aFile "\t\t\t<Add option=\"\$(CSF_OPT_CMPL)\" />"
2888   foreach anIncPath $theIncPaths {
2889     puts $aFile "\t\t\t<Add directory=\"$anIncPath\" />"
2890   }
2891   puts $aFile "\t\t</Compiler>"
2892
2893   # COMMON linker options
2894   puts $aFile "\t\t<Linker>"
2895   foreach aFrameworkName $theFrameworks {
2896     if { "$aFrameworkName" != "" } {
2897       puts $aFile "\t\t\t<Add option=\"-framework $aFrameworkName\" />"
2898     }
2899   }
2900   foreach aLibName $theLibsList {
2901     if { "$aLibName" != "" } {
2902       puts $aFile "\t\t\t<Add library=\"$aLibName\" />"
2903     }
2904   }
2905   puts $aFile "\t\t</Linker>"
2906
2907   # list of sources
2908   foreach aSrcFile $theSrcFiles {
2909     if {[string equal -nocase [file extension $aSrcFile] ".mm"]} {
2910       puts $aFile "\t\t<Unit filename=\"$aSrcFile\">"
2911       puts $aFile "\t\t\t<Option compile=\"1\" />"
2912       puts $aFile "\t\t\t<Option link=\"1\" />"
2913       puts $aFile "\t\t</Unit>"
2914     } elseif {[string equal -nocase [file extension $aSrcFile] ".c"]} {
2915       puts $aFile "\t\t<Unit filename=\"$aSrcFile\">"
2916       puts $aFile "\t\t\t<Option compilerVar=\"CC\" />"
2917       puts $aFile "\t\t</Unit>"
2918     } else {
2919       puts $aFile "\t\t<Unit filename=\"$aSrcFile\" />"
2920     }
2921   }
2922
2923   puts $aFile "\t</Project>"
2924   puts $aFile "</CodeBlocks_project_file>"
2925   close $aFile
2926
2927   return $aCbpFilePath
2928 }
2929
2930 # Auxiliary function to achieve complete information to build Toolkit
2931 # @param theRelativePath - relative path to CASROOT
2932 # @param theToolKit      - Toolkit name
2933 # @param theUsedLib      - dependencies (libraries  list)
2934 # @param theFrameworks   - dependencies (frameworks list, Mac OS X specific)
2935 # @param theIncPaths     - header search paths
2936 # @param theTKDefines    - compiler macro definitions
2937 # @param theTKSrcFiles   - list of source files
2938 proc osutils:tkinfo { theRelativePath theToolKit theUsedLib theFrameworks theIncPaths theTKDefines theTKSrcFiles } {
2939   global path targetStation
2940   set aWokStation "$targetStation"
2941
2942   # collect list of referred libraries to link with
2943   upvar $theUsedLib    aUsedLibs
2944   upvar $theFrameworks aFrameworks
2945   upvar $theIncPaths   anIncPaths
2946   upvar $theTKDefines  aTKDefines
2947   upvar $theTKSrcFiles aTKSrcFiles
2948
2949   osutils:usedOsLibs $theToolKit "$aWokStation" aUsedLibs aFrameworks
2950   set aDepToolkits [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]]
2951   foreach tkx $aDepToolkits {
2952     lappend aUsedLibs "${tkx}"
2953   }
2954
2955   lappend anIncPaths "$theRelativePath/inc"
2956   set listloc [osutils:tk:units $theToolKit]
2957
2958   if { [llength $listloc] == 0 } {
2959     set listloc $theToolKit
2960   }
2961
2962   if { "$aWokStation" == "wnt" } {
2963     set resultloc [osutils:justwnt  $listloc]
2964   } else {
2965     set resultloc [osutils:justunix $listloc]
2966   }
2967   if [array exists written] { unset written }
2968   foreach fxlo $resultloc {
2969     set xlo       $fxlo
2970     set aSrcFiles [osutils:tk:files $xlo osutils:compilable 0]
2971     foreach aSrcFile [lsort $aSrcFiles] {
2972       if { ![info exists written([file tail $aSrcFile])] } {
2973         set written([file tail $aSrcFile]) 1
2974         lappend aTKSrcFiles "${theRelativePath}/[wokUtils:FILES:wtail $aSrcFile 3]"
2975       } else {
2976         puts "Warning : more than one occurences for [file tail $aSrcFile]"
2977       }
2978     }
2979
2980     # macros for correct DLL exports
2981     if { "$aWokStation" == "wnt" } {
2982       lappend aTKDefines "__${xlo}_DLL"
2983     }
2984
2985     # common include paths
2986 #    lappend anIncPaths "${theRelativePath}/src/${xlo}"
2987   }
2988
2989   # extra macros
2990   lappend aTKDefines "CSFDB"
2991   if { "$aWokStation" == "wnt" } {
2992     lappend aTKDefines "WNT"
2993     lappend aTKDefines "_CRT_SECURE_NO_DEPRECATE"
2994   } else {
2995     if { "$aWokStation" == "lin" } {
2996       lappend aTKDefines "LIN"
2997     }
2998     lappend aTKDefines "OCC_CONVERT_SIGNALS"
2999     #lappend aTKDefines "_GNU_SOURCE=1"
3000   }
3001 }
3002
3003 # Define libraries to link using only EXTERNLIB file
3004 proc LibToLinkX {thePackage theDummyName} {
3005   set aToolKits [LibToLink $thePackage]
3006   return $aToolKits
3007 }
3008
3009 # Function to generate Xcode workspace and project files
3010 proc OS:MKXCD { theOutDir {theModules {}} {theAllSolution ""} {theLibType "dynamic"} {thePlatform ""} } {
3011
3012   puts stderr "Generating project files for Xcode"
3013
3014   # Generate projects for toolkits and separate workspace for each module
3015   foreach aModule $theModules {
3016     OS:xcworkspace $aModule $aModule $theOutDir
3017     OS:xcodeproj   $aModule          $theOutDir ::THE_GUIDS_LIST $theLibType $thePlatform
3018   }
3019
3020   # Generate single workspace "OCCT" containing projects from all modules
3021   if { "$theAllSolution" != "" } {
3022     OS:xcworkspace $theAllSolution $theModules $theOutDir
3023   }
3024 }
3025
3026 # Generates toolkits sections for Xcode workspace file.
3027 proc OS:xcworkspace:toolkits { theModule } {
3028   set aBuff ""
3029
3030   # Adding toolkits for module in workspace.
3031   foreach aToolKit [osutils:tk:sort [${theModule}:toolkits]] {
3032     append aBuff "         <FileRef\n"
3033     append aBuff "            location = \"group:${aToolKit}.xcodeproj\">\n"
3034     append aBuff "         </FileRef>\n"
3035   }
3036
3037   # Adding executables for module, assume one project per cxx file...
3038   foreach aUnit [OS:executable ${theModule}] {
3039     set aUnitLoc $aUnit
3040     set src_files [_get_used_files $aUnit false]
3041     set aSrcFiles {}
3042     foreach s $src_files {
3043       regexp {source ([^\s]+)} $s dummy name
3044       lappend aSrcFiles $name
3045     }
3046     foreach aSrcFile $aSrcFiles {
3047       set aFileExtension [file extension $aSrcFile]
3048       if { $aFileExtension == ".cxx" } {
3049         set aPrjName [file rootname $aSrcFile]
3050         append aBuff "         <FileRef\n"
3051         append aBuff "            location = \"group:${aPrjName}.xcodeproj\">\n"
3052         append aBuff "         </FileRef>\n"
3053       }
3054     }
3055   }
3056
3057   # Removing unnecessary newline character from the end.
3058   set aBuff [string replace $aBuff end end]
3059   return $aBuff
3060 }
3061
3062 # Generates workspace files for Xcode.
3063 proc OS:xcworkspace { theWorkspaceName theModules theOutDir } {
3064   # Creating workspace directory for Xcode.
3065   set aWorkspaceDir "${theOutDir}/${theWorkspaceName}.xcworkspace"
3066   wokUtils:FILES:mkdir $aWorkspaceDir
3067   if { ! [file exists $aWorkspaceDir] } {
3068     puts stderr "Error: Could not create workspace directory \"$aWorkspaceDir\""
3069     return
3070   }
3071
3072   # Creating workspace file.
3073   set aWsFilePath "${aWorkspaceDir}/contents.xcworkspacedata"
3074   set aFile [open $aWsFilePath "w"]
3075
3076   # Adding header and section for main Group.
3077   puts $aFile "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
3078   puts $aFile "<Workspace"
3079   puts $aFile "   version = \"1.0\">"
3080   puts $aFile "   <Group"
3081   puts $aFile "      location = \"container:\""
3082   puts $aFile "      name = \"${theWorkspaceName}\">"
3083
3084   # Adding modules.
3085   if { [llength "$theModules"] > 1 } {
3086     foreach aModule $theModules {
3087       puts $aFile "      <Group"
3088       puts $aFile "         location = \"container:\""
3089       puts $aFile "         name = \"${aModule}\">"
3090       puts $aFile [OS:xcworkspace:toolkits $aModule]
3091       puts $aFile "      </Group>"
3092     }
3093   } else {
3094     puts $aFile [OS:xcworkspace:toolkits $theModules]
3095   }
3096
3097   # Adding footer.
3098   puts $aFile "   </Group>"
3099   puts $aFile "</Workspace>"
3100   close $aFile
3101 }
3102
3103 # Generates Xcode project files.
3104 proc OS:xcodeproj { theModules theOutDir theGuidsMap theLibType thePlatform} {
3105   upvar $theGuidsMap aGuidsMap
3106
3107   set isStatic 0
3108   if { "$theLibType" == "static" } {
3109     set isStatic 1
3110   } elseif { "$thePlatform" == "ios" } {
3111     set isStatic 1
3112   }
3113
3114   set aProjectFiles {}
3115   foreach aModule $theModules {
3116     foreach aToolKit [${aModule}:toolkits] {
3117       lappend aProjectFiles [osutils:xcdtk $theOutDir $aToolKit     aGuidsMap $isStatic $thePlatform "dylib"]
3118     }
3119     foreach anExecutable [OS:executable ${aModule}] {
3120       lappend aProjectFiles [osutils:xcdtk $theOutDir $anExecutable aGuidsMap $isStatic $thePlatform "executable"]
3121     }
3122   }
3123   return $aProjectFiles
3124 }
3125
3126 # Generates dependencies section for Xcode project files.
3127 proc osutils:xcdtk:deps {theToolKit theTargetType theGuidsMap theFileRefSection theDepsGuids theDepsRefGuids theIsStatic} {
3128   global path
3129   upvar $theGuidsMap         aGuidsMap
3130   upvar $theFileRefSection   aFileRefSection
3131   upvar $theDepsGuids        aDepsGuids
3132   upvar $theDepsRefGuids     aDepsRefGuids
3133
3134   set aBuildFileSection ""
3135   set aUsedToolKits     [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]]
3136   set aDepToolkits      [lappend [wokUtils:LIST:Purge [osutils:tk:close $theToolKit]] $theToolKit]
3137
3138   if { "$theTargetType" == "executable" } {
3139     set aFile [osutils:tk:files $theToolKit osutils:compilable 0]
3140     set aProjName [file rootname [file tail $aFile]]
3141     set aDepToolkits [LibToLinkX $theToolKit $aProjName]
3142   }
3143
3144   set aLibExt "dylib"
3145   if { $theIsStatic == 1 } {
3146     set aLibExt "a"
3147     if { "$theTargetType" != "executable" } {
3148       return $aBuildFileSection
3149     }
3150   }
3151
3152   osutils:usedOsLibs $theToolKit "mac" aLibs aFrameworks
3153   set aUsedToolKits [concat $aUsedToolKits $aLibs]
3154   set aUsedToolKits [concat $aUsedToolKits $aFrameworks]
3155   foreach tkx $aUsedToolKits {
3156     set aDepLib    "${tkx}_Dep"
3157     set aDepLibRef "${tkx}_DepRef"
3158
3159     if { ! [info exists aGuidsMap($aDepLib)] } {
3160       set aGuidsMap($aDepLib) [OS:genGUID "xcd"]
3161     }
3162     if { ! [info exists aGuidsMap($aDepLibRef)] } {
3163       set aGuidsMap($aDepLibRef) [OS:genGUID "xcd"]
3164     }
3165
3166     append aBuildFileSection "\t\t$aGuidsMap($aDepLib) = \{isa = PBXBuildFile; fileRef = $aGuidsMap($aDepLibRef) ; \};\n"
3167     if {[lsearch -nocase $aFrameworks $tkx] == -1} {
3168       append aFileRefSection   "\t\t$aGuidsMap($aDepLibRef) = \{isa = PBXFileReference; lastKnownFileType = file; name = lib${tkx}.${aLibExt}; path = lib${tkx}.${aLibExt}; sourceTree = \"<group>\"; \};\n"
3169     } else {
3170       append aFileRefSection   "\t\t$aGuidsMap($aDepLibRef) = \{isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ${tkx}.framework; path = /System/Library/Frameworks/${tkx}.framework; sourceTree = \"<absolute>\"; \};\n"
3171     }
3172     append aDepsGuids        "\t\t\t\t$aGuidsMap($aDepLib) ,\n"
3173     append aDepsRefGuids     "\t\t\t\t$aGuidsMap($aDepLibRef) ,\n"
3174   }
3175
3176   return $aBuildFileSection
3177 }
3178
3179 # Generates PBXBuildFile and PBXGroup sections for project file.
3180 proc osutils:xcdtk:sources {theToolKit theTargetType theSrcFileRefSection theGroupSection thePackageGuids theSrcFileGuids theGuidsMap theIncPaths} {
3181   upvar $theSrcFileRefSection aSrcFileRefSection
3182   upvar $theGroupSection      aGroupSection
3183   upvar $thePackageGuids      aPackagesGuids
3184   upvar $theSrcFileGuids      aSrcFileGuids
3185   upvar $theGuidsMap          aGuidsMap
3186   upvar $theIncPaths          anIncPaths
3187
3188   set listloc [osutils:tk:units $theToolKit]
3189   set resultloc [osutils:justunix $listloc]
3190   set aBuildFileSection ""
3191   set aPackages [lsort -nocase $resultloc]
3192   if { "$theTargetType" == "executable" } {
3193     set aPackages [list "$theToolKit"]
3194   }
3195
3196   # Generating PBXBuildFile, PBXGroup sections and groups for each package.
3197   foreach fxlo $aPackages {
3198     set xlo       $fxlo
3199     set aPackage "${xlo}_Package"
3200     set aSrcFileRefGuids ""
3201     if { ! [info exists aGuidsMap($aPackage)] } {
3202       set aGuidsMap($aPackage) [OS:genGUID "xcd"]
3203     }
3204
3205     set aSrcFiles [osutils:tk:files $xlo osutils:compilable 0]
3206     foreach aSrcFile [lsort $aSrcFiles] {
3207       set aFileExt "sourcecode.cpp.cpp"
3208
3209       if { [file extension $aSrcFile] == ".c" } {
3210         set aFileExt "sourcecode.c.c"
3211       } elseif { [file extension $aSrcFile] == ".mm" } {
3212         set aFileExt "sourcecode.cpp.objcpp"
3213       }
3214
3215       if { ! [info exists aGuidsMap($aSrcFile)] } {
3216         set aGuidsMap($aSrcFile) [OS:genGUID "xcd"]
3217       }
3218       set aSrcFileRef "${aSrcFile}_Ref"
3219       if { ! [info exists aGuidsMap($aSrcFileRef)] } {
3220         set aGuidsMap($aSrcFileRef) [OS:genGUID "xcd"]
3221       }
3222       if { ! [info exists written([file tail $aSrcFile])] } {
3223         set written([file tail $aSrcFile]) 1
3224         append aBuildFileSection  "\t\t$aGuidsMap($aSrcFile) = \{isa = PBXBuildFile; fileRef = $aGuidsMap($aSrcFileRef) ;\};\n"
3225         append aSrcFileRefSection "\t\t$aGuidsMap($aSrcFileRef) = \{isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = ${aFileExt}; name = [wokUtils:FILES:wtail $aSrcFile 1]; path = ../../../[wokUtils:FILES:wtail $aSrcFile 3]; sourceTree = \"<group>\"; \};\n"
3226         append aSrcFileGuids      "\t\t\t\t$aGuidsMap($aSrcFile) ,\n"
3227         append aSrcFileRefGuids   "\t\t\t\t$aGuidsMap($aSrcFileRef) ,\n"
3228       } else {
3229         puts "Warning : more than one occurences for [file tail $aSrcFile]"
3230       }
3231     }
3232
3233     append aGroupSection "\t\t$aGuidsMap($aPackage) = \{\n"
3234     append aGroupSection "\t\t\tisa = PBXGroup;\n"
3235     append aGroupSection "\t\t\tchildren = (\n"
3236     append aGroupSection $aSrcFileRefGuids
3237     append aGroupSection "\t\t\t);\n"
3238     append aGroupSection "\t\t\tname = $xlo;\n"
3239     append aGroupSection "\t\t\tsourceTree = \"<group>\";\n"
3240     append aGroupSection "\t\t\};\n"
3241
3242     # Storing packages IDs for adding them later as a child of toolkit
3243     append aPackagesGuids "\t\t\t\t$aGuidsMap($aPackage) ,\n"
3244   }
3245
3246   # Removing unnecessary newline character from the end.
3247   set aPackagesGuids [string replace $aPackagesGuids end end]
3248
3249   return $aBuildFileSection
3250 }
3251
3252 # Creates folders structure and all necessary files for Xcode project.
3253 proc osutils:xcdtk { theOutDir theToolKit theGuidsMap theIsStatic thePlatform {theTargetType "dylib"} } {
3254   set aPBXBuildPhase "Headers"
3255   set aRunOnlyForDeployment "0"
3256   set aProductType "library.dynamic"
3257   set anExecExtension "\t\t\t\tEXECUTABLE_EXTENSION = dylib;"
3258   set anExecPrefix "\t\t\t\tEXECUTABLE_PREFIX = lib;"
3259   set aWrapperExtension "\t\t\t\tWRAPPER_EXTENSION = dylib;"
3260   set aTKDefines [list "CSFDB" "OCC_CONVERT_SIGNALS"]
3261
3262   if { "$theTargetType" == "executable" } {
3263     set aPBXBuildPhase "CopyFiles"
3264     set aRunOnlyForDeployment "1"
3265     set aProductType "tool"
3266     set anExecExtension ""
3267     set anExecPrefix ""
3268     set aWrapperExtension ""
3269   } elseif { $theIsStatic == 1 } {
3270     set aProductType "library.static"
3271     set anExecExtension "\t\t\t\tEXECUTABLE_EXTENSION = a;"
3272     set aWrapperExtension "\t\t\t\tWRAPPER_EXTENSION = a;"
3273   }
3274
3275   set aUsername [exec whoami]
3276
3277   # Creation of folders for Xcode projectP.
3278   set aToolkitDir "${theOutDir}/${theToolKit}.xcodeproj"
3279   wokUtils:FILES:mkdir $aToolkitDir
3280   if { ! [file exists $aToolkitDir] } {
3281     puts stderr "Error: Could not create project directory \"$aToolkitDir\""
3282     return
3283   }
3284
3285   set aUserDataDir "${aToolkitDir}/xcuserdata"
3286   wokUtils:FILES:mkdir $aUserDataDir
3287   if { ! [file exists $aUserDataDir] } {
3288     puts stderr "Error: Could not create xcuserdata directorty in \"$aToolkitDir\""
3289     return
3290   }
3291
3292   set aUserDataDir "${aUserDataDir}/${aUsername}.xcuserdatad"
3293   wokUtils:FILES:mkdir $aUserDataDir
3294   if { ! [file exists $aUserDataDir] } {
3295     puts stderr "Error: Could not create ${aUsername}.xcuserdatad directorty in \"$aToolkitDir\"/xcuserdata"
3296     return
3297   }
3298
3299   set aSchemesDir "${aUserDataDir}/xcschemes"
3300   wokUtils:FILES:mkdir $aSchemesDir
3301   if { ! [file exists $aSchemesDir] } {
3302     puts stderr "Error: Could not create xcschemes directorty in \"$aUserDataDir\""
3303     return
3304   }
3305   # End of folders creation.
3306
3307   # Generating GUID for tookit.
3308   upvar $theGuidsMap aGuidsMap
3309   if { ! [info exists aGuidsMap($theToolKit)] } {
3310     set aGuidsMap($theToolKit) [OS:genGUID "xcd"]
3311   }
3312
3313   # Creating xcscheme file for toolkit from template.
3314   set aXcschemeTmpl [osutils:readtemplate "xcscheme" "xcd"]
3315   regsub -all -- {__TOOLKIT_NAME__} $aXcschemeTmpl $theToolKit aXcschemeTmpl
3316   regsub -all -- {__TOOLKIT_GUID__} $aXcschemeTmpl $aGuidsMap($theToolKit) aXcschemeTmpl
3317   set aXcschemeFile [open "$aSchemesDir/${theToolKit}.xcscheme"  "w"]
3318   puts $aXcschemeFile $aXcschemeTmpl
3319   close $aXcschemeFile
3320
3321   # Creating xcschememanagement.plist file for toolkit from template.
3322   set aPlistTmpl [osutils:readtemplate "plist" "xcd"]
3323   regsub -all -- {__TOOLKIT_NAME__} $aPlistTmpl $theToolKit aPlistTmpl
3324   regsub -all -- {__TOOLKIT_GUID__} $aPlistTmpl $aGuidsMap($theToolKit) aPlistTmpl
3325   set aPlistFile [open "$aSchemesDir/xcschememanagement.plist"  "w"]
3326   puts $aPlistFile $aPlistTmpl
3327   close $aPlistFile
3328
3329   # Creating project.pbxproj file for toolkit.
3330   set aPbxprojFile [open "$aToolkitDir/project.pbxproj" "w"]
3331   puts $aPbxprojFile "// !\$*UTF8*\$!"
3332   puts $aPbxprojFile "\{"
3333   puts $aPbxprojFile "\tarchiveVersion = 1;"
3334   puts $aPbxprojFile "\tclasses = \{"
3335   puts $aPbxprojFile "\t\};"
3336   puts $aPbxprojFile "\tobjectVersion = 46;"
3337   puts $aPbxprojFile "\tobjects = \{\n"
3338
3339   # Begin PBXBuildFile section
3340   set aPackagesGuids ""
3341   set aGroupSection ""
3342   set aSrcFileRefSection ""
3343   set aSrcFileGuids ""
3344   set aDepsFileRefSection ""
3345   set aDepsGuids ""
3346   set aDepsRefGuids ""
3347   set anIncPaths [list "../../../inc"]
3348   set anLibPaths ""
3349
3350   if { [info exists ::env(CSF_OPT_INC)] } {
3351     set anIncCfg [split "$::env(CSF_OPT_INC)" ":"]
3352     foreach anIncCfgPath $anIncCfg {
3353       lappend anIncPaths $anIncCfgPath
3354     }
3355   }
3356   if { [info exists ::env(CSF_OPT_LIB64)] } {
3357     set anLibCfg [split "$::env(CSF_OPT_LIB64)" ":"]
3358     foreach anLibCfgPath $anLibCfg {
3359       lappend anLibPaths $anLibCfgPath
3360     }
3361   }
3362
3363   puts $aPbxprojFile [osutils:xcdtk:sources $theToolKit $theTargetType aSrcFileRefSection aGroupSection aPackagesGuids aSrcFileGuids aGuidsMap anIncPaths]
3364   puts $aPbxprojFile [osutils:xcdtk:deps    $theToolKit $theTargetType aGuidsMap aDepsFileRefSection aDepsGuids aDepsRefGuids $theIsStatic]
3365   # End PBXBuildFile section
3366
3367   # Begin PBXFileReference section
3368   set aToolkitLib "lib${theToolKit}.dylib"
3369   set aPath "$aToolkitLib"
3370   if { "$theTargetType" == "executable" } {
3371     set aPath "$theToolKit"
3372   } elseif { $theIsStatic == 1 } {
3373     set aToolkitLib "lib${theToolKit}.a"
3374   }
3375
3376   if { ! [info exists aGuidsMap($aToolkitLib)] } {
3377     set aGuidsMap($aToolkitLib) [OS:genGUID "xcd"]
3378   }
3379
3380   puts $aPbxprojFile "\t\t$aGuidsMap($aToolkitLib) = {isa = PBXFileReference; explicitFileType = \"compiled.mach-o.${theTargetType}\"; includeInIndex = 0; path = $aPath; sourceTree = BUILT_PRODUCTS_DIR; };\n"
3381   puts $aPbxprojFile $aSrcFileRefSection
3382   puts $aPbxprojFile $aDepsFileRefSection
3383   # End PBXFileReference section
3384
3385
3386   # Begin PBXFrameworksBuildPhase section
3387   set aTkFrameworks "${theToolKit}_Frameworks"
3388   if { ! [info exists aGuidsMap($aTkFrameworks)] } {
3389     set aGuidsMap($aTkFrameworks) [OS:genGUID "xcd"]
3390   }
3391
3392   puts $aPbxprojFile "\t\t$aGuidsMap($aTkFrameworks) = \{"
3393   puts $aPbxprojFile "\t\t\tisa = PBXFrameworksBuildPhase;"
3394   puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
3395   puts $aPbxprojFile "\t\t\tfiles = ("
3396   puts $aPbxprojFile $aDepsGuids
3397   puts $aPbxprojFile "\t\t\t);"
3398   puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = 0;"
3399   puts $aPbxprojFile "\t\t\};\n"
3400   # End PBXFrameworksBuildPhase section
3401
3402   # Begin PBXGroup section
3403   set aTkPBXGroup "${theToolKit}_PBXGroup"
3404   if { ! [info exists aGuidsMap($aTkPBXGroup)] } {
3405     set aGuidsMap($aTkPBXGroup) [OS:genGUID "xcd"]
3406   }
3407
3408   set aTkSrcGroup "${theToolKit}_SrcGroup"
3409   if { ! [info exists aGuidsMap($aTkSrcGroup)] } {
3410     set aGuidsMap($aTkSrcGroup) [OS:genGUID "xcd"]
3411   }
3412
3413   puts $aPbxprojFile $aGroupSection
3414   puts $aPbxprojFile "\t\t$aGuidsMap($aTkPBXGroup) = \{"
3415   puts $aPbxprojFile "\t\t\tisa = PBXGroup;"
3416   puts $aPbxprojFile "\t\t\tchildren = ("
3417   puts $aPbxprojFile $aDepsRefGuids
3418   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkSrcGroup) ,"
3419   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aToolkitLib) ,"
3420   puts $aPbxprojFile "\t\t\t);"
3421   puts $aPbxprojFile "\t\t\tsourceTree = \"<group>\";"
3422   puts $aPbxprojFile "\t\t\};"
3423   puts $aPbxprojFile "\t\t$aGuidsMap($aTkSrcGroup) = \{"
3424   puts $aPbxprojFile "\t\t\tisa = PBXGroup;"
3425   puts $aPbxprojFile "\t\t\tchildren = ("
3426   puts $aPbxprojFile $aPackagesGuids
3427   puts $aPbxprojFile "\t\t\t);"
3428   puts $aPbxprojFile "\t\t\tname = \"Source files\";"
3429   puts $aPbxprojFile "\t\t\tsourceTree = \"<group>\";"
3430   puts $aPbxprojFile "\t\t\};\n"
3431   # End PBXGroup section
3432
3433   # Begin PBXHeadersBuildPhase section
3434   set aTkHeaders "${theToolKit}_Headers"
3435   if { ! [info exists aGuidsMap($aTkHeaders)] } {
3436     set aGuidsMap($aTkHeaders) [OS:genGUID "xcd"]
3437   }
3438
3439   puts $aPbxprojFile "\t\t$aGuidsMap($aTkHeaders) = \{"
3440   puts $aPbxprojFile "\t\t\tisa = PBX${aPBXBuildPhase}BuildPhase;"
3441   puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
3442   puts $aPbxprojFile "\t\t\tfiles = ("
3443   puts $aPbxprojFile "\t\t\t);"
3444   puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = ${aRunOnlyForDeployment};"
3445   puts $aPbxprojFile "\t\t\};\n"
3446   # End PBXHeadersBuildPhase section
3447
3448   # Begin PBXNativeTarget section
3449   set aTkBuildCfgListNativeTarget "${theToolKit}_BuildCfgListNativeTarget"
3450   if { ! [info exists aGuidsMap($aTkBuildCfgListNativeTarget)] } {
3451     set aGuidsMap($aTkBuildCfgListNativeTarget) [OS:genGUID "xcd"]
3452   }
3453
3454   set aTkSources "${theToolKit}_Sources"
3455   if { ! [info exists aGuidsMap($aTkSources)] } {
3456     set aGuidsMap($aTkSources) [OS:genGUID "xcd"]
3457   }
3458
3459   puts $aPbxprojFile "\t\t$aGuidsMap($theToolKit) = \{"
3460   puts $aPbxprojFile "\t\t\tisa = PBXNativeTarget;"
3461   puts $aPbxprojFile "\t\t\tbuildConfigurationList = $aGuidsMap($aTkBuildCfgListNativeTarget) ;"
3462   puts $aPbxprojFile "\t\t\tbuildPhases = ("
3463   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkSources) ,"
3464   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkFrameworks) ,"
3465   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkHeaders) ,"
3466   puts $aPbxprojFile "\t\t\t);"
3467   puts $aPbxprojFile "\t\t\tbuildRules = ("
3468   puts $aPbxprojFile "\t\t\t);"
3469   puts $aPbxprojFile "\t\t\tdependencies = ("
3470   puts $aPbxprojFile "\t\t\t);"
3471   puts $aPbxprojFile "\t\t\tname = $theToolKit;"
3472   puts $aPbxprojFile "\t\t\tproductName = $theToolKit;"
3473   puts $aPbxprojFile "\t\t\tproductReference = $aGuidsMap($aToolkitLib) ;"
3474   puts $aPbxprojFile "\t\t\tproductType = \"com.apple.product-type.${aProductType}\";"
3475   puts $aPbxprojFile "\t\t\};\n"
3476   # End PBXNativeTarget section
3477
3478   # Begin PBXProject section
3479   set aTkProjectObj "${theToolKit}_ProjectObj"
3480   if { ! [info exists aGuidsMap($aTkProjectObj)] } {
3481     set aGuidsMap($aTkProjectObj) [OS:genGUID "xcd"]
3482   }
3483
3484   set aTkBuildCfgListProj "${theToolKit}_BuildCfgListProj"
3485   if { ! [info exists aGuidsMap($aTkBuildCfgListProj)] } {
3486     set aGuidsMap($aTkBuildCfgListProj) [OS:genGUID "xcd"]
3487   }
3488
3489   puts $aPbxprojFile "\t\t$aGuidsMap($aTkProjectObj) = \{"
3490   puts $aPbxprojFile "\t\t\tisa = PBXProject;"
3491   puts $aPbxprojFile "\t\t\tattributes = \{"
3492   puts $aPbxprojFile "\t\t\t\tLastUpgradeCheck = 0430;"
3493   puts $aPbxprojFile "\t\t\t\};"
3494   puts $aPbxprojFile "\t\t\tbuildConfigurationList = $aGuidsMap($aTkBuildCfgListProj) ;"
3495   puts $aPbxprojFile "\t\t\tcompatibilityVersion = \"Xcode 3.2\";"
3496   puts $aPbxprojFile "\t\t\tdevelopmentRegion = English;"
3497   puts $aPbxprojFile "\t\t\thasScannedForEncodings = 0;"
3498   puts $aPbxprojFile "\t\t\tknownRegions = ("
3499   puts $aPbxprojFile "\t\t\t\ten,"
3500   puts $aPbxprojFile "\t\t\t);"
3501   puts $aPbxprojFile "\t\t\tmainGroup = $aGuidsMap($aTkPBXGroup);"
3502   puts $aPbxprojFile "\t\t\tproductRefGroup = $aGuidsMap($aTkPBXGroup);"
3503   puts $aPbxprojFile "\t\t\tprojectDirPath = \"\";"
3504   puts $aPbxprojFile "\t\t\tprojectRoot = \"\";"
3505   puts $aPbxprojFile "\t\t\ttargets = ("
3506   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($theToolKit) ,"
3507   puts $aPbxprojFile "\t\t\t);"
3508   puts $aPbxprojFile "\t\t\};\n"
3509   # End PBXProject section
3510
3511   # Begin PBXSourcesBuildPhase section
3512   puts $aPbxprojFile "\t\t$aGuidsMap($aTkSources) = \{"
3513   puts $aPbxprojFile "\t\t\tisa = PBXSourcesBuildPhase;"
3514   puts $aPbxprojFile "\t\t\tbuildActionMask = 2147483647;"
3515   puts $aPbxprojFile "\t\t\tfiles = ("
3516   puts $aPbxprojFile $aSrcFileGuids
3517   puts $aPbxprojFile "\t\t\t);"
3518   puts $aPbxprojFile "\t\t\trunOnlyForDeploymentPostprocessing = 0;"
3519   puts $aPbxprojFile "\t\t\};\n"
3520   # End PBXSourcesBuildPhase section
3521
3522   # Begin XCBuildConfiguration section
3523   set aTkDebugProject "${theToolKit}_DebugProject"
3524   if { ! [info exists aGuidsMap($aTkDebugProject)] } {
3525     set aGuidsMap($aTkDebugProject) [OS:genGUID "xcd"]
3526   }
3527
3528   set aTkReleaseProject "${theToolKit}_ReleaseProject"
3529   if { ! [info exists aGuidsMap($aTkReleaseProject)] } {
3530     set aGuidsMap($aTkReleaseProject) [OS:genGUID "xcd"]
3531   }
3532
3533   set aTkDebugNativeTarget "${theToolKit}_DebugNativeTarget"
3534   if { ! [info exists aGuidsMap($aTkDebugNativeTarget)] } {
3535     set aGuidsMap($aTkDebugNativeTarget) [OS:genGUID "xcd"]
3536   }
3537
3538   set aTkReleaseNativeTarget "${theToolKit}_ReleaseNativeTarget"
3539   if { ! [info exists aGuidsMap($aTkReleaseNativeTarget)] } {
3540     set aGuidsMap($aTkReleaseNativeTarget) [OS:genGUID "xcd"]
3541   }
3542
3543   # Debug target
3544   puts $aPbxprojFile "\t\t$aGuidsMap($aTkDebugProject) = \{"
3545   puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3546   puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3547
3548   puts $aPbxprojFile "\t\t\t\tDEBUG_INFORMATION_FORMAT = dwarf;"
3549   puts $aPbxprojFile "\t\t\t\tALWAYS_SEARCH_USER_PATHS = NO;"
3550   if { "$thePlatform" == "ios" } {
3551     puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphoneos\*\]\" = \"\$(ARCHS_STANDARD)\";";
3552     puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphonesimulator\*\]\" = \"x86_64\";";
3553     puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LIBRARY = \"libc++\";"
3554     puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_MODULES = YES;"
3555     puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_OBJC_ARC = YES;"
3556   }
3557   puts $aPbxprojFile "\t\t\t\tARCHS = \"\$(ARCHS_STANDARD_64_BIT)\";"
3558   puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LANGUAGE_STANDARD = \"gnu++0x\";"
3559   puts $aPbxprojFile "\t\t\t\tCOPY_PHASE_STRIP = NO;"
3560   puts $aPbxprojFile "\t\t\t\tGCC_C_LANGUAGE_STANDARD = gnu99;"
3561   puts $aPbxprojFile "\t\t\t\tGCC_DYNAMIC_NO_PIC = NO;"
3562   puts $aPbxprojFile "\t\t\t\tGCC_ENABLE_OBJC_EXCEPTIONS = YES;"
3563   puts $aPbxprojFile "\t\t\t\tGCC_OPTIMIZATION_LEVEL = 0;"
3564   puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3565   puts $aPbxprojFile "\t\t\t\t\t\"DEBUG=1\","
3566   puts $aPbxprojFile "\t\t\t\t\t\"\$\(inherited\)\","
3567   puts $aPbxprojFile "\t\t\t\t);"
3568   puts $aPbxprojFile "\t\t\t\tGCC_SYMBOLS_PRIVATE_EXTERN = NO;"
3569   puts $aPbxprojFile "\t\t\t\tGCC_VERSION = com.apple.compilers.llvm.clang.1_0;"
3570   puts $aPbxprojFile "\t\t\t\tGCC_WARN_64_TO_32_BIT_CONVERSION = YES;"
3571   puts $aPbxprojFile "\t\t\t\tGCC_WARN_ABOUT_RETURN_TYPE = YES;"
3572   puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNINITIALIZED_AUTOS = YES;"
3573   puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNUSED_VARIABLE = YES;"
3574   puts $aPbxprojFile "\t\t\t\tOTHER_LDFLAGS = \"\$(CSF_OPT_LNK64D)\"; "
3575   if { "$thePlatform" == "ios" } {
3576     puts $aPbxprojFile "\t\t\t\tONLY_ACTIVE_ARCH = NO;"
3577     puts $aPbxprojFile "\t\t\t\tSDKROOT = iphoneos;"
3578   } else {
3579     puts $aPbxprojFile "\t\t\t\tONLY_ACTIVE_ARCH = YES;"
3580   }
3581   puts $aPbxprojFile "\t\t\t\};"
3582
3583   puts $aPbxprojFile "\t\t\tname = Debug;"
3584   puts $aPbxprojFile "\t\t\};"
3585
3586   # Release target
3587   puts $aPbxprojFile "\t\t$aGuidsMap($aTkReleaseProject) = \{"
3588   puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3589   puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3590
3591   puts $aPbxprojFile "\t\t\t\tDEBUG_INFORMATION_FORMAT = \"dwarf-with-dsym\";"
3592   puts $aPbxprojFile "\t\t\t\tALWAYS_SEARCH_USER_PATHS = NO;"
3593   if { "$thePlatform" == "ios" } {
3594     puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphoneos\*\]\" = \"\$(ARCHS_STANDARD)\";";
3595     puts $aPbxprojFile "\t\t\t\t\"ARCHS\[sdk=iphonesimulator\*\]\" = \"x86_64\";";
3596     puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LIBRARY = \"libc++\";"
3597     puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_MODULES = YES;"
3598     puts $aPbxprojFile "\t\t\t\tCLANG_ENABLE_OBJC_ARC = YES;"
3599   }
3600   puts $aPbxprojFile "\t\t\t\tARCHS = \"\$(ARCHS_STANDARD_64_BIT)\";"
3601   puts $aPbxprojFile "\t\t\t\tCLANG_CXX_LANGUAGE_STANDARD = \"gnu++0x\";"
3602   puts $aPbxprojFile "\t\t\t\tCOPY_PHASE_STRIP = YES;"
3603   puts $aPbxprojFile "\t\t\t\tGCC_C_LANGUAGE_STANDARD = gnu99;"
3604   puts $aPbxprojFile "\t\t\t\tGCC_ENABLE_OBJC_EXCEPTIONS = YES;"
3605   puts $aPbxprojFile "\t\t\t\tDEAD_CODE_STRIPPING = NO;"
3606   puts $aPbxprojFile "\t\t\t\tGCC_OPTIMIZATION_LEVEL = 2;"
3607   puts $aPbxprojFile "\t\t\t\tGCC_VERSION = com.apple.compilers.llvm.clang.1_0;"
3608   puts $aPbxprojFile "\t\t\t\tGCC_WARN_64_TO_32_BIT_CONVERSION = YES;"
3609   puts $aPbxprojFile "\t\t\t\tGCC_WARN_ABOUT_RETURN_TYPE = YES;"
3610   puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNINITIALIZED_AUTOS = YES;"
3611   puts $aPbxprojFile "\t\t\t\tGCC_WARN_UNUSED_VARIABLE = YES;"
3612   puts $aPbxprojFile "\t\t\t\tOTHER_LDFLAGS = \"\$(CSF_OPT_LNK64)\";"
3613   if { "$thePlatform" == "ios" } {
3614     puts $aPbxprojFile "\t\t\t\tIPHONEOS_DEPLOYMENT_TARGET = 7.0;"
3615     puts $aPbxprojFile "\t\t\t\tSDKROOT = iphoneos;"
3616   }
3617   puts $aPbxprojFile "\t\t\t\};"
3618   puts $aPbxprojFile "\t\t\tname = Release;"
3619   puts $aPbxprojFile "\t\t\};"
3620   puts $aPbxprojFile "\t\t$aGuidsMap($aTkDebugNativeTarget) = \{"
3621   puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3622   puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3623   puts $aPbxprojFile "${anExecExtension}"
3624   puts $aPbxprojFile "${anExecPrefix}"
3625   puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3626   foreach aMacro $aTKDefines {
3627     puts $aPbxprojFile "\t\t\t\t\t${aMacro} ,"
3628   }
3629   puts $aPbxprojFile "\t\t\t\t);"
3630
3631   puts $aPbxprojFile "\t\t\t\tHEADER_SEARCH_PATHS = ("
3632   foreach anIncPath $anIncPaths {
3633     puts $aPbxprojFile "\t\t\t\t\t${anIncPath},"
3634   }
3635   puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_INC)\","
3636   puts $aPbxprojFile "\t\t\t\t);"
3637
3638   puts $aPbxprojFile "\t\t\t\tLIBRARY_SEARCH_PATHS = ("
3639   foreach anLibPath $anLibPaths {
3640     puts $aPbxprojFile "\t\t\t\t\t${anLibPath},"
3641   }
3642   puts $aPbxprojFile "\t\t\t\t);"
3643
3644   puts $aPbxprojFile "\t\t\t\tOTHER_CFLAGS = ("
3645   puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_CMPL)\","
3646   puts $aPbxprojFile "\t\t\t\t);"
3647   puts $aPbxprojFile "\t\t\t\tOTHER_CPLUSPLUSFLAGS = ("
3648   puts $aPbxprojFile "\t\t\t\t\t\"\$(OTHER_CFLAGS)\","
3649   puts $aPbxprojFile "\t\t\t\t);"
3650   puts $aPbxprojFile "\t\t\t\tPRODUCT_NAME = \"\$(TARGET_NAME)\";"
3651   set anUserHeaderSearchPath "\t\t\t\tUSER_HEADER_SEARCH_PATHS = \""
3652   foreach anIncPath $anIncPaths {
3653     append anUserHeaderSearchPath " ${anIncPath}"
3654   }
3655   append anUserHeaderSearchPath "\";"
3656   puts $aPbxprojFile $anUserHeaderSearchPath
3657   puts $aPbxprojFile "${aWrapperExtension}"
3658   puts $aPbxprojFile "\t\t\t\};"
3659   puts $aPbxprojFile "\t\t\tname = Debug;"
3660   puts $aPbxprojFile "\t\t\};"
3661   puts $aPbxprojFile "\t\t$aGuidsMap($aTkReleaseNativeTarget) = \{"
3662   puts $aPbxprojFile "\t\t\tisa = XCBuildConfiguration;"
3663   puts $aPbxprojFile "\t\t\tbuildSettings = \{"
3664   puts $aPbxprojFile "${anExecExtension}"
3665   puts $aPbxprojFile "${anExecPrefix}"
3666   puts $aPbxprojFile "\t\t\t\tGCC_PREPROCESSOR_DEFINITIONS = ("
3667   foreach aMacro $aTKDefines {
3668     puts $aPbxprojFile "\t\t\t\t\t${aMacro} ,"
3669   }
3670   puts $aPbxprojFile "\t\t\t\t);"
3671   puts $aPbxprojFile "\t\t\t\tHEADER_SEARCH_PATHS = ("
3672   foreach anIncPath $anIncPaths {
3673     puts $aPbxprojFile "\t\t\t\t\t${anIncPath},"
3674   }
3675   puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_INC)\","
3676   puts $aPbxprojFile "\t\t\t\t);"
3677
3678   puts $aPbxprojFile "\t\t\t\tLIBRARY_SEARCH_PATHS = ("
3679   foreach anLibPath $anLibPaths {
3680     puts $aPbxprojFile "\t\t\t\t\t${anLibPath},"
3681   }
3682   puts $aPbxprojFile "\t\t\t\t);"
3683
3684   puts $aPbxprojFile "\t\t\t\tOTHER_CFLAGS = ("
3685   puts $aPbxprojFile "\t\t\t\t\t\"\$(CSF_OPT_CMPL)\","
3686   puts $aPbxprojFile "\t\t\t\t);"
3687   puts $aPbxprojFile "\t\t\t\tOTHER_CPLUSPLUSFLAGS = ("
3688   puts $aPbxprojFile "\t\t\t\t\t\"\$(OTHER_CFLAGS)\","
3689   puts $aPbxprojFile "\t\t\t\t);"
3690   puts $aPbxprojFile "\t\t\t\tPRODUCT_NAME = \"\$(TARGET_NAME)\";"
3691   puts $aPbxprojFile $anUserHeaderSearchPath
3692   puts $aPbxprojFile "${aWrapperExtension}"
3693   puts $aPbxprojFile "\t\t\t\};"
3694   puts $aPbxprojFile "\t\t\tname = Release;"
3695   puts $aPbxprojFile "\t\t\};\n"
3696   # End XCBuildConfiguration section
3697
3698   # Begin XCConfigurationList section
3699   puts $aPbxprojFile "\t\t$aGuidsMap($aTkBuildCfgListProj) = \{"
3700   puts $aPbxprojFile "\t\t\tisa = XCConfigurationList;"
3701   puts $aPbxprojFile "\t\tbuildConfigurations = ("
3702   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkDebugProject) ,"
3703   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkReleaseProject) ,"
3704   puts $aPbxprojFile "\t\t\t);"
3705   puts $aPbxprojFile "\t\t\tdefaultConfigurationIsVisible = 0;"
3706   puts $aPbxprojFile "\t\t\tdefaultConfigurationName = Release;"
3707   puts $aPbxprojFile "\t\t\};"
3708   puts $aPbxprojFile "\t\t$aGuidsMap($aTkBuildCfgListNativeTarget) = \{"
3709   puts $aPbxprojFile "\t\t\tisa = XCConfigurationList;"
3710   puts $aPbxprojFile "\t\t\tbuildConfigurations = ("
3711   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkDebugNativeTarget) ,"
3712   puts $aPbxprojFile "\t\t\t\t$aGuidsMap($aTkReleaseNativeTarget) ,"
3713   puts $aPbxprojFile "\t\t\t);"
3714   puts $aPbxprojFile "\t\t\tdefaultConfigurationIsVisible = 0;"
3715   puts $aPbxprojFile "\t\t\tdefaultConfigurationName = Release;"
3716   puts $aPbxprojFile "\t\t\};\n"
3717   # End XCConfigurationList section
3718
3719   puts $aPbxprojFile "\t\};"
3720   puts $aPbxprojFile "\trootObject = $aGuidsMap($aTkProjectObj) ;"
3721   puts $aPbxprojFile "\}"
3722
3723   close $aPbxprojFile
3724 }
3725
3726 proc osutils:xcdx { theOutDir theExecutable theGuidsMap } {
3727   set aUsername [exec whoami]
3728
3729   # Creating folders for Xcode project file.
3730   set anExecutableDir "${theOutDir}/${theExecutable}.xcodeproj"
3731   wokUtils:FILES:mkdir $anExecutableDir
3732   if { ! [file exists $anExecutableDir] } {
3733     puts stderr "Error: Could not create project directory \"$anExecutableDir\""
3734     return
3735   }
3736
3737   set aUserDataDir "${anExecutableDir}/xcuserdata"
3738   wokUtils:FILES:mkdir $aUserDataDir
3739   if { ! [file exists $aUserDataDir] } {
3740     puts stderr "Error: Could not create xcuserdata directorty in \"$anExecutableDir\""
3741     return
3742   }
3743
3744   set aUserDataDir "${aUserDataDir}/${aUsername}.xcuserdatad"
3745   wokUtils:FILES:mkdir $aUserDataDir
3746   if { ! [file exists $aUserDataDir] } {
3747     puts stderr "Error: Could not create ${aUsername}.xcuserdatad directorty in \"$anExecutableDir\"/xcuserdata"
3748     return
3749   }
3750
3751   set aSchemesDir "${aUserDataDir}/xcschemes"
3752   wokUtils:FILES:mkdir $aSchemesDir
3753   if { ! [file exists $aSchemesDir] } {
3754     puts stderr "Error: Could not create xcschemes directorty in \"$aUserDataDir\""
3755     return
3756   }
3757   # End folders creation.
3758
3759   # Generating GUID for tookit.
3760   upvar $theGuidsMap aGuidsMap
3761   if { ! [info exists aGuidsMap($theExecutable)] } {
3762     set aGuidsMap($theExecutable) [OS:genGUID "xcd"]
3763   }
3764
3765   # Creating xcscheme file for toolkit from template.
3766   set aXcschemeTmpl [osutils:readtemplate "xcscheme" "xcode"]
3767   regsub -all -- {__TOOLKIT_NAME__} $aXcschemeTmpl $theExecutable aXcschemeTmpl
3768   regsub -all -- {__TOOLKIT_GUID__} $aXcschemeTmpl $aGuidsMap($theExecutable) aXcschemeTmpl
3769   set aXcschemeFile [open "$aSchemesDir/${theExecutable}.xcscheme"  "w"]
3770   puts $aXcschemeFile $aXcschemeTmpl
3771   close $aXcschemeFile
3772
3773   # Creating xcschememanagement.plist file for toolkit from template.
3774   set aPlistTmpl [osutils:readtemplate "plist" "xcode"]
3775   regsub -all -- {__TOOLKIT_NAME__} $aPlistTmpl $theExecutable aPlistTmpl
3776   regsub -all -- {__TOOLKIT_GUID__} $aPlistTmpl $aGuidsMap($theExecutable) aPlistTmpl
3777   set aPlistFile [open "$aSchemesDir/xcschememanagement.plist"  "w"]
3778   puts $aPlistFile $aPlistTmpl
3779   close $aPlistFile
3780 }
3781
3782 # launch generation
3783 genproj {*}$::argv