%bcond_with test

Name:           tbb
Summary:        The Threading Building Blocks library abstracts low-level threading details
Summary(ja):    スレッド処理を抽象化するスレッディング・ビルディング・ブロックライブラリ
Version:        2020.3
Release:        1%{?_dist_release}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        ASL 2.0
URL:            https://github.com/oneapi-src/oneTBB
Source0:        https://github.com/intel/tbb/archive/v%{version}/%{name}-%{version}.tar.gz
# These three are downstream sources.
Source6:        tbb.pc
Source7:        tbbmalloc.pc
Source8:        tbbmalloc_proxy.pc

# Don't snip -Wall from C++ flags.  Add -fno-strict-aliasing, as that
# uncovers some static-aliasing warnings.
# Related: https://bugzilla.redhat.com/show_bug.cgi?id=1037347
Patch0: tbb-2019-dont-snip-Wall.patch

# Make attributes of aliases match those on the aliased function.
Patch1: tbb-2020-attributes.patch

# Fix test-thread-monitor, which had multiple bugs that could (and did, on
# ppc64le) result in a hang.
Patch2: tbb-2019-test-thread-monitor.patch

# Fix a test that builds a 4-thread barrier, but cannot guarantee that more
# than 2 threads will be available to use it.
Patch3: tbb-2019-test-task-scheduler-init.patch

# Fix compilation on aarch64 and s390x.  See
# https://github.com/intel/tbb/issues/186
Patch4: tbb-2019-fetchadd4.patch

BuildRoot:     %{_tmppath}/%{name}-%{version}-root
BuildRequires: doxygen
BuildRequires: libstdc++-devel
BuildRequires: python3-rpm-macros
BuildRequires: python3-devel
BuildRequires: python3-setuptools
BuildRequires: swig

%description
Threading Building Blocks (TBB) is a C++ runtime library that
abstracts the low-level threading details necessary for optimal
multi-core performance.  It uses common C++ templates and coding style
to eliminate tedious threading implementation work.

TBB requires fewer lines of code to achieve parallelism than other
threading models.  The applications you write are portable across
platforms.  Since the library is also inherently scalable, no code
maintenance is required as more processor cores become available.


%package devel
Summary: The Threading Building Blocks C++ headers and shared development libraries
Summary(ja): TBBの C++ ヘッダファイルと開発用共有ライブラリ
Group: programming
Requires: %{name} = %{version}-%{release}

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


%package doc
Summary: The Threading Building Blocks documentation
Summary(ja): TBBのドキュメント
Group: documentation
BuildArch: noarch

%description doc
PDF documentation for the user of the Threading Building Block (TBB)
C++ library.


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

%description -n python3-%{name}
Python 3 TBB module.


%debug_package


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

# For repeatable builds, don't query the hostname or architecture
sed -i 's/"`hostname -s`" ("`uname -m`"/fedorabuild (%{_arch}/' \
    build/version_info_linux.sh

# Do not assume the RTM instructions are available.
# Insert --as-needed before the libraries to be linked.
sed -e 's/-mrtm//' \
    -e "s/-fPIC/& -Wl,--as-needed/" \
    -i build/linux.gcc.inc

# Invoke the right python binary directly
sed -i 's,env python,python3,' python/TBB.py python/tbb/__*.py

# Remove shebang from files that don't need it
sed -i '/^#!/d' python/tbb/{pool,test}.py


%build
make %{?_smp_mflags} tbb_build_prefix=obj stdver=c++14 \
    compiler=gcc \
    CXXFLAGS="%{optflags} -DDO_ITT_NOTIFY -DUSE_PTHREAD" \
    LDFLAGS="$RPM_LD_FLAGS -lpthread"
for file in %{SOURCE6} %{SOURCE7} %{SOURCE8}; do
    base=$(basename ${file})
    sed 's/_FEDORA_VERSION/%{version}/' ${file} > ${base}
    touch -r ${file} ${base}
done

# Build for python 3
. build/obj_release/tbbvars.sh
pushd python
make %{?_smp_mflags} -C rml stdver=c++14 \
    compiler=gcc \
    CPLUS_FLAGS="%{optflags} -DDO_ITT_NOTIFY -DUSE_PTHREAD" \
    LDFLAGS="$RPM_LD_FLAGS -lpthread"
