Package eml: Specfile

%global _unpackaged_files_terminate_build 1
#set_verify_elf_method none

%define ver 10.0
%define mver vd7u66
# generate mcst version from %%ver, e.g. 9.2 -> 0902
# avoid generator within %%ver, since gear-create-tag can't digest it
%define bver %(echo "%ver" | awk -F'.' '{ printf("%%02d%%02d",$1,$2) }')

Name:     eml
Version:  %{ver}_%{mver}
Release:  alt4

Summary:  Original EML binary libs
License:  non-free
Group:    System/Libraries

Url:      http://www.mcst.ru

Source0:  eml_%{bver}-%{mver}_e2k-4c.deb
Source1:  eml_%{bver}-%{mver}_e2k-8c.deb
Source2:  eml_%{bver}-%{mver}_e2k-8c2.deb
Source3:  eml_%{bver}-%{mver}_e2k-16c.deb

ExclusiveArch: %e2k
BuildRequires: dpkg libgomp-devel

%set_verify_elf_method skip

%package doc
Group:    Development/Documentation
Summary:  MCST EML documentation
# Docs may be different because EML API on different architectures
# is different, e.g. some functions are not available on all arches
#Buildarch: noarch

%package devel
Group:    Development/C
Summary:  Headers for building apps with EML library
Requires: %name = %EVR
Buildarch: noarch

%package devel-static
Group:    Development/C
Summary:  Static library for linking apps with EML
Requires: %name-devel = %EVR

%package devel-compat-blas
Group:    Development/C
Summary:  Compat files to use EML as BLAS or CBLAS implementations
Requires: %name-devel = %EVR

%package devel-compat-blas-static
Group:    Development/C
Summary:  Compat static files to use EML as BLAS or CBLAS implementations
Requires: %name-devel-compat-blas = %EVR

%package devel-compat-lapack
Group:    Development/C
Summary:  Compat files to use EML as LAPACK implementation
Requires: %name-devel = %EVR

%package devel-compat-lapack-static
Group:    Development/C
Summary:  Compat static files to use EML as LAPACK implementation
Requires: %name-devel-compat-lapack = %EVR

%package devel-compat-fftw3
Group:    Development/C
Summary:  Compat files to use EML as FFTW3 implementation
Requires: %name-devel = %EVR

%package devel-compat-fftw3-static
Group:    Development/C
Summary:  Compat static files to use EML as FFTW3 implementation
Requires: %name-devel-compat-fftw3 = %EVR

%define descr_common\
The EML (Elbrus Math Libraries) from MCST.\
They provide (C)BLAS, LAPACK and FFTW interfaces as well as additional\
routines heavily optimizied for the E2K architecture.\
See documentation or headers for details.

%description
%descr_common

%description doc
%descr_common

This package contains documentation for MCST EML libraries.

%description devel
%descr_common

This package contains headers for building apps with MCST EML
libraries.

%description devel-static
%descr_common

This package contains static libraries for building apps with MCST EML
libraries.

%define descr_compat()\
This package contains %{1} compatibility files for using MCST EML\
library as %{2} implementation.

%description devel-compat-blas
%descr_common
%descr_compat %nil "BLAS or CBLAS"

%description devel-compat-blas-static
%descr_common
%descr_compat static "BLAS or CBLAS"

%description devel-compat-lapack
%descr_common
%descr_compat %nil LAPACK

%description devel-compat-lapack-static
%descr_common
%descr_compat static LAPACK

%define descr_fftw3\
Note that it has provides a partial support:\
- only double precision is supported;\
- only 1 and 2 deminsions are supported;\
- there are further limitations, see docs for details.

%description devel-compat-fftw3
%descr_common
%descr_compat %nil FFTW3
%descr_fftw3

%description devel-compat-fftw3-static
%descr_common
%descr_compat static FFTW3
%descr_fftw3

%prep
%ifarch e2kv6
dpkg-deb -x %SOURCE3 .
%else
%ifarch e2kv5
dpkg-deb -x %SOURCE2 .
%else
%ifarch e2kv4
dpkg-deb -x %SOURCE1 .
%else # always fallback to e2kv3
dpkg-deb -x %SOURCE0 .
%endif
%endif
%endif

