File scotch.spec of Package scotch

#
# spec file for package scotch
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%global flavor @BUILD_FLAVOR@%{nil}

%define base_pname scotch
%define vers 7.0.4
%define _vers 7_0_4
%define so_ver %{_vers}

%if "%{flavor}" == ""
ExclusiveArch:  do_not_build
 %define package_name %pname
%endif

%if "%{flavor}" == "serial"
%bcond_with hpc
%endif

%if "%{flavor}" == "openmpi4"
%{?DisOMPI4}
%global mpi_family openmpi
%bcond_with hpc
%define mpi_vers 4
%endif

%if "%{flavor}" == "openmpi5"
%{?DisOMPI5}
%global mpi_family openmpi
%bcond_with hpc
%define mpi_vers 5
%endif

%if "%{flavor}" == "mvapich2"
%global mpi_family %{flavor}
%bcond_with hpc
%endif

%if "%{flavor}" == "mpich"
%global mpi_family %{flavor}
%bcond_with hpc
BuildRequires:  chrpath
%endif

%if "%{flavor}" == "gnu-hpc"
%bcond_without hpc
%global compiler_family gnu
%undefine c_f_ver
%endif

%if "%{flavor}" == "gnu-mvapich2-hpc"
%bcond_without hpc
%define compiler_family gnu
%undefine c_f_ver
%global mpi_family mvapich2
%endif

%if "%{flavor}" == "gnu-mpich-hpc"
%bcond_without hpc
%define compiler_family gnu
%undefine c_f_ver
%global mpi_family mpich
%endif

%if "%{flavor}" == "gnu-openmpi4-hpc"
%{?DisOMPI4}
%bcond_without hpc
%define compiler_family gnu
%undefine c_f_ver
%global mpi_family openmpi
%define mpi_vers 4
%endif

%if "%{flavor}" == "gnu-openmpi5-hpc"
%{?DisOMPI5}
%bcond_without hpc
%define compiler_family gnu
%undefine c_f_ver
%global mpi_family openmpi
%define mpi_vers 5
%endif

# Don't build non-HPC on SLE
%if !0%{?is_opensuse} && !0%{?with_hpc:1}
ExclusiveArch:  do_not_build
%endif

%if 0%{?with_hpc}
%bcond_with mumps
%else
%bcond_without mumps
%endif

%{?mpi_family:%{bcond_without mpi}}%{!?mpi_family:%{bcond_with mpi}}
%{?with_hpc:%{!?compiler_family:%global compiler_family gnu}}
%{?with_mpi:%{!?mpi_family:error "No MPI family specified!"}}

%define mpi_ext %{?mpi_vers}

%if %{without mpi}
%define pname %{base_pname}
%define metis metis
%else
%define pt_pref pt
%define pname pt%{base_pname}
%define metis parmetis
%endif

%if %{with hpc}
ExcludeArch:    %ix86
%{hpc_init -c %compiler_family %{?with_mpi:-m %mpi_family} %{?c_f_ver:-v %{c_f_ver}} %{?mpi_vers:-V %{mpi_vers}} %{?ext:-e %{ext}}}
 %define my_prefix %hpc_prefix
 %define my_bindir %hpc_bindir
 %define my_libdir %hpc_libdir
 %define my_incdir %hpc_includedir
 %define my_mandir %hpc_mandir
 %define package_name   %{hpc_package_name %_vers}
 %define f_name(ln:s:)   %{-l:lib}%{pname}%{-n*}%{hpc_package_name_tail %{?_vers}}
%else
 %if %{without mpi}
  %define my_prefix %_prefix
  %define my_bindir %_bindir
  %define my_libdir %_libdir
  %define my_incdir %_includedir
  %define my_mandir %_mandir
 %else
  %define my_suffix -%{mpi_family}%{?mpi_ext}
  %define my_prefix %{_libdir}/mpi/gcc/%{mpi_family}%{?mpi_ext}
  %define my_bindir %{my_prefix}/bin
  %define my_libdir %{my_prefix}/%{_lib}/
  %define my_incdir %{my_prefix}/include/
  %define my_mandir %{my_prefix}/share/man
 %endif
 %if 0%{!?package_name:1}
  %define package_name   %pname%{?my_suffix}
 %endif
 %define f_name(ln:s:)   %{-l:lib}%{pname}%{-n*}%{-s*}%{?my_suffix}
