File mlpack.spec of Package mlpack

#
# spec file for package mlpack
#
# Copyright (c) 2021 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#

%define libname libmlpack3

Name:           mlpack
Version:        3.4.2
Release:        0
Summary:        Scalable, fast C++ machine learning library
License:        BSD-3-Clause
URL:            https://www.mlpack.org
Source0:        https://www.mlpack.org/files/%{name}-%{version}.tar.gz
# By default the mlpack Doxyfile excludes all files in the directory pattern
# */build/*.  Well, on OBS that's everything.  So we need to not exclude that.
Patch0:         no_exclude_build.patch
BuildRequires:  make
BuildRequires:  gcc-c++
BuildRequires:  fdupes
BuildRequires:  cmake >= 2.8.5
BuildRequires:  armadillo-devel >= 8.400.0
BuildRequires:  boost-devel
BuildRequires:  cli11-devel
BuildRequires:  ensmallen-devel >= 2.10.0
BuildRequires:  libboost_math-devel
BuildRequires:  libboost_serialization-devel >= 1.49
BuildRequires:  libboost_test-devel
BuildRequires:  memory-constraints
BuildRequires:  pkg-config
BuildRequires:  stb-devel
# For generating man pages (CMake configuration takes care of this assuming
# txt2man is installed).  It is possible that we could just add all the man
# pages, generated offline, as a patch to this SRPM, but txt2man seems to exist
# in repos.
BuildRequires:  txt2man
# For generation of Doxygen HTML documentation.
BuildRequires:  doxygen
BuildRequires:  graphviz
# Required for building Python bindings.
BuildRequires:  python3
BuildRequires:  python3-Cython
BuildRequires:  python3-setuptools
BuildRequires:  python3-numpy-devel
BuildRequires:  python3-pandas
BuildRequires:  python3-pytest
BuildRequires:  python-rpm-macros
ExcludeArch:    %{ix86} %{arm}

%description
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use. Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users. mlpack outperforms competing machine learning libraries by large
margins.

# Executables.
%package bin
Summary:        Command-line executables for mlpack (machine learning library)
Requires:       %{name}%{_isa} = %{version}-%{release}

%description bin
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use. Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users. mlpack outperforms competing machine learning libraries by large
margins.  This package provides the command-line executables which run mlpack
methods and related documentation.

# Development headers.
%package devel
Summary:  Development headers for mlpack (C++ machine learning library)
Requires: %{name} = %{version}-%{release}
Requires: armadillo-devel >= 8.400.0
Requires: ensmallen-devel >= 2.10.0
Requires: boost-devel, boost-program-options, boost-math
Requires: libxml2-devel
Requires: lapack-devel
Requires: pkg-config

%description devel
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use. Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users. mlpack outperforms competing machine learning libraries by large
margins.  This package provides the headers to compile applications against
mlpack.

%package -n %{libname}
Summary:  Lib for mlpack

%description -n %{libname}
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use.  Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users.  mlpack outperforms competing machine learning libraries by large
margins.  This package provides libmlpack


%package doc
Summary:  Doxygen documentation for mlpack (C++ machine learning library)

%description doc
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use.  Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users.  mlpack outperforms competing machine learning libraries by large
margins.  This package provides the Doxygen-generated documentation for mlpack.

%package python3
Summary:  Python 3 bindings for mlpack (C++ machine learning library)
Requires: python3
Requires: python3-numpy
Requires: python3-pandas
Requires: python3-Cython

%description python3
mlpack is a C++ machine learning library with emphasis on scalability, speed,
and ease-of-use.  Its aim is to make machine learning possible for novice users
by means of a simple, consistent API, while simultaneously exploiting C++
language features to provide maximum performance and maximum flexibility for
expert users.  mlpack outperforms competing machine learning libraries by large
margins.  This package provides the Python bindings for mlpack.

%prep
%autosetup -p1

# Disable Doxygen warnings being fatal.
sed -i 's/WARN_AS_ERROR          = YES/WARN_AS_ERROR = NO/' Doxyfile;

%build
%limit_build -m 4000

%cmake \
  -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
  -DPROFILE=OFF \
  -DBUILD_TESTS=OFF \
  -DBUILD_PYTHON_BINDINGS=ON \
  -DPYTHON_EXECUTABLE=$(which python3) \
  -DBUILD_GO_BINDINGS=OFF \
  -DBUILD_JULIA_BINDINGS=OFF

# Try and reduce RAM usage.
%ifarch armv7hl
cd build;
cmake \
  -D CMAKE_C_FLAGS="`echo %{optflags} | sed 's/-pipe//g' | sed 's/$/ --param ggc-min-heapsize=32768 --param ggc-min-expand=1/'`" \
  -D CMAKE_CXX_FLAGS="`echo %{optflags} | sed 's/-pipe//g' | sed 's/$/ --param ggc-min-heapsize=32768 --param ggc-min-expand=1/'`" .
cd ..;
%endif

%ifarch i686
cd build;
cmake \
  -D CMAKE_C_FLAGS="`echo %{optflags} | sed 's/-pipe//g' | sed 's/$/ --param ggc-min-heapsize=32768 --param ggc-min-expand=1/'`" \
  -D CMAKE_CXX_FLAGS="`echo %{optflags} | sed 's/-pipe//g' | sed 's/$/ --param ggc-min-heapsize=32768 --param ggc-min-expand=1/'`" .
cd ..;
%endif

%cmake_build
# Build documentation ('doc' is not in the list of default targets).
make doc

%install
%cmake_install
# Install docs in the right folder
mkdir -p %{buildroot}%{_docdir}
mv %{buildroot}/usr/share/doc/mlpack %{buildroot}%{_docdir}/mlpack
#
# Fix shebang and perms
for file in __init__.py matrix_utils.py; do
  sed -i 's|#!%{_bindir}/env python|#!%{_bindir}/python3|' %{buildroot}%{python3_sitearch}/mlpack/$file
  chmod 0755 %{buildroot}%{python3_sitearch}/mlpack/$file
done
# fdupes
%fdupes %{buildroot}%{python3_sitearch}/mlpack/


%ldconfig_scriptlets -n %{libname}

%files -n %{libname}
%{_libdir}/libmlpack.so.3
%{_libdir}/libmlpack.so.3.*
%license LICENSE.txt

%files bin
%{_bindir}/mlpack_*
%{_mandir}/mlpack_*.1*

%files devel
%{_libdir}/libmlpack.so
%{_includedir}/mlpack/
%{_libdir}/pkgconfig/mlpack.pc
%dir %{_libdir}/cmake/mlpack
%{_libdir}/cmake/mlpack/mlpack-*.cmake

%files doc
%dir %{_docdir}/mlpack
%{_docdir}/mlpack/*

%files python3
%{python3_sitearch}/mlpack/
%{python3_sitearch}/mlpack-*.egg-info

%changelog
openSUSE Build Service is sponsored by