## START: Set by rpmautospec
## (rpmautospec version 0.6.0)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 36;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Switch them off if you want
# Best to start with the serial version
%bcond_without mpich
%bcond_without openmpi

# Do not currently use system sundials
# https://bugzilla.redhat.com/show_bug.cgi?id=1820991
# https://github.com/CNS-OIST/STEPS/issues/23
%bcond_with system_sundials

%global _description %{expand:
STEPS is a package for exact stochastic simulation of reaction-diffusion
systems in arbitrarily complex 3D geometries. Our core simulation algorithm is
an implementation of Gillespie's SSA, extended to deal with diffusion of
molecules over the elements of a 3D tetrahedral mesh.

While it was mainly developed for simulating detailed models of neuronal
signaling pathways in dendrites and around synapses, it is a general tool and
can be used for studying any biochemical pathway in which spatial gradients and
morphology are thought to play a role.

STEPS also supports accurate and efficient computational of local membrane
potentials on tetrahedral meshes, with the addition of voltage-gated channels
and currents. Tight integration between the reaction-diffusion calculations and
the tetrahedral mesh potentials allows detailed coupling between molecular
activity and local electrical excitability.

We have implemented STEPS as a set of Python modules, which means STEPS users
can use Python scripts to control all aspects of setting up the model,
generating a mesh, controlling the simulation and generating and analyzing
output. The core computational routines are still implemented as C/C++
extension modules for maximal speed of execution.

STEPS 3.0.0 and above provide early parallel solution for stochastic spatial
reaction-diffusion and electric field simulation.

Documentation can be found here:
http://steps.sourceforge.net/manual/manual_index.html}

Name:           python-steps
Version:        3.6.0
Release:        %autorelease
Summary:        STochastic Engine for Pathway Simulation

License:        GPLv2
URL:            http://steps.sourceforge.net/
Source0:        https://github.com/CNS-OIST/STEPS/archive/%{version}/STEPS-%{version}.tar.gz

%if %{without system_sundials}
# Version based on path: src/third_party/cvode-VERSION
%global sundials_version 2.6.0
%endif

# Patches generated from: https://github.com/sanjayankur31/STEPS/tree/fedora-3.5.0
# use system gtest
Patch:          0001-Unbundle-gtest.patch
# Remove flags they set
Patch:          0003-Remove-flags-set-by-project.patch
# Remove pysteps flags
Patch:          0004-Remove-pysteps-flags.patch
# We'll install manually, much easier and cleaner
Patch:          0005-Disable-pyinstall.patch
# Use pytest instead of NOSE
# Sent upstream: https://github.com/CNS-OIST/STEPS/pull/24
Patch:          0001-feat-replace-nose-invocations-with-pytest.patch
# libstepsutil is not meant to be a separate shared object
Patch:          0002-Make-libstepsutil-static.patch
# Add more template function to match
Patch:          0007-template-matching-collections_hpp.patch
# Add a missing #include directive
# Fixes failure to compile with GCC 13.
# https://github.com/CNS-OIST/STEPS/pull/29
Patch:          https://github.com/CNS-OIST/STEPS/pull/29.patch

# https://fedoraproject.org/wiki/Changes/EncourageI686LeafRemoval
ExcludeArch:    %{ix86}

BuildRequires:  make
BuildRequires:  cmake
BuildRequires:  gcc-c++
BuildRequires:  pkgconfig(gtest_main)
BuildRequires:  petsc-devel
BuildRequires:  python3-devel
BuildRequires:  %{py3_dist Cython}
BuildRequires:  %{py3_dist matplotlib}
BuildRequires:  %{py3_dist numpy}
BuildRequires:  %{py3_dist pytest}
BuildRequires:  %{py3_dist scipy}
BuildRequires:  %{py3_dist setuptools}
BuildRequires:  flexiblas-devel
BuildRequires:  Random123-devel
# The -static BR is required for tracking of header-only libraries
BuildRequires:  pkgconfig(easyloggingpp)
BuildRequires:  easyloggingpp-static

%if %{with system_sundials}
BuildRequires:  sundials2-devel
%endif

%description
%{_description}


%package -n python3-steps
Summary:        STochastic Engine for Pathway Simulation

Provides:       steps = %{version}-%{release}
%if %{without system_sundials}
Provides:       bundled(sundials2) = %{sundials_version}
%endif

%description -n python3-steps %{_description}


%if %{with openmpi}
%package -n python3-steps-openmpi
Summary:        steps built with openmpi

BuildRequires:  openmpi-devel
BuildRequires:  petsc-openmpi-devel
BuildRequires:  rpm-mpi-hooks
%if %{with system_sundials}
BuildRequires:  sundials2-openmpi-devel
%endif

Requires:       openmpi

%if %{without system_sundials}
Provides:       bundled(sundials2) = %{sundials_version}
%endif

%description -n python3-steps-openmpi %{_description}
%endif


%if %{with mpich}
%package -n python3-steps-mpich
Summary:        steps built with mpich

BuildRequires:  mpich-devel
BuildRequires:  petsc-mpich-devel
BuildRequires:  rpm-mpi-hooks
%if %{with system_sundials}
BuildRequires:  sundials2-mpich-devel
%endif

Requires:       mpich

%if %{without system_sundials}
Provides:       bundled(sundials2) = %{sundials_version}
%endif

%description -n python3-steps-mpich
%{_description}
%endif


%prep
%autosetup -n STEPS-%{version} -N
# use the copy that cmake ships instead of the older outdated copy that
# upstream bundles
rm -rf CMake/FindBLAS.cmake
%autopatch -p1

# gtest/gmock 1.13.0 requires C++14 or later
sed -r -i 's/(CXX_DIALECT_OPT_CXX)11/\114/' CMakeLists.txt

%if %{with system_sundials}
# We add %%{_includedir}/sundials2 to the CXXFLAGS in %%build; we must also
# alter any includes that start with sundials/ in order to use the sundials2
# compatibility package. The find-then-modify pattern preserves mtimes on
# sources that did not need to be modified.
find 'src' -type f \( -name '*.c*' -o -name '*.h*' \) -exec gawk \
    '/^#include +[<"]sundials\// { print FILENAME; nextfile }' '{}' '+' |
  xargs -r sed -r -i 's@^(#include +[<"])sundials/@\1@'
%endif

# Remove bundled dependencies that we have unbundled:
rm -rvf \
%if %{with system_sundials}
    src/third_party/cvode* \
%endif
    src/third_party/easyloggingpp \
    src/third_party/superlu* \
    src/third_party/Random123*

# Finding an unbundled easylogging++ via pkg_check_modules() doesn’t work quite
# the way upstream intended. The CMake variable EASYLOGGINGPP_INCLUDE_DIRS is
# not set, but upstream expects to use that to find the source file
# easylogging++.cc, and defining it manually
# (-DEASYLOGGINGPP_INCLUDE_DIRS:PATH=…) without a corresponding set() in a
# CMakeLists.txt somewhere does not seem to work.
#
# We could patch in “set(EASYLOGGINGPP_INCLUDE_DIRS %%{_includedir})” to the
# top-level CMakeLists.txt in the case where USE_BUNDLE_EASYLOGGINGPP is false,
# but it’s easier just to symlink the system files to the expected bundled
# location and let the build system think it is stil bundled.
mkdir -p src/third_party/easyloggingpp/src
ln -s %{_includedir}/easylogging++.h %{_includedir}/easylogging++.cc \
    src/third_party/easyloggingpp/src/

# Build directories
mkdir build
%if %{with openmpi}
mkdir build-openmpi
%endif

%if %{with mpich}
mkdir build-mpich
%endif


%build
# Best to use && so that if anything in the chain fails, the build also fails
# straight away
%global do_cmake_config %{expand: \
echo
echo "*** BUILDING steps-%{version}$MPI_COMPILE_TYPE ***"
echo
%set_build_flags
export CXXFLAGS="${CXXFLAGS-} $(pkgconf --cflags gtest_main) $(pkgconf --libs gtest_main)"
%if %{with system_sundials}
# Correct for sundials2
export CXXFLAGS="${CXXFLAGS-} -I%{_includedir}/sundials2"
%endif
pushd build$MPI_COMPILE_TYPE &&
  cmake \\\
      -DUSE_BUNDLE_EASYLOGGINGPP:BOOL="ON" \\\
      -DUSE_BUNDLE_RANDOM123:BOOL="OFF" \\\
%if %{with system_sundials}
      -DUSE_BUNDLE_SUNDIALS:BOOL="OFF" \\\
      -DSUNDIALS_DIR:PATH=%{_prefix} \\\
      -DSUNDIALS_INCLUDE_DIR:PATH=%{_includedir} \\\
      -DSUNDIALS_LIBRARY_DIR:PATH=%{_libdir} \\\
%else
      -DUSE_BUNDLE_SUNDIALS:BOOL="ON" \\\
      -DSUNDIALS_DIR:PATH=../src/third_party/cvode-2.6.0 \\\
      -DSUNDIALS_INCLUDE_DIR:PATH=../src/third_party/cvode-2.6.0/include \\\
%endif
      -DCMAKE_C_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
      -DCMAKE_CXX_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
      -DCMAKE_Fortran_FLAGS_RELEASE:STRING="-DNDEBUG" \\\
      -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \\\
      -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF \\\
      -DCMAKE_INSTALL_PREFIX:PATH=$MPI_HOME \\\
      -DINCLUDE_INSTALL_DIR:PATH=%{_includedir} \\\
      -DLIB_INSTALL_DIR:PATH=%{_libdir} \\\
      -DSYSCONF_INSTALL_DIR:PATH=%{_sysconfdir} \\\
      -DSHARE_INSTALL_PREFIX:PATH=%{_datadir} \\\
      -DPYTHON_INSTALL_PREFIX:PATH=$MPI_PYTHON3_SITEARCH \\\
      -DCMAKE_SKIP_RPATH:BOOL=ON \\\
      -DUSE_MPI:BOOL=$MPI_YES \\\
      -DUSE_PETSC:BOOL="OFF" \\\
      -DBLA_VENDOR:STRING=FlexiBLAS \\\
      -DBLA_PREFER_PKGCONFIG:BOOL=True \\\
      -DBUILD_SHARED_LIBS:BOOL="ON" \\\
%if "%{_lib}" == "lib64"
      -DLIB_SUFFIX=64 ../ &&
%else
      -DLIB_SUFFIX="" ../ &&
%endif
  popd || exit -1
}

%global do_make_build %{expand: \
%make_build -C build$MPI_COMPILE_TYPE &&
  pushd pysteps &&
  CFLAGS="%{optflags}" \\\
      LDFLAGS="%{__global_ldflags}" \\\
      %{python3} \\\
      "../build$MPI_COMPILE_TYPE/pysteps/cmake_setup.py" \\\
      build \\\
      --executable="%{python3} %{py3_shbang_opts}" \\\
      --build-base="../build$MPI_COMPILE_TYPE/pysteps/build/" &&
  popd || exit -1
}

# Build serial version, dummy arguments
export MPI_COMPILE_TYPE=""
export MPI_COMPILER=serial
export MPI_SUFFIX=""
export MPI_HOME=%{_prefix}
export MPI_BIN=%{_bindir}
export MPI_PYTHON3_SITEARCH=%{python3_sitearch}
export MPI_YES="False"
%{do_cmake_config}
%{do_make_build}

# Build mpich version
%if %{with mpich}
%{_mpich_load}
export CC=mpicc
export CXX=mpicxx
export FC=mpif90
export F77=mpif77
export MPI_YES="True"
export MPI_COMPILE_TYPE="-mpich"
%{do_cmake_config}
%{do_make_build}
%{_mpich_unload}
%endif

# Build OpenMPI version
%if %{with openmpi}
%{_openmpi_load}
export CC=mpicc
export CXX=mpicxx
export FC=mpif90
export F77=mpif77
export MPI_YES="True"
export MPI_COMPILE_TYPE="-openmpi"
%{do_cmake_config}
%{do_make_build}
%{_openmpi_unload}
%endif


%install
# Install everything
%global do_install %{expand: \
echo
echo "*** INSTALLING steps-%{version}$MPI_COMPILE_TYPE ***"
echo
%make_install CPPROG="cp -p" -C build$MPI_COMPILE_TYPE || exit -1
pushd pysteps &&
  CFLAGS="%{optflags}" \\\
      LDFLAGS="%{__global_ldflags}" \\\
      %{python3} \\\
      "../build$MPI_COMPILE_TYPE/pysteps/cmake_setup.py" \\\
      build \\\
      --executable="%{python3} %{py3_shbang_opts}" \\\
      --build-base="../build$MPI_COMPILE_TYPE/pysteps/build/" \\\
      install \\\
      --install-lib=$MPI_PYTHON3_SITEARCH \\\
      -O1 \\\
      --skip-build \\\
      --root $RPM_BUILD_ROOT &&
  popd || exit -1
}

# install serial version
export MPI_COMPILE_TYPE=""
export MPI_SUFFIX=""
export MPI_HOME=%{_prefix}
export MPI_BIN=%{_bindir}
export MPI_YES="False"
export MPI_COMPILE_TYPE=""
export MPI_PYTHON3_SITEARCH="%{python3_sitearch}"
%{do_install}

# Install MPICH version
%if %{with mpich}
%{_mpich_load}
export MPI_YES="True"
export MPI_COMPILE_TYPE="-mpich"
%{do_install}
%{_mpich_unload}
%endif

# Install OpenMPI version
%if %{with openmpi}
%{_openmpi_load}
export MPI_YES="True"
export MPI_COMPILE_TYPE="-openmpi"
%{do_install}
%{_openmpi_unload}
%endif


%files -n python3-steps
%license LICENSE.md
%{python3_sitearch}/steps
%{python3_sitearch}/steps-%{version}-py%{python3_version}.egg-info


%if %{with mpich}
%files -n python3-steps-mpich
%license LICENSE.md
%{python3_sitearch}/mpich/steps
%{python3_sitearch}/mpich/steps-%{version}-py%{python3_version}.egg-info
%endif


%if %{with openmpi}
%files -n python3-steps-openmpi
%license LICENSE.md
%{python3_sitearch}/openmpi/steps
%{python3_sitearch}/openmpi/steps-%{version}-py%{python3_version}.egg-info
%endif


%changelog
## START: Generated by rpmautospec
* Fri Jul 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-36
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Sat Jun 08 2024 Python Maint <python-maint@redhat.com> - 3.6.0-35
- Rebuilt for Python 3.13

* Fri Jan 26 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-34
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Jan 22 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-33
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Mon Oct 30 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-32
- Rebuild for gtest 1.14.0

* Sun Oct 29 2023 Orion Poplawski <orion@nwra.com> - 3.6.0-31
- Rebuild for openmpi 5.0.0, drops C++ API

* Fri Jul 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-30
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Tue Jun 27 2023 Python Maint <python-maint@redhat.com> - 3.6.0-29
- Rebuilt for Python 3.12

* Fri Feb 03 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-28
- Leaf package on ix86: drop ix86 support

* Tue Jan 24 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-27
- Rebuilt for gtest 1.13.0 (fix RHBZ#2164003)
- Build with C++14 instead of C++11, since gtest dropped support
- Add a missing #include directive for GCC 13

* Tue Jan 24 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-26
- Remove old easylogging++ sources from dist-git

* Fri Jan 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-25
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Thu Sep 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-24
- Tidy up spec file formatting

* Thu Sep 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-23
- Stop numbering patches

* Thu Sep 08 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-22
- Unbundle easyloggingpp

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-21
- Improve treatment of bundled sundials(2)
- Unbundling currently works up to linking, where there are undefined
  references

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-20
- Use more standard macros where we can

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-19
- Add -DCMAKE_INSTALL_DO_STRIP:BOOL=OFF to match %%%%cmake

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-18
- Use pkgconf to set unbundled gtest flags

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-17
- Simplify patch application

* Mon Aug 29 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-16
- Better handle bundled easyloggingpp dependency

* Thu Aug 18 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-15
- Remove unbundled dependencies in %%%%prep

* Thu Aug 18 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-14
- Remove workaround for pre-flexiblas Fedora versions

* Thu Aug 18 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-13
- Reduce macro indirection in the spec file

* Fri Jul 22 2022 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-12
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Sun Jul 10 2022 Ankur Sinha (Ankur Sinha Gmail) <sanjay.ankur@gmail.com> - 3.6.0-11
- fix: correct macro

* Tue Jul  5 2022 Mamoru TASAKA <mtasaka@fedoraproject.org> - 3.6.0-8
- Add more template funtion to match (bug 2046914)

* Wed Jun 15 2022 Python Maint <python-maint@redhat.com> - 3.6.0-7
- Rebuilt for Python 3.11

* Fri Jan 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-6
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Mon Oct 18 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.6.0-5
- Rebuild for PETSc-3.16.0

* Sun Sep 05 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 3.6.0-4
- Rebuild for gtest 1.11.0

* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.6.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Mon Jun 28 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.6.0-2
- Fix requires

* Sat Jun 26 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.6.0-1
- Merge https://src.fedoraproject.org/rpms/python-steps/pull-request/2 manually
- Release 3.6.0
- Update Patch2
- Use bundled cvode-2.6.0 (upstream bug #23)

* Fri Jun 04 2021 Python Maint <python-maint@redhat.com> - 3.5.0-10
- Rebuilt for Python 3.10

* Mon May 17 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.5.0-9
- Rebuild for sundials update

* Wed Apr 21 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.5.0-8
- Rebuild for petsc update

* Wed Jan 27 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.5.0-7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Tue Oct 06 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.5.0-6
- Rebuild for sundials-5.4.0

* Thu Aug 27 2020 Iñaki Úcar <iucar@fedoraproject.org> - 3.5.0-5
- https://fedoraproject.org/wiki/Changes/FlexiBLAS_as_BLAS/LAPACK_manager

* Wed Jul 29 2020 Fedora Release Engineering <releng@fedoraproject.org> - 3.5.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_33_Mass_Rebuild

* Thu Jun 25 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.5.0-3
- Explicitly BR setuptools

* Tue May 26 2020 Miro Hrončok <mhroncok@redhat.com> - 3.5.0-2
- Rebuilt for Python 3.9

* Sat Apr 04 2020 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 3.5.0-1
- Initial rpmbuild

## END: Generated by rpmautospec