%global pkgvers 0
%global scdate0 20241220
%global schash0 b56eab1682529cf0a7feb0360d5e362c935831c7
%global branch0 master
%global source0 https://github.com/shibatch/sleef.git

%global sshort0 %{expand:%%{lua:print(('%{schash0}'):sub(1,8))}}

%global vcu_maj 12
%global vcu_min 6

Name:           sleef
Version:        3.7
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Functions for evaluating some elementary functions
License:        Boost

URL:            https://github.com/shibatch/sleef

BuildRequires:  cmake gcc-c++ git
BuildRequires:  gmp-devel fftw-devel mpfr-devel glibc-devel openssl-devel ninja-build

%define have_cuda 0
%define have_cuda_gcc 0

%bcond_without cuda
%if %{without cuda}
%global have_cuda 0
%endif

%if %{have_cuda}
BuildRequires:  cuda-nvcc-%{vcu_maj}-%{vcu_min}
BuildRequires:  cuda-cudart-devel-%{vcu_maj}-%{vcu_min}
BuildRequires:  cuda-nvml-devel-%{vcu_maj}-%{vcu_min}
%endif

%global __cmake_in_source_build 1

%description
Functions for evaluating some elementary functions
are implemented. The library also includes DFT subroutines.

%package        devel
Summary:        Development files
Requires:       %{name} = %{version}-%{release}

%description    devel
This package contains the development files for %{name}.


%prep
%setup -T -c -n %{name}
git clone --depth 1 -n -b %{branch0} %{source0} .
git fetch --depth 1 origin %{schash0}
git reset --hard %{schash0}
git log --format=fuller


%build
sed -i 's|sleef_cpuidtmp|sleef_cpuid_tmp|g' src/libm/tryvsx3.c
mkdir build
pushd build
%ifarch ppc64le
export CFLAGS="%{optflags} -mcpu=power9 -mtune=power9"
%endif
%cmake .. -Wno-dev \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DBUILD_TESTS=OFF \
       -DBUILD_SHARED_LIBS=TRUE \
       -DENFORCE_TESTER3=TRUE \
       -DENABLE_GNUABI=ON \
       -DBUILD_SCALAR_LIB=TRUE \
       -DBUILD_QUAD=TRUE \
       -DBUILD_DFT=TRUE \
       -DBUILD_INLINE_HEADERS=TRUE \
%if %{have_cuda}
       -DENABLE_CUDA=ON \
       -DENFORCE_CUDA=TRUE \
%if %{have_cuda_gcc}
       -DCUDA_HOST_COMPILER="%{_bindir}/cuda-g++" \
       -DCMAKE_CUDA_HOST_COMPILER="%{_bindir}/cuda-g++" \
%endif
       -DCUDA_PROPAGATE_HOST_FLAGS=OFF \
       -DCMAKE_CUDA_FLAGS='--compiler-options -fpie' \
       -DCMAKE_CUDA_COMPILER='/usr/local/cuda-%{vcu_maj}.%{vcu_min}/bin/nvcc'
%else
       -DENABLE_CUDA=OFF
%endif
make %{?_smp_mflags}
popd


%install
rm -rf %{buildroot}

pushd build
make install DESTDIR=%{buildroot}
popd


%files
%license LICENSE.txt
%doc README.md
%{_libdir}/*.so.*

%files devel
%license LICENSE.txt
%doc README.md
%{_includedir}/*
%{_libdir}/*.so
%{_libdir}/pkgconfig/*
%{_libdir}/cmake/*


%changelog
* Fri Sep 25 2020 Cristian Balint <cristian.balint@gmail.com>
- github update releases