# -*- mode: rpm-spec; indent-tabs-mode: nil -*-
#========================================================================
%global debug_package %{nil}

%define    ldas_tools_cmake_ver @LDAS_TOOLS_CMAKE_VERSION@
%define    ldas_tools_al_ver    @LDAS_TOOLS_AL_VERSION@
%define    basename_            ldas-tools-al
%define    name                 %{basename_}-swig
%define    hdr_dir              ldastoolsal
%define    tarbasename          @PROJECT_NAME@
%define    version              @PROJECT_VERSION@
%define    release              1
%define    _docdir              %{_datadir}/doc/%{name}-%{version}

%define check_cmake3  ( 0%{?rhel} && 0%{?rhel} <= 7 )
%define check_python3 ( 0%{?__python3:1} || ( 0%{?rhel} >= 7 ) )
%define check_gcc_toolset_14 ( 0%{?rhel} == 8 )

#------------------------------------------------------------------------
Name:      %{name}
Summary:   LDAS tools abstraction toolkit language buildings
Version:   %{version}
Release:   %{release}%{?dist}
License:        GPLv2+ and BSD
URL:       @PACKAGE_URL@
Group:     Application/Scientific
Conflicts: ldas-tools-al <= 2.6.1
Prefix:    %_prefix
BuildRoot: %{buildroot}
Source0:   @LDAS_TOOLS_SOURCE_URL@/%{tarbasename}-%{version}.tar.gz

#------------------------------------------------------------------------

%if %{check_cmake3}
BuildRequires: cmake3 >= 3.6
BuildRequires: cmake
%else
BuildRequires: cmake >= 3.6
%endif
BuildRequires: gawk
BuildRequires: gcc, gcc-c++, glibc
BuildRequires: make
BuildRequires: pkgconfig
BuildRequires: python3-rpm-macros
BuildRequires: rpm-build
%if %{check_gcc_toolset_14}
# C++20 thread library on EL 8 requires gcc-toolset-14 to BUILD (issue #302).
# Mechanism: toolset's libstdc++_nonshared.a statically links new GLIBCXX
# 3.4.26+ symbols (std::jthread, std::stop_token, ...) into each binary;
# runtime libstdc++.so.6 is the system one. No SCL runtime dep on installed
# RPMs. Validated by .gitlab-ci-local/el8-cxx20-smoke.yml.
BuildRequires: gcc-toolset-14-gcc-c++
BuildRequires: gcc-toolset-14-libstdc++-devel
%endif
BuildRequires: swig >= @LDAS_TOOLS_SWIG_VERSION@
BuildRequires: ldas-tools-cmake-devel >= %{ldas_tools_cmake_ver}
BuildRequires: %{basename_}-devel >= %{ldas_tools_al_ver}

#........................................................................
# Python 3 dependencies
#........................................................................
BuildRequires: python3
BuildRequires: python3-devel
#........................................................................
# Runtime dependencies
#........................................................................
Requires: %{basename_}-devel

%description
This provides the runtime libraries for the abstaction library.

#========================================================================
%package -n python%{python3_pkgversion}-%{basename_}
Summary:   LDAS tools abstraction toolkit language buildings
#........................................................................
# Runtime dependencies
#........................................................................
Requires: ldas-tools-al >= %{ldas_tools_al_ver}
Requires: python3
%{?python_provide:%python_provide python%{python3_pkgversion}-%{basename_}}

%description -n  python%{python3_pkgversion}-%{basename_}
This provides the runtime libraries for the abstaction library.

%prep
%setup -c -T -D -a 0 -n %{name}-%{version}

%build
%if %{check_gcc_toolset_14}
# Source gcc-toolset-14 for the rest of this section (issue 302).
# (Do not use literal section names or hash-ticket-number in this comment —
# rpmbuild's spec parser scans for %% directives and matches across the
# whole line, not just line-start, on some older EL 8 rpm versions.)
. /opt/rh/gcc-toolset-14/enable
%endif
%if %check_python3
export PYTHON3_BUILD_OPTS="-DENABLE_SWIG_PYTHON3=YES -DPYTHON3_EXECUTABLE=%{__python3}"
%else
export PYTHON3_BUILD_OPTS="-DENABLE_SWIG_PYTHON3=NO"
%endif

%if %{check_cmake3}
export CMAKE_PROGRAM=cmake3
%else
export CMAKE_PROGRAM=cmake
%endif

${CMAKE_PROGRAM} \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=1 \
    -DCMAKE_INSTALL_PREFIX=%{_prefix} \
    -DCMAKE_INSTALL_DOCDIR=%{_docdir} \
    ${PYTHON3_BUILD_OPTS} \
    %{tarbasename}-%{version}

%install
%if %{check_gcc_toolset_14}
# Source gcc-toolset-14 for the rest of this section (issue 302).
. /opt/rh/gcc-toolset-14/enable
%endif
%if %{check_cmake3}
export CMAKE_PROGRAM=cmake3
%else
export CMAKE_PROGRAM=cmake
%endif

${CMAKE_PROGRAM} --build . --target install -- DESTDIR=%{buildroot}

%check
%if %{check_cmake3}
export CTEST_PROGRAM=ctest3
%else
export CTEST_PROGRAM=ctest
%endif

${CTEST_PROGRAM} -V %{?_smp_mflags}

%clean
rm -rf %{buildroot}

%files
%license %{name}-%{version}/COPYING
%license %{name}-%{version}/LICENSE.md
%defattr(-,root,root,-)
%{_includedir}/%{hdr_dir}/*.i

%files -n python%{python3_pkgversion}-%{basename_}
%defattr(-,root,root,-)
%{_libdir}/python3*

%changelog
* Tue Jun 23 2026 Ed Maros <ed.maros@ligo.org> - 2.6.14-1
- Built for 2.6.14 release as described in ChangeLog.md

* Thu May 21 2026 Edward Maros <ed.maros@ligo.org> - 2.6.13-1
- Built for 2.6.13 release as described in ChangeLog.md

* Wed Apr 01 2026 Edward Maros <ed.maros@ligo.org> - 2.6.12-1
- Built for 3.2.1 release as described in ChangeLog.md

* Mon Dec 16 2024 Edward Maros <ed.maros@ligo.org> - 2.6.11-1
- Built for new release

* Fri Jun 17 2022 Edward Maros <ed.maros@ligo.org> - 2.6.10-1
- Built for new release

* Wed Sep 29 2021 Edward Maros <ed.maros@ligo.org> - 2.6.9-1
- Built for new release

* Tue Mar 9 2021 Edward Maros <ed.maros@ligo.org> - 2.6.8-1
- Built for new release

* Wed Aug 14 2019 Edward Maros <ed.maros@ligo.org> - 2.6.7-1
- Built for new release

* Tue Nov 27 2018 Edward Maros <ed.maros@ligo.org> - 2.6.5-1
- Built for new release

* Tue Oct 11 2011 Edward Maros <emaros@ligo.caltech.edu> - 1.19.13-1
- Initial build.
