%global debug_package %{nil}
%global middle_release 0

%bcond_without check
%bcond_without test_api
%bcond_without test_header
%bcond_without benchmark
# Documentation needs external online `cppreference-doc/releases/download/v20220201/html-book-20220201.tar.xz`
%bcond_with doc

# SeqAn3 aims to support any 64-bit architecture running Linux/POSIX;
# currently big-endian CPU architectures like s390x are less supported.
ExclusiveArch: %{power64} x86_64 aarch64

%if 0%{?middle_release}
%global  commit      8c604d98e0d291bc3909ecbad78ca778b3ad5a5c
%global  date        .20230403git
%global  shortcommit %(c=%{commit}; echo ${c:0:8})
%else
%global  commit      %{nil}
%global  date        %{nil}
%global  shortcommit %{nil}
%endif

Name:      seqan3
Summary:   The modern C++ library for sequence analysis
Version:   3.4.0
Release:   0.1.rc1%{date}%{shortcommit}%{?dist}
License:   BSD-3-Clause
URL:       https://www.seqan.de/
# Source code archive generated by:
# git clone -b 3.3.0 --depth 1 --single-branch --progress --recursive https://github.com/seqan/seqan3.git
# find seqan3 -name '.git*' -exec  rm -rf {} ';'
# find seqan3 -name '.git*' -exec  rm -f {} ';'
# tar -czvf seqan3-%%{version}.tar.gz seqan3
%if 0%{?middle_release}
Source0:   https://github.com/seqan/%{name}/archive/%{commit}/%{name}-%{commit}.tar.gz
%else
Source0:   https://github.com/seqan/%{name}/archive/%{version}-rc.1/%{name}-%{version}-rc.1.tar.gz
%endif

BuildRequires: gcc, gcc-c++, dos2unix
BuildRequires: ccache
BuildRequires: cmake >= 3.4
BuildRequires: cereal-devel >= 1.3.2
BuildRequires: sdsl-lite-devel >= 3.0.1
BuildRequires: make
BuildRequires: zlib-devel >= 1.2
BuildRequires: bzip2-devel >= 1.0
BuildRequires: range-v3-devel >= 0.11.0
%if %{with check}
BuildRequires: google-benchmark-devel
BuildRequires: gtest-devel >= 1.10.0
%endif
%if %{with doc}
BuildRequires: texlive-newunicodechar
BuildRequires: doxygen >= 1.9.4
%endif

# Patches for unbundling libraries and fix some errors
Patch0: %{name}-unbundle_benchmark.patch
Patch1: %{name}-unbundle_sdsl.patch

# Skip tests that rely on byte-identical zlib output
# The output of zlib-ng differs from that of traditional zlib
Patch2: %{name}-zlib-ng.patch

%description
SeqAn3 is the new version of the popular SeqAn template
library for the analysis of biological sequences.
It enables the rapid development of high-performance
solutions by providing generic algorithms and
data structures for:

 - sequence representation and transformation
 - full-text indexing and efficient search
 - sequence alignment
 - input/output of common file formats

%package devel
Summary: SeqAn3 header only files
# bzip2stream and zipstream libraries are distributed under zlib/libpng
License:  BSD-3-Clause AND Zlib
Requires: cmake%{?_isa} >= 3.4
Requires: cereal-devel%{?_isa} >= 1.3.2
Requires: sdsl-lite-devel%{?_isa} >= 3.0.1
Requires: zlib-devel%{?_isa} >= 1.2
Requires: bzip2-devel%{?_isa} >= 1.0
Requires: range-v3-devel%{?_isa} >= 0.11.0

Provides: bundled(bzip2stream)
Provides: bundled(zipstream)

%description devel
C++ headers files of SeqAn3, including CMake configuration files.

%package doc
Summary: SeqAn3 documentation
BuildArch: noarch
%description doc
SeqAn3 documentation.

%prep
%autosetup -n %{name}-%{version}-rc.1 -N

dos2unix test/cmake/seqan3_require_benchmark.cmake
%patch 0 -p1 -b .backup
%patch 1 -p1 -b .backup
%patch 2 -p1 -b .backup

# Unbundle libraries already available in Fedora
rm -rf submodules/cereal
rm -rf submodules/range-v3
rm -rf submodules/sdsl-lite

# Fix file permissions
find . -type f -name "*.hpp" -exec chmod 0644 '{}' \;

%build
%if %{with check}
%if %{with test_api}
mkdir -p build
export CXXFLAGS="%{build_cxxflags} -std=c++20"
%cmake -S test/unit -B build -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 -DSEQAN3_CEREAL:BOOL=ON \
 -DSEQAN3_TEST_BUILD_OFFLINE:BOOL=ON

%define _vpath_builddir build
%cmake_build
%endif
%if %{with test_header}
mkdir -p build-header
export CXXFLAGS="%{build_cxxflags} -std=c++20"
%cmake -S test/header -B build-header -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 -DSEQAN3_CEREAL:BOOL=ON \
 -DSEQAN3_TEST_BUILD_OFFLINE:BOOL=ON

%define _vpath_builddir build-header
%cmake_build
%endif
%if %{with benchmark}
mkdir -p build-performance
export CXXFLAGS="%{build_cxxflags} -std=c++20"
%cmake -S test/performance -B build-performance -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
 -DSEQAN3_CEREAL:BOOL=ON \
 -DSEQAN3_TEST_BUILD_OFFLINE:BOOL=ON

