# 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_COMPILERS  %{OHPC_PUB}/compiler
%global OHPC_MPI_STACKS %{OHPC_PUB}/mpi
%global OHPC_APPS       %{OHPC_PUB}/apps
%global OHPC_LIBS       %{OHPC_PUB}/libs
%global OHPC_MODULES    %{OHPC_PUB}/modulefiles
%global OHPC_MODULEDEPS %{OHPC_PUB}/moduledeps
%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 gnu7}
%{!?mpi_family: %global mpi_family openmpi}

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

%if "%{compiler_family}" == "gnu7"
BuildRequires: gnu7-compilers%{PROJ_DELIM} >= 7.1.0
Requires:      gnu7-compilers%{PROJ_DELIM} >= 7.1.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

%endif

# MPI dependencies
%if 0%{?ohpc_mpi_dependent} == 1
%if "%{mpi_family}" == "impi"
BuildRequires: intel-mpi-devel%{PROJ_DELIM}
Requires:      intel-mpi-devel%{PROJ_DELIM}
%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}" == "openmpi"
BuildRequires: openmpi-%{compiler_family}%{PROJ_DELIM}
Requires:      openmpi-%{compiler_family}%{PROJ_DELIM}
%endif
%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 \
}
