%define so_ver 18
# Disable validation tests by default due to opencl needing to be set up
%bcond_with computelibrary_tests
Name:           ComputeLibrary
Version:        20.02.1
Release:        2
Summary:        ARM Compute Library
License:        MIT
URL:            https://developer.arm.com/technologies/compute-library
Source:         https://github.com/ARM-software/ComputeLibrary/archive/v%{version}.tar.gz#/ComputeLibrary-%{version}.tar.gz
BuildRequires:  gcc-c++
BuildRequires:  git-core
BuildRequires:  scons >= 2.4
Recommends:     %{name}-sample-data
ExclusiveArch:  aarch64 x86_64

%description
A software library for computer vision and machine learning.
The Compute Library is a collection of low-level functions optimized for Arm CPU and GPU architectures targeted at image processing, computer vision, and machine learning.
Examples binaries part.

%package -n libarm_compute%{so_ver}
Summary:        ARM Compute Library

%description -n libarm_compute%{so_ver}
A software library for computer vision and machine learning.
The Compute Library is a collection of low-level functions optimized for Arm CPU and GPU architectures targeted at image processing, computer vision, and machine learning.
Library part.

%package devel
Summary:        ARM Compute Library -- devel
Requires:       %{name} = %{version}
Requires:       libarm_compute%{so_ver} = %{version}

%description devel
A software library for computer vision and machine learning.
The Compute Library is a collection of low-level functions optimized for Arm CPU and GPU architectures targeted at image processing, computer vision, and machine learning.
Devel part, including headers.

%package sample-data
%define sampledir sample-data
Summary:        Compute Library sample data

%description sample-data
Free *.npy and *.ppm files to use with example binaries.

%prep
%setup -q -n ComputeLibrary-%{version}

%build
scons os=linux build=native \
      set_soname=1 \
      examples=1 \
      gles_compute=0 \
      opencl=1 \
%if %{with computelibrary_tests}
      validation_tests=1 \
%else
      validation_tests=0 \
%endif
%ifarch aarch64
      neon=1 arch=arm64-v8a \
%endif
%ifarch x86_64
      neon=0 arch=x86_64 \
%endif
      extra_cxx_flags="%{optflags}" \
      Werror=0 %{?_smp_mflags}

%install
rm build/examples/*.o
rm build/examples/gemm_tuner/*.o
mv build/examples/gemm_tuner/* build/examples
rm -r build/examples/gemm_tuner
mkdir -p %{buildroot}%{_bindir}
install -Dm0755 build/examples/* %{buildroot}%{_bindir}/
mkdir -p %{buildroot}%{_libdir}
cp -a build/*.so* %{buildroot}%{_libdir}/
mkdir -p %{buildroot}%{_includedir}/
cp -a arm_compute/ include/half/ include/libnpy/ support/ utils/ %{buildroot}%{_includedir}/
# Remove *.cpp files from includedir
rm -f $(find %{buildroot}%{_includedir}/ -name *.cpp)
# Install sample data
mkdir -p %{buildroot}%{_datadir}/ComputeLibrary/%{sampledir}
cp -r data/* %{buildroot}%{_datadir}/ComputeLibrary/%{sampledir}
# Install scripts
install -Dm0755 scripts/* %{buildroot}%{_bindir}
# Fix Python scripts interpreter
for pyfile in `ls %{buildroot}%{_bindir}/*.py`; do
  sed -i -e 's|#!%{_bindir}/env python|#!%{_bindir}/python|' $pyfile
done

%post -n libarm_compute%{so_ver} -p /sbin/ldconfig
%postun -n libarm_compute%{so_ver} -p /sbin/ldconfig

%if %{with computelibrary_tests}
%check
LD_LIBRARY_PATH="build/" build/tests/arm_compute_validation
%endif

%files
%{_bindir}/*

%files -n libarm_compute%{so_ver}
%license LICENSE
%{_libdir}/*.so.%{so_ver}*

%files devel
%dir %{_includedir}/arm_compute
%dir %{_includedir}/half
%dir %{_includedir}/libnpy
%dir %{_includedir}/support
%dir %{_includedir}/utils
%{_includedir}/arm_compute/*
%{_includedir}/half/*
%{_includedir}/libnpy/*
%{_includedir}/support/*
%{_includedir}/utils/*
%{_libdir}/*.so

%files sample-data
%dir %{_datadir}/ComputeLibrary/
%{_datadir}/ComputeLibrary/%{sampledir}

%changelog
* Mon Jun 22 2020 Senlin Xia <xisenlin1@huawei.com> - 20.02.1-2
- fix build errors

* Mon May 10 2010 sinever <sinever@126.com>
- Initial release 20.02.1
