%define build_kmod 0
%define kversion %(uname -r)
%define kver    %(uname -r | sed -e 's/-/_/g')
%define kflavor %(uname -r | sed -e 's/.*vl.//')
%if "%kflavor" == ""
%undefine kflavor
%endif
%define kmod	kernel-module%{?kflavor:-%{kflavor}}

%define name	kqemu
%define ver	1.4.0
%define rel	1.pre1%{?_dist_release}

Summary:	QEMU accelerator Linux kernel module
Summary(ja): 	QEMU Accelerator Linux カーネルモジュール
Name:		%{name}
Version:	%{ver}
Release: 	%{rel}
Source0:	%{name}-%{ver}pre1.tar.gz
Source1:	kqemu.modules
Source2:	99-kqemu.rules
Source10:	kqemu-kmp.spec
License:	GPL2
Group:		System Environment/Base
URL:		http://fabrice.bellard.free.fr/qemu/

Requires:	qemu >= 0.9.1
BuildRequires:	kernel-devel

BuildRoot:	%{_tmppath}/%{name}-%{ver}-root


%description
QEMU Accelerator (KQEMU) is a kernel module allowing the QEMU PC 
emulator to run much faster when emulating a PC on an x86 host.

%description -l ja
QEMU Accelerator (KQEMU) は、x86 プロセッサを搭載したホスト PC 上で 
PC エミュレーションを実行する時に、QEMU PC エミュレータを非常に高速に
実行できるカーネルモジュールです。

#------------------------------------------------------------------------------

%package -n dkms-%{name}
Summary:         QEMU accelerator Linux kernel module
Summary(ja):     QEMU Accelerator Linux カーネルモジュール
Group:           System Environment/Kernel

Requires:        %{name} = %{version}-%{release}
Requires:        qemu >= 0.8.1
Requires(pre):   kernel, kernel-devel
Requires(post):  dkms
Requires(preun): dkms
Obsoletes:       kernel-module-kqemu

%description -n dkms-%{name}
QEMU Accelerator (KQEMU) is a kernel module allowing the QEMU PC 
emulator to run much faster when emulating a PC on an x86 host.

%description -n dkms-%{name} -l ja
QEMU Accelerator (KQEMU) は、x86 プロセッサを搭載したホスト PC 上で 
PC エミュレーションを実行する時に、QEMU PC エミュレータを非常に高速に
実行できるカーネルモジュールです。

#------------------------------------------------------------------------------

%prep
%setup -q -n %{name}-%{ver}pre1


%build


%install
%__rm -rf %{buildroot}

# install system config files.
%__install -d -m 755 %{buildroot}/%{_sysconfdir}/sysconfig/modules/
%__install -m 755 %{SOURCE1} %{buildroot}/%{_sysconfdir}/sysconfig/modules/
%__install -d -m 755 %{buildroot}/%{_sysconfdir}/udev/rules.d/
%__install -m 644 %{SOURCE2} %{buildroot}/%{_sysconfdir}/udev/rules.d/

# install kernel module source.
mkdir -p %{buildroot}/usr/src/%{name}-%{version}-%{release}
cp -a * %{buildroot}/usr/src/%{name}-%{version}-%{release}/

## DKMS.CONF ##
cat > %{buildroot}/usr/src/%{name}-%{version}-%{release}/dkms.conf << EOF

PACKAGE_NAME="%{name}"
PACKAGE_VERSION="%{version}-%{release}"

BUILT_MODULE_NAME[0]="kqemu"
DEST_MODULE_LOCATION[0]="/extra/kqemu"
MAKE[0]="./configure --kernel-path=\${kernel_source_dir} && make"

AUTOINSTALL="YES"

EOF

## KMP.SPEC ##
sed -e 's|##KMOD_NAME##|%{name}|g' \
    -e 's|##KMOD_VER##|%{version}-%{release}|g' \
    -e 's|##LICENSE##|%{license}|g' \
    %{SOURCE10} > \
    %{buildroot}/usr/src/%{name}-%{version}-%{release}/%{name}-kmp.spec


%clean
%__rm -rf %{buildroot}


%post -n dkms-%{name}
/usr/sbin/dkms add     -m %{name} -v %{version}-%{release} --rpm_safe_upgrade
/usr/sbin/dkms mkkmp   -m %{name} -v %{version}-%{release}
/usr/sbin/dkms build   -m %{name} -v %{version}-%{release} --rpm_safe_upgrade
/usr/sbin/dkms install -m %{name} -v %{version}-%{release} --rpm_safe_upgrade
exit 0


%preun -n dkms-%{name}
/usr/sbin/dkms remove  -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --all
exit 0


%files
%defattr(-,root,root)
%doc Changelog LICENSE kqemu-doc.html kqemu-doc.texi
%{_sysconfdir}/sysconfig/modules/kqemu.modules
%{_sysconfdir}/udev/rules.d/99-kqemu.rules


%files -n dkms-%{name}
%defattr(-,root,root)
%dir /usr/src/%{name}-%{version}-%{release}
/usr/src/%{name}-%{version}-%{release}/*


%changelog
* Tue Nov 03 2009 NAKAMURA Kenta <kenta@vinelinux.org> - 1.4.0-1.pre1
- new upstream release.

* Sat May  2 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.3.0-5.pre11
- fix post/preun scripts for dkms subpackage

* Sun Apr 26 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.3.0-4.pre11
- add Source10 for mkkmp feature

* Thu Apr  9 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.3.0-3.pre11
- drop kernel-module-kqemu subpackage; make DKMS-compatible

* Tue Jan 28 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.3.0-2.pre11
- add kflavor(pae,smp..) to package name

* Sun Apr 27 2008 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-1.pre11
- apply new versioning policy.

* Wed Mar 07 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl4.0pre11
- new upstream release.
- license is changed to GPL.

* Wed Sep 06 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl3.0pre9
- fix typo of Group <BTS:VineLinux:148>.

* Sat Jul 22 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl2.0pre9
- run depmod for target kernel version
  (we need System.map to run depmod in %%post script)

* Mon Jul 17 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl1.0pre9
- combine kqemu-common & kernel-module-kqemu to one source package.
- add build_kmod option to switch build target.(kqemu or kernel-module-kqemu)
- change Group to System Environment/Base for kqemu.
- build for kernel-2.6.16-0vl20

* Mon Jul 03 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl0.0pre9.2
- build for kernel-2.6.16-0vl19
- add Requires qemu >= 0.8.1

* Sun Jul 02 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl0.0pre9.1
- build for kernel-2.6.16-0vl18

* Sun Jul 02 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.3.0-0vl0.0pre9.1
- initial build for VineSeed test package.
- build for kernel-2.6.16-0vl17
