Name:               alsa-utils
Version:            1.1.6
Release:            8
Summary:            Advanced linux sound architecture (ALSA) utility to the Linux operating system.
License:            GPLv2+
URL:                http://www.alsa-project.org/
Source:             ftp://ftp.alsa-project.org/pub/utils/alsa-utils-%{version}.tar.bz2
Patch0000:          alsa-git.patch
Source1:            alsaunmute
Source2:            alsa.rules
Source3:            alsactl.conf
Source4:            alsa-restore.service
Source5:            alsa-state.service

BuildRequires:      alsa-lib-devel >= 1.1.6 libsamplerate-devel
BuildRequires:      ncurses-devel gettext-devel xmlto python3-docutils systemd
Requires(post):     systemd
Requires(preun):    systemd
Requires(postun):   systemd
Requires:           alsa-lib >= 1.1.6

%description
This package provides command line utilities for audio and MIDI functionality
to the Linux operating system.

%package devel
Summary:            ALSA Basic Audio Tester
BuildRequires:      fftw-devel
Provides:           %{name}-alsabat = %{version}-%{release}
Obsoletes:          %{name}-alsabat < %{version}-%{release}

%description devel
This package contains tool for basic audio testing using ALSA framework
and Fast Fourier Transform library.

%package help
Summary:            ALSA help

%description help
This package contains help documentation for alsa-utils.

%prep
%autosetup -n %{name}-%{version} -p1

%build
%configure CFLAGS="$RPM_OPT_FLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" --disable-alsaconf \
   --with-udev-rules-dir=%{_prefix}/lib/udev/rules.d --with-systemdsystemunitdir=%{_unitdir}
%make_build
cp %{SOURCE1} .

%install
%make_install
%find_lang %{name}

install -d %{buildroot}/%{_prefix}/lib/udev/rules.d
install -pm 644 %{SOURCE2} %{buildroot}/%{_prefix}/lib/udev/rules.d/90-alsa-restore.rules
sed -e 's,@bindir@,%{_bindir},g' alsaucm/89-alsa-ucm.rules.in > alsaucm/89-alsa-ucm.rules
install -pm 644 alsaucm/89-alsa-ucm.rules %{buildroot}/%{_prefix}/lib/udev/rules.d/89-alsa-ucm.rules
install -d %{buildroot}/%{_unitdir}
install -pm 644 %{SOURCE4} %{buildroot}/%{_unitdir}/alsa-restore.service
install -pm 644 %{SOURCE5} %{buildroot}/%{_unitdir}/alsa-state.service

install -d -m 755 %{buildroot}/%{_bindir}
install -p -m 755 %{SOURCE1} %{buildroot}/%{_bindir}
install -d -m 755 %{buildroot}/%{_mandir}/man1

install -d -m 755 %{buildroot}/%{_prefix}/lib/alsa
mv %{buildroot}%{_datadir}/alsa/init %{buildroot}/%{_prefix}/lib/alsa

ln -s ../../lib/alsa/init %{buildroot}%{_datadir}/alsa/init

install -d -m 755 %{buildroot}/etc/alsa
install -pm 644 %{SOURCE3} %{buildroot}/etc/alsa
install -d -m 755 %{buildroot}/var/lib/alsa

%pre
if [ ! -r %{_unitdir}/alsa-state.service ]; then
  [ -d /etc/alsa ] || mkdir -m 0755 /etc/alsa
  echo "# Remove this file to disable the alsactl daemon mode" > \
        /etc/alsa/state-daemon.conf
fi

%post
%systemd_post alsa-state.service

%preun
%systemd_preun alsa-state.service

%postun
%systemd_postun_with_restart alsa-state.service

%files -f %{name}.lang
%doc COPYING ChangeLog
%config %{_sysconfdir}/alsa/*
%{_prefix}/lib/udev/rules.d/*
%{_unitdir}/*
%{_unitdir}/sound.target.wants/*
%{_prefix}/lib/alsa/init/*
%{_bindir}/*
%exclude %{_bindir}/alsabat
%{_sbindir}/*
%{_datadir}/alsa/
%{_datadir}/sounds/*
%dir %{_sysconfdir}/alsa/
%dir %{_prefix}/lib/alsa/
%dir %{_prefix}/lib/alsa/init/
%dir %{_sharedstatedir}/alsa/
%files devel
%{_bindir}/alsabat

%files help
%{_mandir}/*/*
%doc README TODO

%changelog
* Fri Feb 14 2020 gulining<gulining1@huawei.com> - 1.1.6-8
- Package init
