%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	rt2860
%define ver	2.4.0.0
%define rel	2%{?_dist_release}

%define tgzname 2010_07_16_RT2860_Linux_STA_v%{ver}

Summary:        Linux kernel module for Ralink RT2860 WiFi adapters
Summary(ja):    Ralink RT2860 WiFi アダプタ用のカーネルモジュール
Name:		%{name}
Version:	%{ver}
Release: 	%{rel}
# $ file 2010_07_16_RT2860_Linux_STA_v2.4.0.0.tar.bz2
# 2010_07_16_RT2860_Linux_STA_v2.4.0.0.tar.bz2: gzip compressed data, from Unix, last modified: Thu Jul 15 20:09:16 2010
# so, repacked %{tgzname}.tar.bz2
Source0:	%{tgzname}.tar.bz2
Source10:	%{name}-kmp.spec
Patch0:		%{tgzname}-NetworkManager-support.patch
License:	GPLv2+
Group:		System Environment/Base
URL:            http://www.ralinktech.com/support.php?s=2

BuildRequires:	kernel-devel

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


%description
This package contains the rt2860 driver for Ralink RT2860 WiFi adapters. 

%description -l ja
このパッケージには、Ralink RT2860 無線LANアダプタ用ドライバである
rt2860 カーネルモジュールが収録されています。


%package -n dkms-%{name}
Summary:         Linux kernel module for Ralink RT2860 WiFi adapters
Summary(ja):     Ralink RT2860 WiFi アダプタ用のカーネルモジュール
License:         GPLv2+
Group:           System Environment/Kernel
Requires(pre):   kernel, kernel-devel
#Requires(pre):   rt2860-firmware
Requires(pre):   linux-firmware >= 20110601
Requires(post):	 dkms
Requires(preun): dkms

%description -n dkms-%{name}
This package contains the rt2860 driver for Ralink RT2860 WiFi adapters. 

%description -l ja -n dkms-%{name}
このパッケージには、Ralink RT2860 無線LANアダプタ用ドライバである
rt2860 カーネルモジュールが収録されています。


%prep
%setup -q -n %{tgzname}
%patch0 -p1 -b .mn

## fix permission
find . -type f -print0 | xargs -0 chmod 644

%install
%__rm -rf %{buildroot}
%__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}"

MAKE[0]="make LINUX_SRC=\$kernel_source_dir HAS_WPA_SUPPLICANT=y HAS_NATIVE_WPA_SUPPLICANT_SUPPORT=y"

BUILT_MODULE_NAME[0]="%{name}sta"
BUILT_MODULE_LOCATION[0]="os/linux"
DEST_MODULE_LOCATION[0]="/kernel/3rdparty/%{name}"

AUTOINSTALL="yes"
EOF

%__mkdir_p %{buildroot}%{_sysconfdir}/Wireless/RT2860STA
%__install -m 644 RT2860STA.dat %{buildroot}%{_sysconfdir}/Wireless/RT2860STA

## 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}
dkms add     -m %{name} -v %{version}-%{release} --rpm_safe_upgrade
dkms mkkmp   -m %{name} -v %{version}-%{release}
dkms build   -m %{name} -v %{version}-%{release} --rpm_safe_upgrade
dkms install -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --force
exit 0

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


%files -n dkms-%{name}
%defattr(-,root,root)
%doc README_STA *.txt
%{_sysconfdir}/Wireless
%dir /usr/src/%{name}-%{version}-%{release}
/usr/src/%{name}-%{version}-%{release}/*


%changelog
* Sat Jul 02 2011 Munehiro Yamamoto <munepi@vinelinux.org> - 2.4.0.0-2
- dropped Requires(pre): rt2860-firmware
- added Requires(pre):   linux-firmware >= 20110601

* Sat Jan 01 2010 Munehiro Yamamoto <munepi@vinelinux.org> - 2.4.0.0-1
- initial package for Vine Linux
