%define libname     rivet-release
%define libnamedev  rivet-release-devel
%global debug_package %{nil}
%global __spec_install_post   /usr/lib/rpm/check-buildroot 

Name:           rivet-release
Version:        3.1.x
Release:        1003%{?dist}
License:        GPLv3
Url:            http://rivet.hepforge.org/
Source0:        https://gitlab.com/hepcedar/rivet/-/archive/release-3-1-x/rivet-release-3-1-x.tar.gz

Prefix: %{_prefix}
Summary:        Robust Independent Validation of Experiment and Theory
Requires:       fastjet    ImageMagick tex(latex)  which
Requires:       YODA >= 1.9.0
Requires:       fjcontrib
BuildRequires:  fjcontrib fjcontrib-devel
BuildRequires:  binutils 
BuildRequires:  YODA >= 1.9.0 
BuildRequires:  YODA-devel >= 1.9.0
BuildRequires:  automake autoconf libtool  fastjet-devel  fastjet 
BuildRequires:  rsync
%if %{?fedora}%{!?fedora:0} || %{?rhel}%{!?rhel:0}
Requires:       zlib gsl
BuildRequires:  zlib zlib-devel gsl gsl-devel 
Requires:       HepMC3 = 3.2.7
Requires:       HepMC3-search
BuildRequires:  HepMC3-devel
BuildRequires:  HepMC3-search-devel
%if %{?fedora}%{!?fedora:0} >= 39
BuildRequires: python3-rpm-macros
%endif
%endif
%if 0%{?suse_version}
Requires:       pkgconfig(zlib) pkgconfig(gsl)
BuildRequires:  pkgconfig(zlib) zlib-devel pkgconfig(gsl) gsl-devel  python3-setuptools
%endif

%if %{?rhel}%{!?rhel:0} >= 8
BuildRequires: python3 python3-devel  platform-python-devel python3-Cython
Requires:      python3-YODA
%endif
%if %{?fedora}%{!?fedora:0}
%if %{?fedora}%{!?fedora:0} >= 35
BuildRequires: python-setuptools
%endif
BuildRequires:   Cython python3 python3-devel python3-libs 
Requires:        python3-YODA python3-matplotlib
%endif
%if %{?fedora}%{!?fedora:0} || %{?rhel}%{!?rhel:0} >= 8
BuildRequires: gcc-c++ gcc-gfortran
%endif
%if 0%{?suse_version}
BuildRequires: gcc-c++ gcc-fortran python3-Cython python3-devel  python3-setuptools
%endif


%description
The Rivet project (Robust Independent Validation of Experiment and Theory) 
is a toolkit for validation of Monte Carlo event generators. It provides a
large (and ever growing) set of experimental analyses useful for MC generator 
development, validation, and tuning, as well as a convenient infrastructure for
 adding your own analyses. Rivet is the most widespread way by which analysis code 
 from the LHC and other high-energy collider experiments is preserved for comparison 
 to and development of future theory models. 




%package  devel
Summary:        Libraries and headers for %{name}
Provides:       %{name}-devel = %{version}-%{release}
Requires:       YODA-devel >= 1.8.0
%description devel
%{libnamedev} contains the libraries and header files needed to
develop programs which make use of %{name}.
The library documentation is available on header files.


%prep
%setup -q -n %{name}-3-1-x

%build

%if %{?fedora}%{!?fedora:0} || %{?rhel}%{!?rhel:0} >= 8
export PYTHON=%{_bindir}/python3
export CXXFLAGS="-g -Wformat -Wno-error -fPIC"  
%if %{?fedora}%{!?fedora:0} >= 39
%py3_shebang_fix  ./
%py3_shebang_fix  bin/rivet*
%py3_shebang_fix  bin/make-*
%else
pathfix.py -pn -i %{__python3}  ./
pathfix.py -pn -i %{__python3}  bin/rivet*
pathfix.py -pn -i %{__python3}  bin/make-*
%endif
autoreconf --force --install --verbose .
automake -a --force
%configure  --disable-doxygen --with-yoda=$(yoda-config --prefix ) --with-hepmc3=$(HepMC3-config --prefix) --with-fjcontrib=/usr --with-fastjet=$(fastjet-config --prefix)
make %{?_smp_mflags}
%endif


%if 0%{?suse_version}
export PYTHON_VERSION=%{py3_ver}
export PYTHON=%{_bindir}/python%{py3_ver}
export CXXFLAGS="-Wno-error -fPIC"  
autoreconf --force --install --verbose .
automake -a --force
%configure  --disable-doxygen --with-yoda=$(yoda-config --prefix ) --with-hepmc3=$(HepMC3-config --prefix) --with-fjcontrib=/usr --with-fastjet=$(fastjet-config --prefix)
make %{?_smp_mflags}
%endif


%install
%make_install 
find %{buildroot}/%{_libdir}/ -name "*.la" -delete
rm -fr %{buildroot}/%_libdir/python*/site-packages/__pycache__  
rm -fr %{buildroot}/%_libdir/python*/site-packages/easy-install.pth
rm -fr %{buildroot}/%_libdir/python*/site-packages/site.py

%files 
%{_bindir}/*
%_libdir/pkgconfig/*
%_libdir/*.*so*
%_libdir/python*/site-packages/*
%_libdir/Rivet/*
%{_sysconfdir}/bash_completion.d/*
/usr/share/Rivet/*

%files -n %{libnamedev}
%{_includedir}/Rivet/*