Files
earlyoom/earlyoom.spec

108 lines
3.0 KiB
RPMSpec

#
# spec file for package earlyoom
#
# Copyright (c) 2020 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 https://bugs.opensuse.org/
#
%global rpm_version %(rpm -q --qf %%{version} rpm)
%if ! 0%{?_fillupdir:1}
%global _fillupdir %{_localstatedir}/adm/fillup-templates
%endif
Name: earlyoom
Version: 1.3
Release: 0%{?extraver:0.}1%{?dist}
Summary: Early OOM Daemon for Linux
License: MIT
Group: System/Daemons
URL: https://github.com/rfjakob/earlyoom
Source0: %{name}-%{version}.tar.bz2
Source11: earlyoom.sysconfig
# pandoc only for `pandoc MANPAGE.md -s -t man > earlyoom.1`, thus could be excluded if earlyoom.1 would be provided.
BuildRequires: pandoc
BuildRequires: pkgconfig
BuildRequires: pkgconfig(systemd)
Requires(post): insserv-compat
Recommends: libnotify%{?suse_version:-tools}
Conflicts: oomd
%description
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).
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{name}-%{version}%{?extraver}
# Fix defaults file location
sed -i 's|/default/|/sysconfig/|' earlyoom.service.in
# CentOS' gzip does not have option `-k`
sed -i 's|gzip -f -k.*$|gzip -c $< > $@|' Makefile
# Fix LDFLAGS handling
sed -ri '/LDFLAGS/ s|$| -lrt|' Makefile
# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags} %{?gcc_lto} -Wall -Wextra -DVERSION=\"%{version}\" -fstack-protector-all -std=gnu99'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all %{?gcc_lto}'
make %{?_smp_mflags} \
CFLAGS="$_CFLAGS" \
LDFLAGS="$_LDFLAGS"
# Install built stuff
%install
make install DESTDIR=%{buildroot} \
SYSTEMDUNITDIR=%{_unitdir} \
PREFIX=%{_prefix}
install -D -m644 %{SOURCE11} %{buildroot}%{_fillupdir}/sysconfig.%{name}
# Files list
%files
%license LICENSE
%doc MANPAGE.md README.md
%{_bindir}/earlyoom
%{_unitdir}/%{name}.service
%exclude %{_sysconfdir}/default/earlyoom
%{_fillupdir}/sysconfig.%{name}
%{_mandir}/man1/earlyoom.1%{?ext_man}
%if 0%{?_unitdir:1}
%pre
%{service_add_pre %{name}.service}
%endif
%post
%if 0%{?_unitdir:1}
%{fillup_only %{name}}
%{service_add_post %{name}.service}
%else
%{fillup_and_insserv %{name}}
%endif
%preun
%if 0%{?_unitdir:1}
%{service_del_preun %{name}.service}
%else
%{stop_on_removal %{name}}
%endif
%postun
%if 0%{?_unitdir:1}
%{service_del_postun %{name}.service}
%else
%{restart_on_update %{name}}
%endif
%insserv_cleanup
%changelog