cp -p rml/libirml.so* .
%py3_build
popd

%ifnarch %{ix86}
# Build the documentation
make doxygen
%endif

%if %{with test}
%check
# This test assumes it can create thread barriers for arbitrary numbers of
# threads, but tbb limits the number of threads spawned to a function of the
# number of CPUs available.  Some of the koji builders have a small number of
# CPUs, so the test hangs waiting for threads that have not been created to
# arrive at the barrier.  Skip this test until upstream fixes it.
sed -i '/test_task_scheduler_observer/d' build/Makefile.test

make test tbb_build_prefix=obj stdver=c++14 CXXFLAGS="%{optflags}"
%endif


%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%{_libdir}
mkdir -p $RPM_BUILD_ROOT%{_includedir}

pushd build/obj_release
    for file in libtbb{,malloc{,_proxy}}; do
        install -p -D -m 755 ${file}.so.2 $RPM_BUILD_ROOT/%{_libdir}
        ln -s $file.so.2 $RPM_BUILD_ROOT/%{_libdir}/$file.so
    done
popd

pushd include
    find tbb -type f ! -name \*.htm\* -exec \
        install -p -D -m 644 {} $RPM_BUILD_ROOT/%{_includedir}/{} \
    \;
popd

for file in %{SOURCE6} %{SOURCE7} %{SOURCE8}; do
    install -p -D -m 644 $(basename ${file}) \
        $RPM_BUILD_ROOT/%{_libdir}/pkgconfig/$(basename ${file})
done

