File ddccontrol.spec of Package ddccontrol

%define realname ddccontrol
%define srcext   tar.xz

%define db_ver   20210505

%if 0%{?suse_version} >= 1230 || 0%{?rhel} >= 7
%bcond_without systemd
%else
%bcond_with systemd
%endif

%define so_ver   0

# Common info
Name:          %{realname}
Version:       0.4.2
Release:       wiz%{?extraver:0.}1%{?dist}
License:       GPL-2.0
Group:         Hardware/Other
URL:           https://github.com/ddccontrol/ddccontrol
Summary:       Control monitor parameters via DDC/CI
Summary(ru_RU.UTF-8): Управление параметрами монитора посредством DDC/CI

# Install-time parameters
%if 0%{?suse_version}
PreReq:        permissions
%endif
Provides:      ddccontrol-db = %{db_ver}-%{release}
Provides:      ddccontrol-gtk = %{version}-%{release}
Provides:      libddccontrol%{so_ver} = %{version}-%{release}
Provides:      libddccontrol_dbus_client%{so_ver} = %{version}-%{release}
Provides:      libddccontrol
Provides:      libddccontrol_dbus_client
Obsoletes:     ddccontrol-db < %{db_ver}-%{release}
Obsoletes:     ddccontrol-gtk < %{version}-%{release}
Obsoletes:     libddccontrol%{so_ver} < %{version}-%{release}
Obsoletes:     libddccontrol_dbus_client%{so_ver} < %{version}-%{release}

# Build-time parameters
BuildRequires: autoconf automake libtool intltool
BuildRequires: pkgconfig gettext perl
BuildRequires: libxml2-devel pciutils-devel zlib-devel
%if 0%{?suse_version} >= 1130 || 0%{?rhel} >= 6
BuildRequires: pkgconfig(gtk+-2.0) >= 2.4 pkgconfig(gthread-2.0) >= 2.4
BuildRequires: perl(XML::Parser)
%else
BuildRequires: gtk2-devel
BuildRequires: perl-XML-Parser
%endif
%if 0%{?suse_version}
BuildRequires: update-desktop-files
%endif
%if %{with systemd}
BuildRequires: systemd
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       %{realname}-%{version}%{?extraver}.%{srcext}
Source1:       ddccontrol-db-%{db_ver}.%{srcext}

%description
DDCcontrol is a program running on Linux, used to control monitor parameters,
like brightness and contrast, by software, i.e. without using the OSD (On Screen
Display) and the buttons in front of the monitor.

%description -l ru_RU.UTF-8
DDCcontrol - программа для Linux, предназначенная для программного, т.е. без
использования OSD (экранного меню) и кнопок, управления параметрами монитора,
такими как яркость и контраст.

%package devel
Group:         Development/Languages/C and C++
Summary:       Development files for %{name}
Requires:      %{name} = %{version}
Provides:      libddccontrol-devel

%description devel
Development files for %{name}

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{version}%{?extraver} -a1
if [ ! -x configure ]; then
  if [ -x autogen.sh ]; then
    ./autogen.sh
  else
    autoreconf --force --install
  fi
fi
cd ddccontrol-db-%{db_ver}
if [ ! -x configure ]; then
  if [ -x autogen.sh ]; then
    ./autogen.sh
  else
    autoreconf --install
  fi
fi
cd -

%build
%configure \
 --disable-static \
 CFLAGS="%{optflags} %{?gcc_lto}" \
 LDFLAGS="-Wl,--as-needed -Wl,--strip-all -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}"
%{__make} %{?_smp_mflags}
cd ddccontrol-db-%{db_ver}
%configure
%{__make} %{?_smp_mflags}
cd -

%install
%{__make} install DESTDIR=%{buildroot}
%{__make} install DESTDIR=%{buildroot} \
 -C ddccontrol-db-%{db_ver}
%find_lang %{name}
%find_lang %{name}-db %{name}-db.lang
%if 0%{?suse_version}
%{__mkdir} %{buildroot}%{_sysconfdir}/permissions.d
echo '%{_libexecdir}/ddccontrol/ddcpci root:root 4711' > %{buildroot}%{_sysconfdir}/permissions.d/%{name}
%suse_update_desktop_file -r gddccontrol GTK Settings HardwareSettings
%endif

%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

%files -f %{name}.lang -f %{name}-db.lang
%defattr(-,root,root)
%doc AUTHORS CHANGELOG.md COPYING NEWS README.md
%{_bindir}/ddccontrol
%{_bindir}/gddccontrol
%{_libdir}/libddccontrol.so.*
%{_libdir}/libddccontrol_dbus_client.so.*
%dir %{_libexecdir}/ddccontrol
%{_libexecdir}/ddccontrol/*
%config %{_sysconfdir}/dbus-1/system.d/ddccontrol.DDCControl.conf
%if 0%{?suse_version}
%config %{_sysconfdir}/permissions.d/%{name}
%endif
%if %{with systemd}
%{_unitdir}/ddccontrol.service
%endif
%{_datadir}/dbus-1/interfaces/ddccontrol.DDCControl.xml
%{_datadir}/dbus-1/system-services/ddccontrol.DDCControl.service
%dir %{_datadir}/ddccontrol-db/
%{_datadir}/ddccontrol-db/*
%{_datadir}/applications/gddccontrol.desktop
%dir %{_datadir}/icons/Bluecurve/48x48/apps
%dir %{_datadir}/icons/Bluecurve/48x48
%dir %{_datadir}/icons/Bluecurve
%{_datadir}/icons/Bluecurve/48x48/apps/gddccontrol.png
%{_datadir}/icons/hicolor/48x48/apps/gddccontrol.png
%doc %{_mandir}/man1/*

%files devel
%defattr(-,root,root)
%dir %{_includedir}/%{name}
%{_libdir}/pkgconfig/ddccontrol.pc
%{_includedir}/%{name}/*.h
%{_libdir}/libddccontrol.so
%{_libdir}/libddccontrol_dbus_client.so
%exclude %{_libdir}/*.la

%if 0%{?suse_version} && %{with systemd}
%pre
%{service_add_pre %{name}.service}

%preun
%{service_del_preun %{name}.service}
%endif

%post
/sbin/ldconfig
%if 0%{?suse_version}
%set_permissions /usr/lib/ddccontrol/ddcpci
%if %{with systemd}
%{service_add_post %{name}.service}
%endif
%endif

%postun
/sbin/ldconfig
%if 0%{?suse_version} && %{with systemd}
%{service_del_postun %{name}.service}
%endif

%if 0%{?suse_version}
%verifyscript
%verify_permissions -e /usr/lib/ddccontrol/ddcpci
%endif

%changelog
openSUSE Build Service is sponsored by