| 1 |
#%Module |
| 2 |
# Choose compiler version |
| 3 |
# |
| 4 |
# This check if any compiler was previously "module loaded", or if no compiler |
| 5 |
# previously loaded, will use the default compiler. Either way, it will check |
| 6 |
# if there is a subdirectory matching the compiler family name, and if so |
| 7 |
# will default to that. |
| 8 |
# |
| 9 |
# If no subdirectory matching compiler family name is found, we just return |
| 10 |
# without defaulting. The modulecmd will default based on its internal rules, |
| 11 |
# and it is up to the resulting module file to either load an appropriate |
| 12 |
# compiler if no compiler is loaded or to abort with appropriate error |
| 13 |
# messages if it wants an incompatible compiler. |
| 14 |
# |
| 15 |
# Usage: |
| 16 |
# In most cases, can simply symlink .modulerc to this file |
| 17 |
# |
| 18 |
# In more complicated cases, .modulerc can source this file, and can |
| 19 |
# then test the variable _did_default, which will be true if we set |
| 20 |
# a default for modules for the next level, or false otherwise (in which |
| 21 |
# case your .modulerc can set one) |
| 22 |
|
| 23 |
# Source some required Tcl procedures here. Hack for cookbook |
| 24 |
# making use of environment variable for location. |
| 25 |
# In production, this should ideally be in a site config file. |
| 26 |
# At minimum, hardcode the path |
| 27 |
set rootdir $::env(MOD_GIT_ROOTDIR) |
| 28 |
set tcllibdir $rootdir/doc/example/compiler-etc-dependencies/tcllib |
| 29 |
source $tcllibdir/common_utilities.tcl |
| 30 |
|
| 31 |
set moduledir [file dirname $ModulesCurrentModulefile] |
| 32 |
set parentdir [ file tail $moduledir ] |
| 33 |
|
| 34 |
# _did_default will be true if we actually default something |
| 35 |
# Useful in case a .modulerc sources us, and wants to set a default if we |
| 36 |
# did not |
| 37 |
set _did_default false |
| 38 |
|
| 39 |
# Get the currently loaded compiler or default, but do not load/prereq it |
| 40 |
set compilerTag [ GetLoadedCompiler 1 1 ] |
| 41 |
|
| 42 |
if { $compilerTag ne {} } { |
| 43 |
# Compiler loaded or defaulted |
| 44 |
# Make sure it matches our parent dir |
| 45 |
set tmpCompTag [ GetPackageFamilyVersion $compilerTag ] |
| 46 |
set compilerFamily [ lindex $tmpCompTag 0 ] |
| 47 |
set compilerVersion [ lindex $tmpCompTag 1 ] |
| 48 |
|
| 49 |
# Convert any gnus to gccs |
| 50 |
set tmp1 $compilerFamily |
| 51 |
if { $tmp1 eq {gnu} } { set tmp1 gcc } |
| 52 |
set tmp2 $parentdir |
| 53 |
if { $tmp2 eq {gnu} } { set tmp2 gcc } |
| 54 |
|
| 55 |
if { $tmp1 eq $tmp2 } { |
| 56 |
# If reach here, our parent dir agrees with |
| 57 |
# the family of our loaded/defaulted compiler |
| 58 |
if { $compilerVersion ne {} } { |
| 59 |
# We have a version, does a modulefile/dir exist for it |
| 60 |
if [ ChildModuleExists $compilerVersion ] { |
| 61 |
# There is a modulefile/dir for this compiler version, default to it |
| 62 |
module-version $compilerFamily/$compilerVersion default |
| 63 |
set _did_default true |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |