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

Name:           oscillatord
Version:        3.4.1
Release:        %autorelease
Summary:        Daemon for disciplining an oscillator

License:        GPLv2+
URL:            https://github.com/Orolia2s/oscillatord
Source0:        %{url}/archive/v%{version}/%{name}-%{version}.tar.gz
Patch0: oscillatord-c99.patch

BuildRequires:  gcc
BuildRequires:  cmake
BuildRequires:  gpsd-devel
BuildRequires:  json-c-devel
BuildRequires:  liboscillator-disciplining-devel >= %{version}
BuildRequires:  pps-tools-devel
BuildRequires:  sed
BuildRequires:  systemd
BuildRequires:  systemd-devel
BuildRequires:  systemd-rpm-macros
BuildRequires:  ubloxcfg-devel >= 1.13-1.20220420gita46d97c

Requires: liboscillator-disciplining = %{version}
Requires: ubloxcfg >= 1.13-1.20220420gita46d97c

%description
The oscillatord daemon takes input from a PHC clock, reporting once per second,
the phase error between an oscillator and a reference GNSS receiver. For an
example of such a device, please see the ptp_ocp kernel driver.

The phase error read is then used as an input to the disciplining-minipod
library which will compute a setpoint, used by oscillatord to control an
oscillator and discipline it to the 1PPS from a GNSS receiver. Oscillatord also
sets PHC'stime at start up, using Output from a GNSS receiver.

To communicate with GNSS receiver's serial it uses ubloxcfg

%prep
%autosetup -p1
# Fix paths in systemd unit
sed -e 's/^Environment=LD_LIBRARY_PATH.*$//' \
    -e "s@/usr/local/bin@%{_bindir}@" \
    -i systemd/oscillatord.service
# Drop hardcoded CFLAGS
sed -e 's/-O0//g' -i CMakeLists.txt

%build
%cmake -DBUILD_UTILS=1
%cmake_build

%install
%cmake_install

# install default config
install -Dpm0644 example_configurations/%{name}_default.conf \
    %{buildroot}%{_sysconfdir}/%{name}.conf

%post
%systemd_post oscillatord.service

%preun
%systemd_preun oscillatord.service

%postun
%systemd_postun_with_restart oscillatord.service

%files
%license LICENSE
%doc README.md example_configurations
%{_bindir}/*
%{_unitdir}/%{name}.service
%config(noreplace) %{_sysconfdir}/%{name}.conf
%exclude %{_unitdir}/%{name}@.service

%changelog
* Sat Dec 17 2022 Florian Weimer <fweimer@redhat.com> 3.4.1-3
- C99 compatibility fix

* Wed Oct 26 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.4.1-1
- Update to 3.4.1

* Fri Oct 07 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.4.0-1
- Update to 3.4.0

* Mon Sep 12 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.9-1
- Update to 3.3.9

* Mon Sep 05 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.8-2
- Add systemd in BuildRequires to fix pkgconfig systemd resolution

* Mon Sep 05 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.8-1
- Update to 3.3.8

* Wed Aug 10 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.7-1
- Update to 3.3.7

* Thu Aug 04 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.6-1
- Update to 3.3.6

* Tue Aug 02 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.5-1
- Update to 3.3.5

* Mon Aug 01 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.4-1
- Update to 3.3.4

* Fri Jul 29 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.3-1
- Update to 3.3.3

* Fri Jul 22 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.2-1
- Update to 3.3.2

* Wed Jul 13 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.3.1-1
- Update to 3.3.1

* Mon Jul 11 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.2.6-2
- [oscillatord] require exact version of liboscillator-disciplining

* Tue Jul 05 2022 Oleg Obleukhov <leoleovich@fedoraproject.org> 3.2.6-1
- Update to 3.2.6

* Fri Jun 17 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.2.4-1
- Update to 3.2.4

* Thu Jun 16 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.2.3-1
- Update to 3.2.3

* Tue Jun 07 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.2.1-1
- Update to 3.2.1

* Fri Jun 03 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.2.0-1
- Update to 3.2.0

* Wed May 25 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.1.1-1
- Update to 3.1.1

* Fri May 20 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.1.0-1
- Update to 3.1.0

* Thu May 12 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.0.10-1
- Update to 3.0.10

* Thu May 05 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.0.8-1
- Update to 3.0.8

* Wed Apr 27 2022 Alexander Bulimov <abulimov@fedoraproject.org> 3.0.3-1
- Update to 3.0.3

* Fri Mar 25 2022 Alexander Bulimov <abulimov@fedoraproject.org> 2.1.0-1
- Update to v2.1.0

* Mon Mar 07 2022 Alexander Bulimov <abulimov@fedoraproject.org> 1.3.3-1
- Update to v1.3.3

* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> 1.2.12-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild

* Tue Dec 14 2021 Alexander Bulimov <abulimov@fedoraproject.org> 1.2.12-1
- Update to v1.2.12

* Tue Nov 30 2021 Alexander Bulimov <abulimov@fedoraproject.org> 1.2.10-1
- Update to v1.2.10

* Thu Nov 18 2021 Alexander Bulimov <alexander.bulimov@gmail.com> 1.2.9-1
- Update to v1.2.9

* Mon Nov 01 2021 Alexander Bulimov <alexander.bulimov@gmail.com> 1.2.8-1
- Update to 1.2.8

* Mon Oct 18 2021 Alexander Bulimov <alexander.bulimov@gmail.com> 1.2.1-1
- Update to v1.2.1

* Mon Oct 18 2021 Alexander Bulimov <alexander.bulimov@gmail.com> 1.2.0-1
- Update to v1.2.0

* Tue Aug 17 2021 Davide Cavalca <dcavalca@fedoraproject.org> 1.0.1-1
- Initial import; Fixes: RHBZ#1992728