File librespot.spec of Package librespot

#
# spec file for package librespot
#
# 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 https://bugs.opensuse.org/
#

%global rustflags '-Clink-arg=-Wl,-z,relro,-z,now'
%define features alsa-backend,pulseaudio-backend,jackaudio-backend,gstreamer-backend,with-tremor,with-vorbis,with-dns-sd
Name:           librespot
Version:        0.2.0
Release:        0
Summary:        Headless Spotify Connect receiver
License:        MIT
Group:          Productivity/Multimedia/Sound/Players
URL:            https://github.com/librespot-org/librespot
Source0:        %{url}/archive/refs/tags/v0.2.0.tar.gz#/%{name}-%{version}.tar.gz
Source1:        vendor.tar.xz
Source2:        cargo_config
Source3:        %{name}.service
Source4:        %{name}.config
BuildRequires:  alsa-devel 
BuildRequires:  cargo >= 1.48
BuildRequires:  rust >= 1.48
BuildRequires:  pkgconfig(avahi-compat-libdns_sd)
BuildRequires:  pkgconfig(glib-2.0)
BuildRequires:  pkgconfig(gstreamer-1.0)
BuildRequires:  pkgconfig(gstreamer-app-1.0)
BuildRequires:  pkgconfig(jack)
BuildRequires:  pkgconfig(libpulse)

%description
librespot is an open source client library for Spotify.
It enables applications to use Spotify's service to control and play music via various backends,
and to act as a Spotify Connect receiver.

%prep
%setup -qa1
mkdir .cargo                # cargo automatically uses this dir
cp %{SOURCE2} .cargo/config # and automatically uses this config

%build
export RUSTFLAGS=%{rustflags}
cargo build --release --features %{features}

%install
export RUSTFLAGS=%{rustflags}
cargo install \
  --path . \
  --no-track \
  --features %{features} \
  --root=%{buildroot}%{_prefix}
install -D -m 0644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
install -D -m 0644 %{SOURCE4} %{buildroot}%{_sysconfdir}/default/%{name}

%pre
%service_add_pre %{name}.service

%post
%service_add_post %{name}.service

%preun
%service_del_preun %{name}.service

%postun
%service_del_postun %{name}.service

%files
%doc README.md
%license LICENSE
%{_bindir}/librespot
%{_unitdir}/%{name}.service
%config %{_sysconfdir}/default/%{name}

%changelog
openSUSE Build Service is sponsored by