%define _vpath_builddir build-performance
%cmake_build
%endif
%endif
%if %{with doc}
mkdir -p build-doc
%cmake -S test/documentation -B build-doc -DCMAKE_BUILD_TYPE=Release
%define _vpath_builddir build-doc
%cmake_build -- -j1
%endif

%install
mkdir -p %{buildroot}%{_libdir}/cmake/%{name}
cp -a include %{buildroot}%{_prefix}/
rm %{buildroot}%{_includedir}/%{name}/contrib/std/.{clang-format,gitignore}

install -pm 644 build_system/*.cmake %{buildroot}%{_libdir}/cmake/%{name}/

%if %{with doc}
mkdir -p build-doc
%cmake -S test/documentation -B build-doc -DCMAKE_BUILD_TYPE=Release
%define _vpath_builddir build-doc
%cmake_install
%endif

%if %{with check}
%check
# Tests the API of the library
%if %{with test_api}
%define _vpath_builddir build
%ctest
%endif
# Tests that every header includes all required headers and detects linkage issues
%if %{with test_header}
%define _vpath_builddir build-header
%ctest
%endif
# Microbenchmarks
%if %{with benchmark}
%define _vpath_builddir build-performance
%ctest
%endif
%endif

%files devel
%license LICENSE.md
%doc README.md
%{_includedir}/%{name}/
%{_libdir}/cmake/%{name}/

%if %{with doc}
%files doc
#%%doc build-doc/doc_usr/html
%doc doc/*
%license LICENSE.md
%doc README.md
%endif

%changelog
* Tue Jan 30 2024 Jerry James <loganjerry@gmail.com> - 3.4.0-0.1.rc1
- Pre-release 3.4.0 RC1
- Remove unused dependency on coin-or-lemon
- Convert License field to SPDX
- Note that the devel package bundles zipstream and bzip2stream
- Note that the devel package needs zlib-devel and bzip2-devel

* Sat Jan 27 2024 Fedora Release Engineering <releng@fedoraproject.org> - 3.3.0-0.7.rc2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Thu Aug 10 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.6.rc2
- Pre-release 3.3.0 RC2

* Tue Jul 18 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.5.rc1
- Pre-release 3.3.0 RC1

* Thu Apr 06 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.4.20230403git8c604d98
- Pre-release 3.3.0 commit #8c604d98

* Thu Mar 30 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.3.20230330git174255ee
- Pre-release 3.3.0 commit #174255ee
- Disable tests
- Disable benchmarks

* Sat Mar 25 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.2.20230119gitc5ec15bd
- Pre-release 3.3.0 commit #c5ec15bd

* Tue Jan 24 2023 Antonio Trande <sagitter@fedoraproject.org> - 3.3.0-0.1.20230119git404affbf
- Pre-release 3.3.0 commit #404affbf

* Sat Jan 21 2023 Fedora Release Engineering <releng@fedoraproject.org> - 3.2.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Sat Jul 23 2022 Fedora Release Engineering <releng@fedoraproject.org> - 3.2.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Sun Jun 26 2022 Antonio Trande <sagitter@fedoraproject.org> - 3.2.0-1
- Release 3.2.0

* Wed Jun 15 2022 Antonio Trande <sagitter@fedoraproject.org> - 3.2.0-0.1.rc1.20220615git1148ce10
- Pre-release 3.2.0
- Enable tests

* Sat Feb 05 2022 Fedora Release Engineering <releng@fedoraproject.org> - 3.1.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
- Patched for GCC-12

* Mon Jan 17 2022 Kevin Fenzi <kevin@scrye.com> - 3.1.0-2
- Rebuild for hiredis 1.0.2

* Fri Nov 26 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.1.0-1
- Release 3.1.0

* Sun Sep 05 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.1.0-0.2.20210809git4604f1b2
- Rebuild for gtest-1.11.0

* Mon Aug 09 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.1.0-0.1.20210809git4604f1b2
- Pre-release 3.1.0

* Fri Jul 23 2021 Fedora Release Engineering <releng@fedoraproject.org> - 3.0.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild

* Fri May 28 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.0.3-1
- Release 3.0.3

* Wed May 26 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.0.3-0.1.rc1
- Pre-release 3.0.3-rc1

* Sun Feb 14 2021 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-7
- Disable tests with GCC-11 (rhbz#1923593)
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild

* Fri Dec 11 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-6
- Rebuild for GCC-11

* Tue Nov 03 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-5
- Bundle sdsl header files

* Sat Oct 17 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-4
- Remove old License file from bundled libraries
- Redefine vpath builddir

* Fri Oct 16 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-3
- Fix Requires packages

* Wed Oct 14 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-2
- Use -std=c++2a flag
- Patched for upstream bugs #2209 #2210

* Tue Oct 13 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-1
- Release 3.0.2

* Fri Aug 07 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-0.2.20200806gitbf04354
- Pre-release 3.0.2 with bundled range-v3

* Thu Aug 06 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.2-0.1.20200806gitbf04354
- Pre-release 3.0.2

* Thu Mar 05 2020 Antonio Trande <sagitter@fedoraproject.org> - 3.0.1-1
- Execute header/performance tests
- Build docs
- First package