%endif

Summary:        Graph, mesh and hypergraph partitioning library
License:        CECILL-C
Group:          Productivity/Scientific/Math
Name:           %{package_name}
Version:        %{vers}
Release:        0
URL:            https://gitlab.inria.fr/scotch/scotch
Source0:        %{url}/-/archive/v%{version}/%{base_pname}-v%{version}.tar.gz
# PATCH-FIX-UPSTREAM scotch-cmake-installdirs.patch badshah400@gmail.com -- Fix install dirs in CMakeLists.txt
Patch0:         scotch-cmake-installdirs.patch
BuildRequires:  bison
BuildRequires:  cmake
BuildRequires:  fdupes
BuildRequires:  flex
BuildRequires:  make
BuildRequires:  pkgconfig(bzip2)
BuildRequires:  pkgconfig(liblzma)
BuildRequires:  pkgconfig(zlib)
%if %{without hpc}
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  gcc-fortran
%if %{with mpi}
BuildRequires:  %{mpi_family}%{?mpi_ext}-devel
%endif
%else
# hpc
BuildRequires:  %{compiler_family}%{?c_f_ver}-compilers-hpc-macros-devel
BuildRequires:  lua-lmod  >= 7.6.1
BuildRequires:  suse-hpc >= 0.2
Requires:       %{f_name -l -s %{so_ver}} = %version
%if %{with mpi}
BuildRequires:  %{mpi_family}%{?mpi_vers}-%{compiler_family}%{?c_f_ver}-hpc-macros-devel
%endif
%endif

%description
Scotch is a software package for graph and mesh/hypergraph partitioning and
sparse matrix ordering.

%{?with_hpc:%{hpc_master_package -L}}

%package     -n %{f_name -l -s %{so_ver}}
Summary:        Graph, mesh and hypergraph partitioning library
Group:          System/Libraries
%if %{without hpc}
 %if %{with mpi}
BuildRequires:  libscotch%{so_ver}
Requires:       libscotch%{so_ver}
 %endif
%else
%hpc_requires
Requires:       lua-lmod  >= 7.6.1
%endif

%description -n %{f_name -l -s %{so_ver}}
Scotch is a software package for graph and mesh/hypergraph partitioning and
sparse matrix ordering.

%{?with_hpc:%{hpc_master_package -L -l -n lib%{pname}%{hpc_package_name_tail}}}

%package     devel
Summary:        Development libraries for scotch
Group:          Development/Libraries/C and C++
Requires:       %{f_name -l -s %{so_ver}} = %{version}
%if %{without hpc}
Requires:       gcc-fortran
%if %{with mpi}
Requires:       %{mpi_family}%{?mpi_ext}-devel
%else
Requires:       %{f_name -l -s %{so_ver}}
%endif
%else
%hpc_requires_devel
%endif

%description devel
This package contains development libraries for libscotch.

%{?with_hpc:%{hpc_master_package -L devel}}

%package     -n %{f_name -n -%{metis}}-devel
Summary:        Development libraries for scotch
Group:          Development/Libraries/C and C++
%{?!with_hpc:%{?!with_mpi:Conflicts:      metis-devel}}
Requires:       %{f_name -l -s %{so_ver}}
Requires:       %{f_name}-devel = %{version}

%description -n %{f_name -n -%{metis}}-devel
This package contains the devel libraries and header file in the case
scotch is used as a replacement of the metis library.

%package -n %{pname}-doc
Summary:        Documentation for %{pname}
BuildArch:      noarch

%description -n %{pname}-doc
This package provides documentation for scotch.

%prep
%autosetup -p1 -n scotch-v%{version}

%build
%if %{with hpc}
%hpc_setup
%hpc_debug
%else
export CC=gcc
export CXX=g++
%{?with_mpi:source %{my_bindir}/mpivars.sh}
%endif
%{?with_mpi:export CC=mpicc CXX=mpic++}
%define CFLAGS %{optflags}

