Debian Codegraph @

doc/example/compiler-etc-dependencies/tcllib/LoadedCompMatches.tcl

raw
1 # =========================================================
2 # Author: Tom Payerle <[email protected]>
3
4 #--------------------------------------------------------------------
5 # LoadedCompilerMatches:
6 #
7 # Takes the tag of the desired compiler $wanted (in form of FAMILY/VERSION)
8 # Checks if any compiler is loaded, and will throw error if one is
9 # loaded and it does not match $wanted.
10 # If compilers match, it will prereq the compiler if $requireIt set
11 # If no compiler is loaded, will load if optional boolean parameter
12 # $loadIt is set (default unset), and prereq if $requireIt is set, and
13 # then return.
14 # Option parameters:
15 # requireIt: boolean, default false. If set, require $wanted
16 # loadIt: boolean, default false. If set, load $wanted if no compiler
17 # already loaded
18 # modTag: string, defaults go [module-info specified]. Used in error messages
19 proc LoadedCompilerMatches { wanted {requireIt 0} { loadIt 0 } {modTag {} } } {
20 # Default modTag
21 if { $modTag eq {} } { set modTag [ module-info specified ] }
22 # If no compiler given in $wanted, just return
23 if { $wanted eq {} } { return }
24
25 # Get loaded compiler (w/out defaults)
26 set loaded [ GetLoadedCompiler 0 0 ]
27 # If no compiler is loaded, then require it if asked, and return
28 if { $loaded eq {} } {
29 if { $loadIt } {
30 RequireCompiler $wanted
31 if { $requireIt } { prereq $wanted }
32 }
33 return
34 }
35
36 # Have a loaded compiler, split into family and version
37 set tmpLoaded [ GetPackageFamilyVersion $loaded ]
38 set loadedFam [ lindex $tmpLoaded 0 ]
39 set loadedVer [ lindex $tmpLoaded 1 ]
40 # Always use 'gcc' not 'gnu'
41 if { $loadedFam eq {gnu} } { set loadedFam gcc }
42
43 # Split wanted into family and version
44 set tmpWanted [ split $wanted / ]
45 set wantedLen [ llength $tmpWanted ]
46 #Nothing to do if no components to wanted
47 if { $wantedLen < 1 } { return }
48
49 set wantedFam [ lindex $tmpWanted 0 ]
50 # Always use 'gcc' not 'gnu'
51 if { $wantedFam eq {gnu} } { set wantedFam gcc }
52
53 # Ensure families match
54 if { $loadedFam ne $wantedFam } {
55 PrintLoadError "Compiler Mismatch
56 Package $modTag does not appear to be built for currently
57 loaded compiler $loaded."
58 }
59
60 # OK, families match
61 # If no version specified in $wanted, we are basically done
62 if { $wantedLen < 2 } {
63 if { $requireIt } { prereq $wanted }
64 return
65 }
66
67 # Ensure versions match
68 set wantedVer [ lindex $tmpWanted 1 ]
69 if { $loadedVer eq $wantedVer } {
70 if { $requireIt } { prereq $wanted }
71 return
72 }
73 # Versions don't match
74 PrintLoadError "Compiler Mismatch
75 Package $modTag does not appear to be built for currently
76 loaded compiler $loaded."
77 }