File earlyoom.spec of Package earlyoom

# spec file for package earlyoom
# Copyright (c) 2021 SUSE LLC
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via

# the tests are quite flaky in a VM
%bcond_with tests
%if ! 0%{?_fillupdir:1}
%global _fillupdir %{_localstatedir}/adm/fillup-templates
Name:           earlyoom
Version:        1.6.2
Release:        0
Summary:        Early OOM Daemon for Linux
License:        MIT
Group:          System/Daemons
URL:  {name}
Source0:        %{URL}/archive/v%{version}.tar.gz
Source11:       %{name}.sysconfig
# Inject pre-build earlyoom.1, built on x86_64 machine, as pandoc does not exist on all archs
Source12:       earlyoom.1
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(systemd)
Conflicts:      oomd
%if %{with tests}
BuildRequires:  go

earlyoom checks the amount of available memory and free swap, and if both are
below critical level, it will kill the largest process (highest oom_score).

# Test if our pre-build earloom.1 is newer than; if not, fail
# in case of fail, rebuild the earlyoom.1 out of the build system using
#     pandoc -s -t man > earlyoom.1
test %{SOURCE12} -nt

# Fix defaults file location
sed -i 's|/default/|/sysconfig/|'

# remove calls to systemctl in install
sed -e '/systemctl/d' -i Makefile

%if %{with tests}
# fix version test
sed -i 's|stderrContains: "earlyoom v",|stderrContains: "earlyoom %{version}",|' testsuite_cli_test.go

CFLAGS='%{?build_cflags}%{!?build_cflags:%optflags} -DVERSION=\"%{version}\" -std=gnu99'

%if %{with tests}
%make_build test

%make_install PREFIX=%{_prefix} SYSTEMDUNITDIR=%{_unitdir}
install -D -m644 %{SOURCE11} %{buildroot}%{_fillupdir}/sysconfig.%{name}
install -d %{buildroot}%{_mandir}/man1/
install -m644 %{SOURCE12} %{buildroot}%{_mandir}/man1/

mkdir -p %{buildroot}%{_sbindir}
ln -sf service %{buildroot}%{_sbindir}/rc%{name}

%license LICENSE
%exclude %{_sysconfdir}/default/%{name}

%{service_add_pre %{name}.service}

%{fillup_only %{name}}
%{service_add_post %{name}.service}

%{service_del_preun %{name}.service}

%{service_del_postun %{name}.service}

openSUSE Build Service is sponsored by