Name:           tbb
Version:        2021.11.0
Release:        1
Summary:        Threading Building Blocks lets you easily write parallel C++ programs
License:        ASL 2.0
URL:            http://threadingbuildingblocks.org/

Source0:        https://github.com/oneapi-src/oneTBB/archive/v%{version}/%{name}-%{version}.tar.gz
Source7:        tbbmalloc.pc
Source8:        tbbmalloc_proxy.pc
Patch0:         tbb-2021-Werror.patch
Patch1:         tbb-2021-strict-aliasing.patch

Patch9000:      bugfix-tbb-fix-__TBB_machine_fetchadd4-was-not-declared-on-.patch

BuildRequires:  gcc-c++ swig python3-devel hwloc hwloc-devel cmake python3-pip
BuildRequires:  python3-setuptools python3-sphinx python3-sphinx_rtd_theme python3-wheel

%description
Threading Building Blocks (TBB) lets you easily write parallel C++ programs that 
take full advantage of multicore performance, that are portable, composable and 
have future-proof scalability.

%package devel
Summary:        C++ headers and shared development libraries of TBB
Requires:       tbb = %{version}-%{release}
Requires:       tbb-bind = %{version}-%{release}

%description devel
The Threading Building Blocks (TBB) C++ libraries including Header files and 
shared object symlinks.

%package bind
Summary: NUMA support library for TBB
Requires:     %{name} = %{version}-%{release}

%description bind
NUMA support library for TBB, allowing the binding of tasks to selected
CPU cores.

%package help
Summary:        Documents for tbb
Requires:       man info
Provides:       bundled(jquery) tbb-doc = %{version}-%{release}
Obsoletes:      tbb-doc < %{version}-%{release}

%description help
Man pages and other related documents for tbb.

%package -n python3-tbb
Summary: TBB module of Python 3
%{?python_provide:%python_provide python3-tbb}

%description -n python3-tbb
TBB module of Python 3

%prep
%autosetup -n oneTBB-%{version} -p1

for fil in $(grep -Frl %{_bindir}/env python); do
    sed -i.orig 's,env python3,python3,' $fil
    touch -r $fil.orig $fil
    rm $fil.orig
done

sed -e "s|\('https://docs\.python\.org/': \)None|\1'%{_docdir}/python3-docs/html/objects.inv'|" \
    -i doc/GSG/conf.py doc/main/conf.py

%build
export TBBROOT=$PWD
export PYTHONPATH=$(sed "s,%{_prefix},$PWD/%{_vpath_builddir}/python/build," <<< %{python3_sitearch})
%cmake \
    -DCMAKE_CXX_STANDARD=17 \
    -DTBB4PY_BUILD:BOOL=ON \
    -DTBB_STRICT:BOOL=OFF \
    -DCMAKE_HWLOC_2_4_LIBRARY_PATH=%{_libdir}/libhwloc.so \
    -DCMAKE_HWLOC_2_4_INCLUDE_PATH=%{_includedir}/hwloc \

%make_build

unset PYTHONPATH
export LD_LIBRARY_PATH=$(ls -1d $PWD/*relwithdebinfo)
%ifarch riscv64
pxport LDFLAGS="-L $LD_LIBRARY_PATH %{build_ldflags} -latomic"
%else
export LDFLAGS="-L $LD_LIBRARY_PATH %{build_ldflags}"
%endif
cd python
%pyproject_build
cd -

export BUILD_TYPE=oneapi
sphinx-build doc/GSG getting-started
sphinx-build doc/main html

%install
%make_install

rm -fr %{buildroot}%{python3_sitearch}
cd python
%pyproject_install
cd -

mkdir -p %{buildroot}/%{_libdir}/pkgconfig
for file in %{SOURCE7} %{SOURCE8}; do
    target=%{buildroot}/%{_libdir}/pkgconfig/$(basename ${file})
    sed 's/_openEuler_VERSION/%{version}/' $file > $target
    touch -r $file $target
done

if [ -f %{buildroot}/%{_libdir}/pkgconfig/%{name}32.pc ]; then
    mv %{buildroot}/%{_libdir}/pkgconfig/%{name}32.pc %{buildroot}/%{_libdir}/pkgconfig/%{name}.pc
fi

rm -fr %{buildroot}%{_datadir}/doc

%check
ctest --output-on-failure --force-new-ctest-process

%files
%defattr(-,root,root)
%license LICENSE.txt
%{_libdir}/libirml.so.1
%{_libdir}/libtbb.so.12*
%{_libdir}/libtbbmalloc.so.2*
%{_libdir}/libtbbmalloc_proxy.so.2*

%files bind
%{_libdir}/libtbbbind_2_5.so.3*

%files devel
%defattr(-,root,root)
%{_libdir}/pkgconfig/*.pc
%{_includedir}/tbb/
%{_includedir}/oneapi/
%{_libdir}/cmake/
%{_libdir}/*.so

%files help
%defattr(-,root,root)
%doc getting-started html  README.md cmake/README.md

%files -n python3-tbb
%doc python/README.md
%{python3_sitearch}/TBB*
%{python3_sitearch}/tbb/
%{python3_sitearch}/__pycache__/TBB*

%changelog
* Wed Mar 13 2024 liyanan <liyanan61@h-partners.com> - 2021.11.0-1
- Update to 2021.11.0

* Fri Jul 15 2022 chenchen <chen_aka_jan@163.com> - 2020.3-5
- disable buggy test_task_schedulerl_observer.

* Fri Jul 2 2021 Hugel <genqihu1@huawei.com> - 2020.3-4
- Add multiple threads to make test

* Wed  Apr 14 2021 yangyanchao <yangyanchao6@huawei.com> - 2020.3-3
- Link to libatomic in riscv

* Sat Mar 20 2021 shenyangyang <shenyangyang4@huawei.com> - 2020.3-2
- Add -fstack-protector-strong for so file

* Fri Jul 24 2020 shixuantong <shixuantong@huawei.com> - 2020.3-1
- update to 2020.3-1

* Fri Feb 14 2020 lingsheng <lingsheng@huawei.com> - 2018.5-4
- Package init
