## START: Set by rpmautospec
## (rpmautospec version 0.6.3)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 1;
    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

# The project contains a version number, but a release has never been tagged.
# The project is normally used as a git submodule and referred to by commit
# hash.
%global commit 0ee9c03d0ef3a7f12db6cb03570aa7606f12ba1b
%global snapdate 20240426

Name:           c4fs
Summary:        C++ file system utilities
Version:        0.0.1^%{snapdate}git%{sub %{commit} 1 7}
# This is the same as the version number. To prevent undetected soversion
# bumps, we nevertheless express it separately.
%global so_version 0.0.1
Release:        %autorelease

# SPDX
License:        MIT
URL:            https://github.com/biojppm/c4fs
Source:         %{url}/archive/%{commit}/c4fs-%{commit}.tar.gz

# Upstream always wants to build with c4core as a git submodule, but we want to
# unbundle it and build with an external library. We therefore maintain this
# patch without sending it upstream.
Patch:          c4fs-1abba00-external-c4core.patch

BuildRequires:  gcc-c++
BuildRequires:  cmake
BuildRequires:  c4project
# Our choice; the default make backend should work just as well
BuildRequires:  ninja-build

BuildRequires:  cmake(c4core)

# For each header-only library, the guidelines require us to BR the -static
# package for tracking.
BuildRequires:  doctest-devel
BuildRequires:  doctest-static

%description
%{summary}.


%package devel
Summary:        Development files for c4fs

Requires:       c4fs%{?_isa} = %{version}-%{release}
Requires:       c4core-devel%{?_isa}

%description devel
The c4fs-devel package contains libraries and header files for developing
applications that use c4fs.


%prep
%autosetup -n c4fs-%{commit} -p1

# Remove/unbundle additional dependencies

# c4project (CMake build scripts)
find ext
cp -rp '%{_datadir}/cmake/c4project' ext/c4core/cmake

# Do not try to link against a nonexistent doctest library (doctest is
# header-only, and we do not have the complete CMake project for doctest that
# would provide a target that knows this):
sed -r -i \
    -e 's/(LIBS.*)\bdoctest\b/\1/' \
    -e 's/(c4_setup_testing\()DOCTEST\)/\1\)/' \
    test/CMakeLists.txt


%build
# We can stop the CMake scripts from downloading doctest by setting
# C4FS_CACHE_DOWNLOAD_DOCTEST to any directory that exists.
%cmake -GNinja \
  -DC4FS_CACHE_DOWNLOAD_DOCTEST:PATH=/ \
  -DC4FS_BUILD_TESTS=ON
%cmake_build


%install
%cmake_install
# Fix wrong installation paths for multilib; it would be nontrivial to patch
# the source to get this right in the first place. The installation path is
# determined by the scripts in https://github.com/biojppm/cmake, packaged as
# c4project.
#
# Installation directory on Linux 64bit OS
# https://github.com/biojppm/rapidyaml/issues/256
if [ '%{_libdir}' != '%{_prefix}/lib' ]
then
  mkdir -p '%{buildroot}%{_libdir}'
  mv -v %{buildroot}%{_prefix}/lib/libc4fs.so* '%{buildroot}%{_libdir}/'
  mkdir -p '%{buildroot}%{_libdir}/cmake'
  mv -v %{buildroot}%{_prefix}/lib/cmake/c4fs '%{buildroot}%{_libdir}/cmake/'
  find %{buildroot}%{_libdir}/cmake/c4fs -type f -name '*.cmake' -print0 |
    xargs -r -t -0 sed -r -i "s@/lib/@/$(basename '%{_libdir}')/@"
fi


%check
%cmake_build --target c4fs-test-run-verbose


%files
%license LICENSE.txt
%doc README.md
%{_libdir}/libc4fs.so.%{so_version}


%files devel
# %%{_includedir}/c4 is owned by c4core-devel
%{_includedir}/c4/fs
%{_libdir}/libc4fs.so
%{_libdir}/cmake/c4fs


%changelog
## START: Generated by rpmautospec
* Sat Apr 27 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20240426git0ee9c03-1
- Update to 0.0.1^20240426git0ee9c03

* Fri Apr 05 2024 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20240405gitedbf7fa-1
- Update to 0.0.1^20240405gitedbf7fa

* Tue Jan 23 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.1^20230512git99eedfa-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Fri Jan 19 2024 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.1^20230512git99eedfa-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild

* Sun Jul 16 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20230512git99eedfa-2
- Fix wrong multilib library paths in .cmake files (fix RHBZ#2223194)

* Thu May 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20230512git99eedfa-1
- Update to 99eedfa

* Thu May 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20221129git0130061-6
- Improved spec-file comment on multilib path

* Thu May 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20221129git0130061-5
- Drop unnecessary manual dependency on cmake-filesystem

* Thu May 25 2023 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20221129git0130061-4
- Do not number the sole Source

* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.1^20221129git0130061-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Wed Dec 28 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20221129git0130061-1
- Update to 0130061

* Mon Dec 19 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220819git3b5bafa-2
- Rebuild for c4core 0.1.11

* Wed Aug 31 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220819git3b5bafa-1
- c4core 0.1.10

* Thu Aug 04 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220225gitf78cbd8-1
- Update to f78cbd8

* Sun Jul 31 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220102git8ffaf65-4
- Confirm that License is SPDX MIT (no License field change)

* Wed Jul 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 0.0.1^20220102git8ffaf65-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild

* Mon Apr 25 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220102git8ffaf65-2
- Simplify doctest download workaround

* Wed Apr 20 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1^20220102git8ffaf65-1
- Drop “forge” macros to use modern snapshot versioning

* Wed Apr 20 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1-6
- Stop numbering patches

* Sat Mar 05 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1-5
- Rebuild for c4core 0.1.9

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

* Thu Jan 13 2022 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1-3
- Update to 8ffaf65 and rebuild for c4core 0.1.8

* Mon Dec 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1-2
- Update to 1abba00

* Mon Dec 27 2021 Benjamin A. Beasley <code@musicinmybrain.net> - 0.0.1-1
- Initial package (close RHBZ#2025359)
## END: Generated by rpmautospec