%if 0%{?el6}%{?el7}
%bcond_without devtoolset
%endif

%global somajor 1
%global sominor 10
%global soupd 1

Name:		libxsmm
Version:	1.15
Release:	2
Summary:	Small dense or sparse matrix multiplications and convolutions for x86_64
License:	BSD
URL:		https://github.com/hfp/libxsmm
Source0:	https://github.com/hfp/libxsmm/archive/%version/%name-%version.tar.gz

Patch0001:	leverage-GNU-source-when-building-the-library.patch

BuildRequires:	python3 openblas-devel
%if %{with devtoolset}
BuildRequires:	devtoolset-6-gcc-gfortran devtoolset-6-gcc-c++
%else
BuildRequires:	gcc-gfortran gcc-c++
%endif
ExclusiveArch:	x86_64

%global __requires_exclude /bin/.*sh$
%{?filter_setup:
%filter_from_requires /\/bin\/.*sh$/d
%filter_setup
}

%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).  The library
generates code for the following instruction set extensions: Intel
SSE, Intel AVX, Intel AVX2, IMCI (KNCni) for Intel Xeon Phi
coprocessors ("KNC"), and Intel AVX‑512 as found in the Intel Xeon Phi
processor family ("KNL") and future Intel Xeon processors.  Small
convolutions are currently only optimized for Intel AVX‑512.
Historically the library was solely targeting the Intel Many
Integrated Core Architecture "MIC") using intrinsic functions.
Currently, optimized assembly code targets all aforementioned
instruction set extensions (static code generation), and Just‑In‑Time
(JIT) code generation targets Intel AVX and beyond.

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

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

%package_help

%prep
%autosetup -n %{name}-%{version} -p1
find samples -name \*.vcxproj | xargs rm
rm documentation/{README,LICENSE,CONTRIBUTING}.md
rm documentation/gxm.md
cp -p samples/deeplearning/gxm/README.md documentation/gxm.md

%build
%if %{with devtoolset}
. /opt/rh/devtoolset-6/enable
%endif
%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
%if %{with devtoolset}
. /opt/rh/devtoolset-6/enable
%endif
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
find samples -name .make | xargs rm
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 %buildroot%_prefix/lib/libxsmm

%check
OMP_NUM_THREADS=1 make test-cp2k %makeflags
rm -r samples/cp2k/{build,.make,.state,cp2k-dbcsr,cp2k-collocate,cp2k-test.txt}
%ldconfig_scriptlets

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

%files devel
%_libdir/libxsmm*.so
%_includedir/*
%_bindir/libxsmm_gemm_generator
%if 0%{?el6}%{?el7}
%dir %_fmoddir
%endif
%_fmoddir/libxsmm.mod
%_libdir/pkgconfig/*.pc

%files help
%defattr(-,root,root)
%doc README.md documentation/*.md documentation/*.pdf samples CONTRIBUTING.md
%license LICENSE.md

%changelog
* Tue Aug 10 2021 lingsheng <lingsheng@huawei.com> - 1.15-2
- leverage GNU-source when building the library

* Thu May 28 2020 openEuler Buildteam <buildteam@openeuler.org> - 1.15-1
- Package init

