# 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.
#-----------------------------------------------------------------------

# Top-level OpenHPC installation paths
%global OHPC_BUILD 1
%global PROJ_NAME       ohpc
%global OHPC_HOME       /opt/%{PROJ_NAME}
%global OHPC_ADMIN      %{OHPC_HOME}/admin
%global OHPC_PUB        %{OHPC_HOME}/pub
%global OHPC_APPS       %{OHPC_PUB}/apps
%global OHPC_COMPILERS  %{OHPC_PUB}/compiler
%global OHPC_LIBS       %{OHPC_PUB}/libs
%global OHPC_MODULES    %{OHPC_PUB}/modulefiles
%global OHPC_MODULEDEPS %{OHPC_PUB}/moduledeps
%global OHPC_MPI_STACKS %{OHPC_PUB}/mpi
%global OHPC_UTILS      %{OHPC_PUB}/utils
%global debug_package   %{nil}
%global dist            .ohpc

%{!?PROJ_DELIM: %global PROJ_DELIM -ohpc}

DocDir:    %{OHPC_PUB}/doc/contrib

%if 0%{?rhel} == 7
    # OBS define's rhel_version to 700 for RHEL, in case we are
    # not running in OBS
    %global rhel_version 700
%endif

# OpenHPC packages require ohpc-filesystem which defines the basic
# installation path layout
%if 0%{?ohpc_bootstrap} == 0
Requires: ohpc-filesystem
%endif

# OpenHPC packages also require ohpc-buildroot to access macros used to define
# compiler and MPI families
%if 0%{?ohpc_bootstrap} == 0
BuildRequires: ohpc-buildroot
%endif

# OpenHPC convention: the default build configuration for compiler/MPI
# dependent packages assumes the gnu compiler and openmpi family; however,
# these choices can be overridden by specifing the compiler_family/mpi_family
# variables via rpmbuild or other mechanisms.

%{!?compiler_family: %global compiler_family gnu}
%{!?mpi_family: %global mpi_family openmpi}
%{!?python_family: %global python_family python3}

# Compiler dependencies
%if 0%{?ohpc_compiler_dependent} == 1

%if "%{compiler_family}" == "gnu7"
BuildRequires: gnu7-compilers%{PROJ_DELIM} >= 7.2.0
Requires:      gnu7-compilers%{PROJ_DELIM} >= 7.2.0
%endif
%if "%{compiler_family}" == "gnu"
BuildRequires: gnu-compilers%{PROJ_DELIM} >= 5.4.0
Requires:      gnu-compilers%{PROJ_DELIM} >= 5.4.0
%endif
%if "%{compiler_family}" == "intel"
BuildRequires: gcc-c++ intel-compilers-devel%{PROJ_DELIM}
Requires:      gcc-c++ intel-compilers-devel%{PROJ_DELIM}
%if 0%{OHPC_BUILD}
BuildRequires: intel_licenses
%endif
%endif
%if "%{compiler_family}" == "dts6"
BuildRequires: devtoolset-6
Requires:      devtoolset-6
BuildRequires: gnu-dts6-compilers%{PROJ_DELIM}
Requires:      gnu-dts6-compilers%{PROJ_DELIM}
%endif
%if "%{compiler_family}" == "gnu7rh"
BuildRequires: gnu-7-compilers%{PROJ_DELIM}
Requires:      gnu-7-compilers%{PROJ_DELIM}
%endif
%if "%{compiler_family}" == "llvm"
BuildRequires: llvm-compilers%{PROJ_DELIM}
Requires:      llvm-compilers%{PROJ_DELIM}
%endif

%endif

# Disable RPM symlink analysis on files in %%{OHPC_HOME}. 
%global __libsymlink_exclude_path  %{OHPC_HOME}/.*$

# MPI dependencies
%if 0%{?ohpc_mpi_dependent} == 1
%if "%{mpi_family}" == "impi"
BuildRequires: intel-mpi-devel%{PROJ_DELIM}
Requires:      intel-mpi-devel%{PROJ_DELIM}
%global __requires_exclude ^libmpi\\.so.*$|^libmpifort\\.so.*$|^libmpicxx\\.so.*$
%endif
%if "%{mpi_family}" == "mpich"
BuildRequires: mpich-%{compiler_family}%{PROJ_DELIM}
Requires:      mpich-%{compiler_family}%{PROJ_DELIM}
%endif
%if "%{mpi_family}" == "mvapich2"
BuildRequires: mvapich2-%{compiler_family}%{PROJ_DELIM}
Requires:      mvapich2-%{compiler_family}%{PROJ_DELIM}
%endif
%if "%{mpi_family}" == "openmpi3"
BuildRequires: openmpi3-%{compiler_family}%{PROJ_DELIM}
Requires:      openmpi3-%{compiler_family}%{PROJ_DELIM}
%endif
%endif

# Python dependencies and macros
%if 0%{?ohpc_python_dependent} == 1
%if "%{python_family}" == "python3"
%global __python %__python3
%global python_module_prefix py3-
%global python_lib_dir python3.4
%if "%{rhel_version}" == "700"
%global python_prefix python34
%endif
%if 0%{?suse_version}
%global python_prefix python3
%endif
%endif
%if "%{python_family}" == "python2"
%global python_module_prefix py2-
%global python_lib_dir python2.7
%global python_prefix python
%endif
BuildRequires: %{python_prefix}-devel
BuildRequires: %{python_prefix}-setuptools
BuildRequires: python-rpm-macros
Requires:      %{python_prefix}
%endif

%global ohpc_setup_compiler %{expand:\
    . %{OHPC_ADMIN}/ohpc/OHPC_setup_compiler %{compiler_family} \
    %if 0%{?ohpc_mpi_dependent} == 1 \
        . %{OHPC_ADMIN}/ohpc/OHPC_setup_mpi %{mpi_family} \
    %endif \
}

