%{?!WITH_SYSV: %define WITH_SYSV 1}

Summary: CDEmu daemon
Summary(ja): CDEmu デーモン
Name: cdemu-daemon
Version: 1.4.0
Release: 1%{?_dist_release}
License: GPLv2+
Group: System Environment/Daemons
URL: http://cdemu.sourceforge.net
Source0: http://downloads.sourceforge.net/cdemu/%{name}-%{version}.tar.gz
Source1: cdemu-daemon.init
Source2: cdemu-daemon.sysconfig
# should be fixed upstream?
#Patch10: %{name}-1.2.0-bigendian-fix.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: dbus-devel >= 0.90
BuildRequires: dbus-glib-devel >= 0.70
BuildRequires: libdaemon-devel >= 0.11
BuildRequires: glib2-devel >= 2.6
BuildRequires: libmirage-devel >= 1.2.0
BuildRequires: libao-devel >= 0.8.0
BuildRequires: sysfsutils-devel

Requires: dkms-vhba

%description
This is CDEmu daemon, the userspace daemon part of the userspace-cdemu suite, a 
free, GPL CD/DVD-ROM device emulator for linux.

It receives SCSI commands from kernel module and processes them, passing the 
requested data back to the kernel. Daemon implements the actual virtual device; 
one instance per each device registered by kernel module. It uses libMirage, an 
image access library that is part of userspace-cdemu suite, for the image access 
(e.g. sector reading).

The daemon registers itself on D-BUS' system or session bus (depending on the
options passed to it) where it exposes an interface that can be used by clients
to control it.

%if %{WITH_SYSV}
%package sysv
Summary: SysV initscripts for cdemu-daemon
Group: System Environment/Daemon
Requires: %{name} = %{version}
Requires(post): initscripts, chkconfig

%description sysv
This is CDEmu daemon, the userspace daemon part of the userspace-cdemu suite, a 
free, GPL CD/DVD-ROM device emulator for linux.

This package provides SysV initscripts for running CDEmu daemon in daemon mode.
%endif


%prep
%setup -q
#%patch10 -p1 -b .bigendian
cp -p %{SOURCE1} ./cdemu-daemon.init
cp -p %{SOURCE2} ./cdemu-daemon.sysconfig

%build
%{configure}
%{__make} %{?_smp_mflags}

%install
%{__rm} -rf $RPM_BUILD_ROOT
%{__make} install DESTDIR=$RPM_BUILD_ROOT

%if %{WITH_SYSV}
%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig
%{__mkdir_p} $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d
%{__install} -Dpm 644 cdemu-daemon.init $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/cdemu-daemon
%{__install} -Dpm 755 cdemu-daemon.sysconfig $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/cdemu-daemon
%endif


%clean
rm -rf $RPM_BUILD_ROOT

%post sysv
# Run cdemu-daemon by default:
/sbin/chkconfig --add cdemu-daemon >/dev/null 2>&1 || :
/sbin/chkconfig cdemu-daemon on

%preun sysv
if [ "$1" -eq 0 ]; then
    /sbin/service cdemu-daemon stop > /dev/null 2>&1 || :
    /sbin/chkconfig --del cdemu-daemon
fi

%postun sysv
if [ "$1" -ge "1" ]; then
   /sbin/service cdemu-daemon condrestart >/dev/null 2>&1 || :
fi

%files
%defattr(-,root,root,-)
%doc AUTHORS ChangeLog COPYING NEWS README
%config(noreplace) %{_sysconfdir}/dbus-1/system.d/cdemud-dbus.conf
%{_bindir}/*
%{_mandir}/man8/*
%{_datadir}/dbus-1/*

%if %{WITH_SYSV}
%files sysv
%defattr(-,root,root,-)
%config(noreplace) %{_sysconfdir}/sysconfig/cdemu-daemon
%attr(0755,root,root) %{_sysconfdir}/rc.d/init.d/cdemu-daemon
%endif

%changelog
* Sat Dec 24 2011 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.4.0-1
- new upstream release

* Fri Nov 19 2010 IWAI, Masaharu <iwai@alib.jp> 1.3.0-2
- add Requires: dkms-vhba

* Thu Sep 2 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.3.0-1
- new upstream release
- dropt patch10

* Mon Oct 12 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.2.0-2
- add Patch10 to fix build failure on ppc

* Sat Sep 26 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.2.0-1
- initial build for VineSeed

* Sat Jun 28 2008 Rok Mandeljc <rok.mandeljc@email.si> - 1.1.0-1
- Updated to 1.1.0

* Thu Dec 20 2007 Rok Mandeljc <rok.mandeljc@email.si> - 1.0.0-1
- Initial RPM release.
