%global pkgvers 0
%global scdate0 20250321
%global schash0 e825856a8b7eea6e9110ec39c0d1d29b580ce261
%global branch0 main
%global source0 https://github.com/pytorch/fbgemm.git

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

Name:           fbgemm
Version:        1.1.0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Facebook GEneral Matrix Multiplication
License:        BSD

URL:            https://github.com/pytorch/fbgemm

ExclusiveArch:  %{ix86} x86_64

BuildRequires:  cmake gcc-c++ git python3
BuildRequires:  asmjit-devel cpuinfo-devel

%global _lto_cflags %{nil}
%global __cmake_in_source_build 1

%description
Facebook GEneral Matrix Multiplication

%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
# only external
rm -rf third_party
sed -i '/-Werror/d' CMakeLists.txt
sed -i 's|hidden|default|' CMakeLists.txt
sed -i '/NOT TARGET cpuinfo/,/^endif/d' CMakeLists.txt
sed -i '/NOT TARGET asmjit/,/^endif/d' CMakeLists.txt
sed -i '/add_dependencies(fbgemm$/,/cpuinfo)/d' CMakeLists.txt
sed -i 's|$<BUILD_INTERFACE:asmjit>|asmjit|' CMakeLists.txt
sed -i 's|$<BUILD_INTERFACE:cpuinfo>|cpuinfo|' CMakeLists.txt
sed -i '$a set_target_properties(fbgemm PROPERTIES SOVERSION 1 VERSION 1.0)' CMakeLists.txt
# gcc13
sed -i '1i #include <cstdint>' include/fbgemm/UtilsAvx2.h


%build
mkdir build
pushd build
export CXX_FLAGS="%{optflags} -fpermissive"
%cmake .. \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DCMAKE_INSTALL_LIBDIR=%{_libdir} \
       -DFBGEMM_LIBRARY_TYPE="shared" \
       -DFBGEMM_BUILD_TESTS=OFF \
       -DFBGEMM_BUILD_BENCHMARKS=OFF \
       -DCPUINFO_SOURCE_DIR="%{_includedir}"

make %{?_smp_mflags}
popd


%install
rm -rf %{buildroot}

pushd build
make install DESTDIR=%{buildroot}
popd

for f in `find ./src -type f -name '*.h'`;
do
  install -D -pm 644 $f %{buildroot}%{_includedir}/%{name}/$f
done


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

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


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