%global pkgvers 0
%global scdate0 20241220
%global schash0 6ea2c101ee6774a240ae6b4fcd8728d4a608e3cc
%global branch0 main
%global source0 https://github.com/hfp/libxsmm.git

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

Name:           libxsmm
Version:        1.17
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Small dense or sparse matrix multiplications and convolutions for x86_64
License:        BSD

URL:            https://github.com/hfp/libxsmm

BuildRequires:  make chrpath git gcc-gfortran gcc-c++ python3 openblas-devel

ExclusiveArch:  x86_64 aarch64

%description
LIBXSMM is a library for small dense and small sparse matrix-matrix
multiplications, as well as for deep learning primitives such as small
convolutions targeting Intel Architecture (x86).

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

%description    devel
The %name-devel package contains libraries and header files for
developing applications that use %{name}.

%package        doc
Summary:        Documentation for %{name}
BuildArch:      noarch

%description    doc
Documentation 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
%ifarch aarch64
sed -i 's|SYS_arch_prctl|SYS_prctl|g' src/libxsmm_cpuid_x86.c
%endif

sed -i 's|-Werror||g' Makefile.inc
%global makeflags STATIC=0 SYM=1 AVX=0 PYTHON=%{_bindir}/python3 PREFIX=%{buildroot}%{_prefix} POUTDIR=%{_lib} VERSION_API=1 OMPLIB=-lgomp
%make_build %makeflags


%install
make install %{makeflags}
mkdir -p %{buildroot}%{_fmoddir} %{buildroot}%{_libdir}/pkgconfig
mv %{buildroot}%{_includedir}/libxsmm.mod %{buildroot}%{_fmoddir}
mv %{buildroot}%{_prefix}/lib/*.pc %{buildroot}%{_libdir}/pkgconfig
sed -i -e 's|^prefix=.*$|prefix=%{_prefix}|' %{buildroot}%{_libdir}/pkgconfig/*.pc
rm -r %{buildroot}%{_datadir}/libxsmm
# instal generator
mkdir -p %{buildroot}/%{_bindir}
install -m755 bin/libxsmm_gemm_generator %{buildroot}/%{_bindir}/
# remove rpath and artifacts
rm -f %{buildroot}/usr/lib/libxsmm.env
chrpath --delete %{buildroot}/%{_bindir}/*
chrpath --delete %{buildroot}/%{_libdir}/*.so.*


# Build artefacts
find samples -name .make -exec rm -rf {} \;
cp Makefile.inc samples  # included by the sub-directories
echo "These are set up to be built in the original source tree.
You will have to adjust the make files to use an installed version." >samples/README
rm -rf %{buildroot}/usr/.*.sh
rm -rf %{buildroot}/usr/Makefile.inc


%ldconfig_scriptlets


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

%files devel
%doc README.md
%{_bindir}/libxsmm_gemm_generator
%{_includedir}/*
%{_fmoddir}/libxsmm.mod
%{_libdir}/libxsmm*.so
%{_libdir}/pkgconfig/*.pc

%files doc
%doc README.md
%doc samples
%doc CONTRIBUTING.md
%doc documentation/*.pdf
%doc documentation/*.md
%license LICENSE.md


%changelog
* Fri Dec 03 2021 Balint Cristian <cristian.balint@gmail.com>
- github build releases