Debian Codegraph @

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

raw
1 # ======= Utilities related to which compiler is loaded, etc =========
2 # Author: Tom Payerle <[email protected]>
3
4 #--------------------------------------------------------------------
5 # GetDefaultCompiler:
6 #
7 # Returns the default compiler, gcc/8.2.0
8 proc GetDefaultCompiler { } {
9 return "gcc/8.2.0"
10 }
11
12 #--------------------------------------------------------------------
13 # RequireCompiler:
14 #
15 # Does a module load of specified compiler $mycomp.
16 # Includes special handling if $mycomp is the default compiler
17 proc RequireCompiler { mycomp } {
18 # If your module tree is set up so that there is no module for the
19 # default compiler (because e.g. it is available w/out loading a module
20 # anyway), you can uncomment the following block which will cause
21 # RequireCompiler to do nothing if mycomp is the default compiler
22 #set defComp [GetDefaultCompiler]
23 #if { $mycomp eq $defComp } {
24 #return
25 #}
26 module load $mycomp
27 }
28
29 #--------------------------------------------------------------------
30 # GetKnownCompilerFamilies:
31 #
32 # Returns a list of recognized compiler family names
33 #E.g. gcc, intel, pgi
34 proc GetKnownCompilerFamilies { } {
35 set cfamilies {gcc intel pgi}
36 return $cfamilies
37 }
38
39 #--------------------------------------------------------------------
40 # GetLoadedCompiler:
41 #
42 # Returns the string for the compiler we are using (i.e. was previously
43 # module loaded). E.g., gcc/8.2.0
44 # If no compiler was previously loaded, then if the optional parameter
45 # $pathDefault is set, it will look for a compiler family and
46 # version in the last components to the path to the current modulefile or
47 # .modulerc, and if found, uses that.
48 # If still no path found, it will return the value of [GetDefaultCompiler]
49 # if $useDefault is set.
50 # Otherwise, returns empty string.
51 #
52 # Takes the following arguments:
53 # pathDefault: boolean, default false. If set, attempt to determine
54 # the compiler from the full path to the modulefile if
55 # no compiler was loaded.
56 # useDefault: boolean, default false. If set, return the value of
57 # GetDefaultCompiler if no compiler is loaded or found from
58 # path (if $pathDefault).
59 # loadIt: boolean, default false. If set and a compiler
60 # was defaulted from path of GetDefaultCompiler, we will
61 # module load that compiler.
62 # Ignored unless either pathDefault or useDefault is set
63 # requireIt: boolean, default false. If set, we will prereq the
64 # compiler before returning.
65 proc GetLoadedCompiler {{pathDefault 0} { useDefault 0}
66 {loadIt 0 } { requireIt 0 } } {
67 global ModulesCurrentModulefile
68 set ctag {}
69 set cfams [ GetKnownCompilerFamilies ]
70 foreach cfam $cfams {
71 if { [ is-loaded $cfam ] } {
72 set ctag [ GetTagOfModuleLoaded $cfam ]
73 if { $requireIt } { prereq $ctag }
74 return $ctag
75 }
76 }
77
78 # No loaded compiler found, try to default from path to modulefile?
79 if { $pathDefault} {
80 set moduledir [file dirname $ModulesCurrentModulefile ]
81 set cversion [file tail $moduledir]
82 set tmppath [file dirname $moduledir]
83 set cfamily [file tail $tmppath]
84
85 if { [lsearch $cfams $cfamily] > -1 } {
86 # We matched a known compiler family in our path
87 set ctag "$cfamily/$cversion"
88 if { $loadIt } { RequireCompiler $ctag }
89 if { $requireIt } { prereq $ctag }
90 return $ctag
91 }
92 }
93
94 # Still no compiler, default to GetDefaultCompiler>
95 if { $useDefault } {
96 set ctag [ GetDefaultCompiler ]
97 if { $loadIt } { RequireCompiler $ctag }
98 if { $requireIt } { prereq $ctag }
99 return $ctag
100 }
101
102 #Nothing found, and not defaulting
103 return $ctag
104 }