File hdtv.spec of Package hdtv

%define debug_package %{nil}

%define rolling_version %(cat rpmbuild/SOURCES/hdtv.obsinfo | grep version | sed "s|version.*:||")

%define gcc_version 9

%if 0%{?sle_version} == 150500 && 0%{?is_opensuse}
%define pythons python3
%define fixed_version 22.11
%else
%if 0%{?sle_version} == 150600 && 0%{?is_opensuse}
%{?sle15_python_module_pythons}
%else
%define pythons %{primary_python}
%endif
%endif

Name:           hdtv
Version:        %{?fixed_version:%{fixed_version}}%{!?fixed_version:%{rolling_version}}
Release:        0
Summary:        Nuclear Spectrum Analysis Tool
License:        GPL-2.0
Group:          Productivity/Scientific/Physics
Url:            https://github.com/janmayer/hdtv
Source0:        %{name}%{?fixed_version:-prepython}.tar.gz

BuildRequires:  root
BuildRequires:  cmake
BuildRequires:  ( gcc-c++ >= %{gcc_version} or gcc%{gcc_version}-c++ )
BuildRequires:  ( gcc >= %{gcc_version} or gcc%{gcc_version} )
BuildRequires:  libX11-devel
BuildRequires:  mpich-devel
BuildRequires:  liburing2-devel

BuildRequires:  %{pythons}
BuildRequires:  %{python_module numpy}
#BuildRequires:  %{python_module scipy}
BuildRequires:  %{python_module matplotlib}
#BuildRequires:  %{python_module uncertainties}
BuildRequires:  %{python_module prompt_toolkit}

Requires:       %{pythons}
Requires:       %{python_module numpy}
#Requires:       %{python_module scipy}
#Requires:       %{python_module matplotlib}
#Requires:       %{python_module uncertainties}
Requires:       %{python_module prompt_toolkit}

%description
HDTV is a nuclear spectrum and coincidence matrix analysis tool. It can load uncompressed (text), compressed, and ROOT spectra and 2D-matrices. It calibrates spectra, fits peaks with background with different models, and cuts matrices. HDTV is written in a mixture of C++ and Python, glued together using PyROOT.

%prep
%setup -q -c -T %{name}-%{version}
tar -zxvf %{SOURCE0} --strip-components=1
sed -i "s|args\.rebuildusr\ or\ args\.rebuildsys:|args\.rebuildusr\ is\ not\ None\ or\ args.rebuildsys\ is\ not\ None:|g" hdtv/app.py
for file in `grep -r \#\!\/usr\/bin\/env\ python ./ | cut -f1 -d':'` ; do
   sed -i "s|#!/usr/bin/env python.*$|#!/usr/bin/python%{python_version}|" ${file}
done

%build

%install
install -d %{buildroot}%{_libdir}/%{name}
cp -r * %{buildroot}%{_libdir}/%{name}

export CC="$([ `command -v gcc-%{gcc_version}` ] && echo gcc-%{gcc_version} || echo gcc )"
export CXX="$([ `command -v g++-%{gcc_version}` ] && echo g++-%{gcc_version} || echo g++ )"
%{buildroot}%{_libdir}/%{name}/bin/%{name} --rebuild-sys

install -d %{buildroot}%{_bindir}
cd %{buildroot}%{_bindir}
echo "#!/bin/sh" > %{name}
echo "exec %{_libdir}/%{name}/bin/%{name} \"\$@\"" >> %{name}
chmod 775 ./%{name}

%files
%dir %{_libdir}/%{name}
%{_libdir}/%{name}/*
%{_bindir}/%{name}

%changelog
* Wed Sep 29 2021 Axiotis Michail
-Initial release of the hdtv
openSUSE Build Service is sponsored by