# OpenHPC build script/utilities
#
#-----------------------------------------------------------------------
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You may
# obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#-----------------------------------------------------------------------
# Sets up build environment for supported compiler families
#-----------------------------------------------------------------------

if [ "$#" = "1" ]; then
    OHPC_COMPILER_FAMILY=$1
fi

if [ -z "$OHPC_COMPILER_FAMILY" ]; then
    echo "Unknown OHPC_COMPILER_FAMILY"
    exit 1
fi

export toolset=gcc
if [ "$OHPC_COMPILER_FAMILY" = "gnu" ]; then
    export CC=gcc
    export CXX=g++
    export FC=gfortran
    export F77=gfortran
    module purge
    module load gnu
elif [ "$OHPC_COMPILER_FAMILY" = "gnu7" ]; then
    export CC=gcc
    export CXX=g++
    export FC=gfortran
    export F77=gfortran
    module purge
    module load gnu7
elif [ "$OHPC_COMPILER_FAMILY" = "intel" ]; then
    export toolset=intel-linux
    export CC=icc
    export CXX=icpc
    export FC=ifort
    export F77=ifort
    module purge
    module load intel
elif [ "$OHPC_COMPILER_FAMILY" = "dts6" ]; then
    # dts is the devtoolset-6 software collection
    # on top of CentOS7/RHEL7 which brings gcc 6.2.1
    # http://mirror.centos.org/centos/7/sclo/$basearch/rh/
    export CC=gcc
    export CXX=g++
    export FC=gfortran
    export F77=gfortran
    module purge
    module load gnu/6
elif [ "$OHPC_COMPILER_FAMILY" = "llvm" ]; then
    export toolset=clang
    export CC=clang
    export CXX=clang++
    export FC=flang
    export F77=flang
    module purge
    module load llvm
else
    echo "Unsupported OHPC_COMPILER_FAMILY -> $OHPC_COMPILER_FAMILY"
    exit 1
fi