%cmake \
  -DCMAKE_C_COMPILER=${CC} \
  -DCMAKE_CXX_COMPILER=${CXX} \
  -DCMAKE_C_FLAGS:STRING=${CFLAGS} \
  -DCMAKE_CXX_FLAGS:STRING=${CFLAGS} \
  -DCMAKE_SHARED_LINKER_FLAGS:STRING=${LDFLAGS} \
  -DCMAKE_INSTALL_PREFIX:PATH=%{my_prefix} \
  -DCMAKE_INSTALL_INCLUDEDIR:PATH=%{my_incdir} \
  -DCMAKE_INSTALL_MANDIR:PATH=%{my_mandir} \
  -DBUILD_PTSCOTCH:BOOL=%{?with_mpi:ON}%{!?with_mpi:OFF} \
  %{nil}
%cmake_build

%install
%if %{with hpc}
%hpc_setup
%else
export CC=gcc
%{?with_mpi:source %{my_bindir}/mpivars.sh}
%endif
%{?with_mpi:export CC=mpicc}

%cmake_install

# Leftover RPATHS seem to be an exclusively mpich problem
%if "%{flavor}" == "mpich"
chrpath -d %{buildroot}%{my_bindir}/*
chrpath -d %{buildroot}%{my_libdir}/*.so*
%endif

%if %{with hpc}
%hpc_write_modules_files
#%%Module1.0#####################################################################

proc ModulesHelp { } {

puts stderr " "
puts stderr "This module loads the Scotch library built with the %{compiler_family} compiler"
puts stderr "toolchain and the %{mpi_family}%{?mpi_vers} MPI stack."
puts stderr " "

puts stderr "\nVersion %{version}\n"

}
module-whatis "Name: %{pname} built with %{compiler_family} compiler and %{mpi_family}%{?mpi_vers} MPI"
module-whatis "Version: %{version}"
module-whatis "Category: runtime library"
module-whatis "Description: %{SUMMARY:0}"
module-whatis "%{url}"

set     version                     %{version}

if {[file isdirectory  %{hpc_bindir}]} {
prepend-path    PATH                %{hpc_bindir}
}
prepend-path    MANPATH             %{hpc_mandir}
if {[file isdirectory  %{hpc_includedir}]} {
prepend-path    INCLUDE             %{hpc_includedir}
}
prepend-path    LD_LIBRARY_PATH     %{hpc_libdir}

setenv          %{hpc_upcase %pname}_DIR        %{hpc_prefix}
setenv          %{hpc_upcase %pname}_BIN        %{hpc_bindir}
if {[file isdirectory  %{hpc_includedir}]} {
setenv          %{hpc_upcase %pname}_LIB        %{hpc_libdir}
}
setenv          %{hpc_upcase %pname}_INC        %{hpc_includedir}
EOF

%endif
# without hpc

# Automatic gzipping of man files only works on %%_mandir; workaround for hpc, mpi builds
%if %{with hpc} || %{with mpi}
for f in %{buildroot}%{my_mandir}/man1/*.1
do
  gzip ${f}
done
%endif

%fdupes %{buildroot}%{my_bindir}
%fdupes %{buildroot}%{my_mandir}

%if %{without mpi} && %{without hpc}
%post -n %{f_name -l -s %so_ver} -p /sbin/ldconfig
%postun -n %{f_name -l -s %so_ver} -p /sbin/ldconfig
%else

# HPC and MPI package install to non-standard locations: don't update cache
%post -n %{f_name -l -s %so_ver}
/sbin/ldconfig -N %{my_libdir}

%postun -n %{f_name -l -s %so_ver}
/sbin/ldconfig -N %{my_libdir}
%{?with_hpc:%hpc_module_delete_if_default}
%endif

%files
%doc README.txt
%license doc/CeCILL-*
%if %{with hpc}
%{my_bindir}
%dir %{hpc_datadir}
%else
%{my_bindir}/%{!?with_mpi:*}
%endif
%{?with_mpi:%dir %{my_mandir}/man1}
%{my_mandir}/man1/*.1%{ext_man}

%files -n %{f_name -l -s %{so_ver}}
%{?with_hpc:%hpc_dirs}
%{?with_hpc:%hpc_modules_files}
%{my_libdir}/*.so.*

%files devel
%{?with_hpc:%dir %{my_incdir}}
%{my_libdir}/*.so
%{my_incdir}/*.h
%{?with_mpi:%dir %{my_libdir}/cmake}
%{my_libdir}/cmake/*

%if %{without hpc} && %{without mpi}
%files -n %{pname}-doc
%doc doc/*.pdf
%endif

%changelog
openSUSE Build Service is sponsored by