## START: Set by rpmautospec
## (rpmautospec version 0.7.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 18;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

# Only supports Matlab at the moment
# https://github.com/chlubba/catch22/issues/12
%bcond octave 0

# Package native R package separately:
# https://github.com/chlubba/catch22/wiki/Installation-and-Testing#r says that is to be preferred
# https://github.com/hendersontrent/Rcatch22

# Downstream .so version; see comment above Source2, and make sure to increment
# the following integer each time there is an ABI change upstream.
%global downstream_so_number 1
Name:           catch22
Version:        0.4.0
Release:        %autorelease
Summary:        CAnonical Time-series CHaracteristics

# The Matlab code is clearly documented as GPL-3.0-or-later. In “Please clarify
# GPL version,” https://github.com/DynamicsAndNeuralSystems/catch22/issues/32,
# upstream clarified that GPL-3.0-or-later is intended for but everything else,
# as well.
License:        GPL-3.0-or-later
URL:            https://github.com/chlubba/catch22
Source0:        %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
# Helper script for content-aware comparison of CSV file output from tests
Source1:        compare_output
# Hand-written for Fedora in groff_man(7) format based on --help text
Source2:        run_features.1
# Upstream does not provide any build system at all. This Makefile allows us to
# build a shared library and link the run_features executable to it. We must
# therefore use downstream .so versioning.
Source3:        Makefile

BuildRequires:  make
BuildRequires:  gcc
BuildRequires:  python3-devel

# Drop python3-catch22 (https://pypi.org/project/catch22/) beginning with F40
# since these bindings are obsolete; replaced by python-pycatch22.
Obsoletes:      python3-catch22 < 0.4.0-9

%global _description %{expand:
catch22 is a collection of 22 time-series features coded in C that can be run
from Python, R, Matlab, and Julia. The catch22 features are a high-performing
subset of the over 7000 features in hctsa.

Features were selected based on their classification performance across a
collection of 93 real-world time-series classification problems, as described
in our open-access paper:

- Lubba et al. (2019). catch22: CAnonical Time-series CHaracteristics
  (https://doi.org/10.1007/s10618-019-00647-x)

The computational pipeline used to generate the catch22 feature set is in the
op_importance (https://github.com/chlubba/op_importance) repository.

For catch22-related information and resources, including a list of publications
using catch22, see the catch22 wiki (https://github.com/chlubba/catch22/wiki).}

Requires:       %{name}-libs = %{version}-%{release}

%description %_description

This package contains the command-line tool run_features.


%package libs
Summary:        %{summary}

%description libs %{_description}

This package contains the implementation compiled as a shared library.


%package devel
Summary:        %{summary}

Requires:       %{name}-libs = %{version}-%{release}

%description devel %{_description}

This package contains headers and other files required for developing
applications that link against the implementation as a shared library.


%if %{with octave}
%global octpkg %{name}
%package -n octave-%{name}
Summary:        %{summary}

BuildRequires:  octave-devel

Requires:       octave(api) = %{octave_api}
Requires(post):   octave
Requires(postun): octave

%description -n octave-%{name} %_description
%endif


%prep
%autosetup -p1
cp -p '%{SOURCE3}' C/
find . -name ".gitignore" -print -delete

%if %{with octave}
# Set up for Octave install
echo "Does not yet support Octave."
%endif


%build
%set_build_flags
%make_build -C C DOWNSTREAM_SO_NUMBER='%{downstream_so_number}'

%if %{with octave}
echo "Does not yet support Octave."
%endif


%install
%make_install -C C \
    DOWNSTREAM_SO_NUMBER='%{downstream_so_number}' \
    PREFIX='%{_prefix}' \
    INCLUDEDIR='%{_includedir}' \
    LIBDIR='%{_libdir}' \
    BINDIR='%{_bindir}'
install -t '%{buildroot}%{_mandir}/man1' -D -p -m 0644 '%{SOURCE2}'

%if %{with octave}
echo "Does not yet support Octave."
%endif


%check
find testData -type f -name '*_output.txt' \
    -execdir cp -v -p '{}' '{}.expected' ';'
env LD_LIBRARY_PATH='%{buildroot}%{_libdir}' \
    PATH="${PATH}:%{buildroot}%{_bindir}" \
    ./testData/runtests.sh

for x in testData/*.expected
do
  %{python3} '%{SOURCE1}' \
      --ignore-extra='DN_Mean' \
      --ignore-extra='DN_Spread_Std' \
      "${x}" "$(echo "${x}" | sed -r 's/\.expected$//')"
done


%if %{with octave}
%post
%octave_cmd pkg rebuild


%preun
%octave_pkg_preun


%postun
%octave_cmd pkg rebuild
%endif


%files
%{_bindir}/run_features
%{_mandir}/man1/run_features.1*


%files libs
%license LICENSE

%{_libdir}/lib%{name}.so.0.%{downstream_so_number}


%files devel
%doc README.md featureList.txt

%{_includedir}/%{name}/
%{_libdir}/lib%{name}.so


%if %{with octave}
%files -n octave-%{name}
%license LICENSE
%doc featureList.txt
%{octpkglibdir}
%dir %{octpkgdir}
%{octpkgdir}/*.m
%doc %{octpkgdir}/doc-cache
%{octpkgdir}/packinfo
%endif


%changelog
## START: Generated by rpmautospec
* Wed Jul 17 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-18
- Rebuilt for https://fedoraproject.org/wiki/Fedora_41_Mass_Rebuild

* Tue Jan 23 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-17
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jan 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-16
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Tue Jan 02 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-15
- F40+: Drop conditional for obsolete “catch22” Python bindings

* Thu Oct 19 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-14
- F38+: Use %%%%{py3_test_envvars} to set up test environments

* Mon Oct 09 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-13
- Update License to GPL-3.0-or-later based on upstream clarification

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-12
- Build the implementation as a shared library
- Add catch22-libs and catch22-devel subpackages.

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-10
- Fix leading blank lines in descriptions

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-9
- Drop obsolete python3-catch22 bindings in F40+

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-8
- Convert to SPDX
- Ask upstream for further license clarification

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-7
- Use new (rpm 4.17.1+) bcond style

* Thu Sep 28 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-6
- Add a trivial hand-written man page

* Wed Jul 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild

* Tue Jun 13 2023 Python Maint <python-maint@redhat.com> - 0.4.0-4
- Rebuilt for Python 3.12

* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Wed Jul 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.4.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Tue Jul 12 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.4.0-1
- Update to 0.4.0 (close RHBZ#2095508)
- Add a Python helper script “compare_output” to validate test output while
  allowing for small differences in floating-point values across
  architectures

* Wed Jun 15 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.3.1-1
- Update to 0.3.1 (close RHBZ#2095508)
- Drop “forge” macros since they are not doing much here
- Switch to pyproject-rpm-macros

* Mon Jun 13 2022 Python Maint <python-maint@redhat.com> - 0.2.1-3
- Rebuilt for Python 3.11

* Wed Jan 19 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.1-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Tue Aug 10 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.1-1
- Correct location of LDFLAGS
- Move linker flags to end

* Mon Aug 09 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.1-1
- Add sub-package specific licenses
- Add LDFLAGS
- Preserve time stamps
- Remove R sub-package: package Rcatch22 separately
- Run python test
- Add basic C test

* Thu Jul 08 2021 Ankur Sinha <ankursinha AT fedoraproject DOT org> - 0.2.1-1
- Initial build

## END: Generated by rpmautospec