%define kmod_name ##KMOD_NAME##
%define kmod_ver  ##KMOD_VER##

%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

Name: kmod-%{kmod_name}%{?kflavor:-%{kflavor}}-source
Version: %(echo %{kmod_ver} | sed -e 's/-.*//g')
Release: %(echo %{kmod_ver} | sed -e 's/.*-//g')
License: ##LICENSE##
Group: System Environment/Kernel
Summary: source of %{kmod_name} kernel module

Source: %{kmod_name}-%{kmod_ver}.tar.bz2

BuildRequires: dkms >= 2.0.21.1-2vl5

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


%description
source of %{kmod_name} kernel module


%package -n kmod-%{kmod_name}%{?kflavor:-%{kflavor}}
Version: %(echo %{kmod_ver} | sed -e 's/-.*//g')_%{kver}
Release: %(echo %{kmod_ver} | sed -e 's/.*-//g')
Requires: kernel = %{kversion}
Group: System Environment/Kernel
Summary: prebuilt %{kmod_name} module for kernel %{version}%{?kflavor:-%{kflavor}}

%description -n kmod-%{kmod_name}%{?kflavor:-%{kflavor}}
source of prebuilt %{kmod_name} module for kernel %{version}%{?kflavor:-%{kflavor}}


%prep
%setup -q -n %{kmod_name}-%{kmod_ver}


%build


%install
rm -rf %{buildroot}

mkdir -p %{buildroot}/var/lib/dkms
mkdir -p %{buildroot}/lib/modules/%{kversion}

dkms add              -m %{kmod_name} -v %{kmod_ver} -c dkms.conf \
	--dkmstree %{buildroot}/var/lib/dkms
dkms build            -m %{kmod_name} -v %{kmod_ver} -c dkms.conf \
	--dkmstree %{buildroot}/var/lib/dkms
dkms install-fakeroot -m %{kmod_name} -v %{kmod_ver} -c dkms.conf \
	--dkmstree %{buildroot}/var/lib/dkms \
	--installtree %{buildroot}/lib/modules

find %{buildroot}/lib/modules/%{kversion} -name "*.ko" | \
	sed -e "s|%{buildroot}||" > kmod.filelist

rm -rf %{buildroot}/var


%post -n kmod-%{kmod_name}%{?kflavor:-%{kflavor}}
/sbin/depmod -a -F /boot/System.map-%{kversion} %{kversion}


%files -n kmod-%{kmod_name}%{?kflavor:-%{kflavor}} -f kmod.filelist
%defattr(-,root,root,0744)


%changelog
* Sun Apr 26 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org>
- initial kmp spec file