# Install the rml headers
mkdir -p $RPM_BUILD_ROOT%{_includedir}/rml
cp -p src/rml/include/*.h $RPM_BUILD_ROOT%{_includedir}/rml

# Python 3 install
. build/obj_release/tbbvars.sh
pushd python
%py3_install
chmod a+x $RPM_BUILD_ROOT%{python3_sitearch}/TBB.py
chmod a+x $RPM_BUILD_ROOT%{python3_sitearch}/tbb/__*.py
cp -p libirml.so.1 $RPM_BUILD_ROOT%{_libdir}
ln -s libirml.so.1 $RPM_BUILD_ROOT%{_libdir}/libirml.so
popd

# Install the cmake files
mkdir -p $RPM_BUILD_ROOT%{_libdir}/cmake
cp -a cmake $RPM_BUILD_ROOT%{_libdir}/cmake/%{name}
rm $RPM_BUILD_ROOT%{_libdir}/cmake/%{name}/README.rst


%clean
rm -rf $RPM_BUILD_ROOT


%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig


%files
%doc doc/Release_Notes.txt README.md
%license LICENSE
%{_libdir}/*.so.*

%files devel
%doc CHANGES
%doc CHANGES cmake/README.rst
%{_includedir}/rml/
%{_includedir}/tbb/
%{_libdir}/*.so
%{_libdir}/cmake/tbb/
%{_libdir}/pkgconfig/*.pc

%ifnarch %{ix86}
%files doc
%doc doc/Release_Notes.txt
%doc html
%endif

%files -n python3-%{name}
%doc python/index.html
%{python3_sitearch}/TBB*
%{python3_sitearch}/tbb/
%{python3_sitearch}/__pycache__/TBB*


%changelog
* Mon Aug 17 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2020.3-1
- new upstream release.

* Tue Jun 30 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 2020.2-1
- new upstream release.

* Sat Sep 03 2016 Toshiaki Ara <ara_t@384.jp> - 4.3u6-2
- rebuild with gcc-5.4.0

* Fri Jun 19 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 4.3u6-1
- new upstream release

* Wed Mar  4 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 4.3u3-2
- Initial build for Vine Linux based on 4.3 update3

* Mon Jan 19 2015 Petr Machata <pmachata@redhat.com> - 4.3-1.20141204
- Rebase to 4.3u2
- Drop ExclusiveArch

* Thu Sep 25 2014 Karsten Hopp <karsten@redhat.com> 4.1-9.20130314
- enable ppc64le and run 'make test' on that new arch

* Mon Aug 18 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.1-8.20130314
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild

* Sun Jun 08 2014 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.1-7.20130314
- Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild

* Sun Jan 12 2014 Peter Robinson <pbrobinson@fedoraproject.org> 4.1-6.20130314
- Build on aarch64, minor spec cleanups

* Tue Dec  3 2013 Petr Machata <pmachata@redhat.com> - 4.1-5.20130314
- Fix building with -Werror=format-security (tbb-4.1-dont-snip-Wall.patch)

* Thu Oct  3 2013 Petr Machata <pmachata@redhat.com> - 4.1-4.20130314
- Fix %%install to also install include files that are not named *.h

* Sun Aug 04 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.1-3.20130314
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild

* Tue May 28 2013 Petr Machata <pmachata@redhat.com> - 4.1-3.20130314
- Enable ARM arches

* Wed May 22 2013 Petr Machata <pmachata@redhat.com> - 4.1-2.20130314
- Fix mfence patch.  Since the __TBB_full_memory_fence macro was
  function-call-like, it stole () intended for function invocation.

* Wed May 22 2013 Petr Machata <pmachata@redhat.com> - 4.1-1.20130314
- Rebase to 4.1 update 3

* Fri Feb 15 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.0-7.20120408
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild

* Tue Aug 28 2012 Petr Machata <pmachata@redhat.com> - 4.0-6.20120408
- Fix build on PowerPC

* Sat Jul 21 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.0-5.20120408
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild

* Thu Jun  7 2012 Petr Machata <pmachata@redhat.com> - 4.0-4.20120408
- Rebase to 4.0 update 4
- Refresh Getting_Started.pdf, Reference.pdf, Tutorial.pdf
- Provide pkg-config files
- Resolves: #825402

* Thu Apr 05 2012 Karsten Hopp <karsten@redhat.com> 4.0-3.20110809
- tbb builds now on PPC(64)

* Sat Jan 14 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 4.0-2.20110809
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild

* Tue Oct 18 2011 Petr Machata <pmachata@redhat.com> - 4.0-1.20110809
- Rebase to 4.0
  - Port the mfence patch
  - Refresh the documentation bundle

* Tue Jul 26 2011 Petr Machata <pmachata@redhat.com> - 3.0-1.20110419
- Rebase to 3.0-r6
  - Port both patches
  - Package Design_Patterns.pdf
  - Thanks to Richard Shaw for initial rebase patch
- Resolves: #723043

* Wed Feb 09 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.2-3.20090809
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild

* Thu Jun 10 2010 Petr Machata <pmachata@redhat.com> - 2.2-2.20090809
- Replace mfence instruction with xchg to make it run on ia32-class
  machines without SSE2.
- Resolves: #600654

* Tue Nov  3 2009 Petr Machata <pmachata@redhat.com> - 2.2-1.20090809
- New upstream 2.2
- Resolves: #521571

* Sun Jul 26 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1-3.20080605
- Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild

* Wed Feb 25 2009 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1-2.20080605
- Rebuilt for https://fedoraproject.org/wiki/Fedora_11_Mass_Rebuild

* Fri Jun 13 2008 Petr Machata <pmachata@redhat.com> - 2.1-1.20080605
- New upstream 2.1
  - Drop soname patch, parallel make patch, and GCC 4.3 patch

* Wed Feb 13 2008 Petr Machata <pmachata@redhat.com> - 2.0-4.20070927
- Review fixes
  - Use updated URL
  - More timestamp preservation
- Initial import into Fedora CVS

* Mon Feb 11 2008 Petr Machata <pmachata@redhat.com> - 2.0-3.20070927
- Review fixes
  - Preserve timestamp of installed files
  - Fix soname not to contain "debug"

* Tue Feb  5 2008 Petr Machata <pmachata@redhat.com> - 2.0-2.20070927
- Review fixes
  - GCC 4.3 patchset
  - Add BR util-linux net-tools
  - Add full URL to Source0
  - Build in debug mode to work around problems with GCC 4.3

* Mon Dec 17 2007 Petr Machata <pmachata@redhat.com> - 2.0-1.20070927
- Initial package.
- Using SONAME patch from Debian.
