%global pkgvers 3
%global scdate0 20230201
%global schash0 70a77f485e8b934224f3a79efd8edcd84cd377b8
%global branch0 master
%global source0 https://github.com/Maratyszcza/nnpack.git

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

Name:           nnpack
Version:        0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Acceleration package for neural networks on multi-core CPUs
Epoch:          1
License:        BSD

URL:            https://github.com/Maratyszcza/nnpack

BuildRequires:  cmake gcc-c++ git
BuildRequires:  python3-devel python3-six
BuildRequires:  peachpy-python3 opcodes-python3 fp16-python3
BuildRequires:  cpuinfo-devel fxdiv-devel pthreadpool-devel psimd-devel fp16-devel

%global __cmake_in_source_build 1

%description
Acceleration package for neural networks on multi-core CPUs

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

%description    devel
This package contains the development files.


%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
# externals
sed -i '/PRIVATE fp16/d' CMakeLists.txt
sed -i '/PRIVATE psimd/d' CMakeLists.txt
sed -i '/PRIVATE fxdiv/d' CMakeLists.txt
sed -i '/NOT TARGET/,/ENDIF/d' CMakeLists.txt
sed -i -e 's/PROCESSOR MATCHES "^(i686/PROCESSOR MATCHES "^(ppc64le|i686/g' CMakeLists.txt
sed -i -e 's|COMMAND "PYTHONPATH=${PEACHPY_PYTHONPATH}"|COMMAND "NOPYTHONPATH=${PEACHPY_PYTHONPATH}"|g' CMakeLists.txt
sed -i -e 's|PROPERTIES PUBLIC_HEADER include/nnpack.h|PROPERTIES PUBLIC_HEADER include/nnpack.h SOVERSION 1 VERSION 1.0|g' CMakeLists.txt

mkdir build
pushd build
%cmake .. \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
%if 0%{?fedora} > 42
       -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
%endif
       -DNNPACK_BUILD_TESTS=OFF \
       -DNNPACK_BUILD_BENCHMARKS=OFF \
       -DPYTHON_SIX_SOURCE_DIR="%{python3_sitearch}" \
       -DPYTHON_ENUM_SOURCE_DIR="%{python3_sitearch}" \
       -DPYTHON_PEACHPY_SOURCE_DIR="%{python3_sitelib}/peachpy" \
       -DFP16_SOURCE_DIR="%{_includedir}" \
       -DPSIMD_SOURCE_DIR="%{_includedir}" \
       -DFXDIV_SOURCE_DIR="%{_includedir}" \
       -DCPUINFO_SOURCE_DIR="%{_includedir}" \
       -DPTHREADPOOL_SOURCE_DIR="%{_includedir}"
make %{?_smp_mflags}
popd


%install
rm -rf %{buildroot}

pushd build
make install DESTDIR=%{buildroot}
popd

mkdir -p %{buildroot}%{_libdir}
mv -f %{buildroot}/usr/lib/* %{buildroot}%{_libdir}/


rm -rf %{buildroot}/%{_includedir}/gmock
rm -rf %{buildroot}/%{_includedir}/gtest
rm -rf %{buildroot}/%{_libdir}/*.a


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

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


%changelog
* Tue Jul 11 2017 Cristian Balint <cristian.balint@gmail.com>
- github update releases