#%Module###########################################
#===============================================================================
# Copyright 2020 Intel Corporation.
#
# This software and the related documents are Intel copyrighted  materials,  and
# your use of  them is  governed by the  express license  under which  they were
# provided to you (License).  Unless the License provides otherwise, you may not
# use, modify, copy, publish, distribute,  disclose or transmit this software or
# the related documents without Intel's prior written permission.
#
# This software and the related documents  are provided as  is,  with no express
# or implied  warranties,  other  than those  that are  expressly stated  in the
# License.
#===============================================================================

set min_tcl_ver 8.4
if { $tcl_version < $min_tcl_ver } {
    puts stderr " "
    puts stderr "ERROR: This modulefile requires tcl $min_tcl_ver or greater."
    puts stderr "Your system reports that tclsh version $tcl_version is installed."
    exit 1
}

# get full pathname for this script file
set scriptpath "${ModulesCurrentModulefile}"

# if modulefile script name is a symlink, resolve it
if { "[file type "$scriptpath"]" eq "link" } {
    set scriptpath "[file readlink "$scriptpath"]"
}

# if fullpath contains links, resolve them
set scriptpath "[file normalize "$scriptpath"]"

# get directory holding this modulefile script and others
set modulefileroot "[file dirname "$scriptpath"]"

# get name of modulefile script we are loading
set modulefilename "[file tail "$scriptpath"]"

# determine modulefile script version
set modulefilever "[file dirname "$modulefileroot"]"
set modulefilever "[file tail "$modulefilever"]"

# point to component top-level root folder
set componentroot "[file dirname "$modulefileroot"]"
set componentroot "[file dirname "$componentroot"]"

# get component folder name
set componentname "[file tail "$componentroot"]"

# get oneAPI top-level root folder
set oneapiroot "[file dirname "$componentroot"]"

# disallow loading multiple copies of 64-bit and 32-bit versions of modulefile
# first assemble 64-bit and 32-bit name pairs for this modulefile
# then specify conflict for each (assumes "name" and "name32" pattern)
set mname32 $modulefilename
set mname64 [string trimright $mname32 "32"]
if { [string equal "$mname32" "$mname64"] } {
    append mname32 "32"
}
conflict $mname32
conflict $mname64

# On load print component name and version being loaded
if { [ module-info mode load ] } {
    puts stderr "Loading $modulefilename version $modulefilever"
}

# On remove print component name and version being removed
if { [ module-info mode ] == "unload" || [ module-info mode ] == "remove" } {
    puts stderr "Removing $modulefilename version $modulefilever"
}


# Intel(R) oneAPI Math Kernel Library (oneMKL) IA-64 architecture modulefile
# Sets up environment for oneMKL

# Show module info
module-whatis "Sets up environment for oneMKL IA-64 architecture"

# Load dependencies
module load compiler-rt/${modulefilever}
module load tbb/${modulefilever}

# Set intermediate variables
set    __mklroot             ${componentroot}/${modulefilever}
set    __target_arch         "intel64"

# Setup environment variables
setenv          MKLROOT            ${__mklroot}
prepend-path    LD_LIBRARY_PATH    ${__mklroot}/lib/${__target_arch}
prepend-path    LIBRARY_PATH       ${__mklroot}/lib/${__target_arch}
prepend-path    CPATH              ${__mklroot}/include
prepend-path    PKG_CONFIG_PATH    ${__mklroot}/tools/pkgconfig

# NLSPATH needs to be set to load correct message catalog.
# Refer $man locale and $man catopen for more details on NLSPATH
prepend-path    NLSPATH            ${__mklroot}/lib/${__target_arch}/locale/%l_%t/%N