%install
# EML can be used as (C)BLAS, LAPACK and FFTW3 implementation,
# though FFTW3 one come with some limitations (see descr_fftw3 above)
pushd usr/lib
rm libblas.a liblapack.a
ln -s -r libeml_algebra.so libblas.so
ln -s -r libeml_algebra.a libblas.a
ln -s -r libeml_algebra.so libcblas.so
ln -s -r libeml_algebra.a libcblas.a
ln -s -r libeml_algebra.so liblapack.so
ln -s -r libeml_algebra.a liblapack.a
ln -s -r libeml_algebra.so libclapack.so
ln -s -r libeml_algebra.a libclapack.a
ln -s -r libeml_image.so libfftw3.so
ln -s -r libeml_image.a libfftw3.a
popd

pushd usr/include
ln -s -r eml/cblas.h cblas.h
ln -s -r eml/clapack.h clapack.h
ln -s -r eml/fftw3.h fftw3.h
popd

# 10.0-vd7u66 got executable headers *on v4* (#8173)
find usr/include -type f -print0 | xargs -r0 chmod 644 --

mkdir -p %buildroot%_libdir
mv usr/lib/*.{so,a} %buildroot%_libdir
mv usr/include %buildroot%_includedir

%files
%_libdir/libeml*.so

%files doc
%ifarch e2k e2kv6
%doc opt/mcst/doc/eml/*
%endif

%files devel
%_includedir/*eml*

%files devel-static
%_libdir/libeml*.a

%files devel-compat-blas
%_includedir/cblas.h
%_libdir/lib*blas.so

%files devel-compat-blas-static
%_libdir/lib*blas.a

%files devel-compat-lapack
%_includedir/clapack.h
%_libdir/lib*lapack.so

%files devel-compat-lapack-static
%_libdir/lib*lapack.a

%files devel-compat-fftw3
%_includedir/fftw3.h
%_libdir/libfftw3.so

%files devel-compat-fftw3-static
%_libdir/libfftw3.a

# TODO:
# - drop %%ifarch for doc subpackage when docs get fixed upstream

%changelog
* Thu Jul 06 2023 Michael Shigorin <mike@altlinux.org> 10.0_vd7u66-alt4
- fix header permissions too (e8c deb had those executable)

* Wed Jul 05 2023 Michael Shigorin <mike@altlinux.org> 10.0_vd7u66-alt3
- docs are missing in e8c/e8c2 debs for this build (mcst#8173)

* Mon Jul 03 2023 Michael Shigorin <mike@altlinux.org> 10.0_vd7u66-alt2
- fix broken SourceN:
- skip ELF check (those are blobs anyways)

* Tue May 16 2023 Michael Shigorin <mike@altlinux.org> 10.0_vd7u66-alt1
- update to 10.0_vd7u66 with proper e16c one

* Tue Dec 07 2021 Andrew Savchenko <bircoph@altlinux.org> 9.3_vd6u61-alt1
- Update to 9.3_vd6u61

* Fri Sep 17 2021 Andrew Savchenko <bircoph@altlinux.org> 9.3_vd6u59-alt2
- Use smaller fine grained eml sublibs for BLAS, LAPACK and FFTW
  interfaces.

* Mon Aug 23 2021 Andrew Savchenko <bircoph@altlinux.org> 9.3_vd6u59-alt1
- Update to 9.3_vd6u59
  Fixes: MCST bug 6277 (missing geqrfp symbol)

* Wed Apr 21 2021 Andrew Savchenko <bircoph@altlinux.org> 9.2_vd6u59-alt1
- Update to 9.2_vd6u59

* Wed Feb 03 2021 Andrew Savchenko <bircoph@altlinux.org> 9.1_vd6u56-alt1
- Update to 9.1_vd6u56

* Wed Dec 30 2020 Andrew Savchenko <bircoph@altlinux.org> 0.0_vd5u55-alt1
- Update to 0.0_vd5u55
- Add e8c2 support

* Wed May 13 2020 Andrew Savchenko <bircoph@altlinux.org> 0.0_54-alt2
- Remove autoreq hack that is no longer needed after rpm is fixed
  to remove surplus lcc deps.

* Thu May 07 2020 Andrew Savchenko <bircoph@altlinux.org> 0.0_54-alt1
- Update to MCST ver. 0.0_u54
- Remove 32-bit libraries
- Enable provides and requires
- Provide BLAS, LAPACK and FFTW3 compatibility symlinks

* Fri Jul 26 2019 Michael Shigorin <mike@altlinux.org> 0.0-alt1.E2K.2
- added doc subpackage

* Fri Jul 26 2019 Michael Shigorin <mike@altlinux.org> 0.0-alt1.E2K.1
- binaries taken from:
  + eml_0.0-u34_e2k-4c.deb (e2k)
  + eml_0.0-u35_e2k-8c.deb (e2kv4)
- spec based on lcc-libs-blobs 1.23.12-alt1.E2K.3