#%define origsnapdate 2011-05-01
#%define snapdate %(echo %origsnapdate | sed -e 's/-//g')

%define origsrcver 2.6.38.2-2
%define srcver %(echo %origsrcver | sed -e 's/-/_/g')

%define build_kmod %{?_with_kmod:1}%{!?_with_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	compat-wireless
#%define ver	0.%{snapdate}
%define ver	%{srcver}
%define rel	1%{?_dist_release}

Summary:        Collection of recent wireless drivers backported
Name:		%{name}
Version:	%{ver}
Release: 	%{rel}
#Source0:	http://wireless.kernel.org/download/compat-wireless-2.6/%{name}-%{origsnapdate}.tar.bz2
Source0:	http://www.orbit-lab.org/kernel/compat-wireless-2.6-stable/v2.6.38/%{name}-%{origsrcver}.tar.bz2

License:	GPLv2+
Group:		System Environment/Base
URL:            http://wireless.kernel.org/
Vendor:         Project Vine
Distribution:   Vine Linux

BuildRequires:	kernel-devel >= 2.6.35
BuildRoot:	%{_tmppath}/%{name}-%{version}-root


%description
This package contains utilities for the latest Linux wireless drivers
backported to kernel >= 2.6.35.

%description -l ja
このパッケージには、kernel >= 2.6.35 用にバックポートされた
最新の Linux 無線 LAN デバイスドライバ用のツールが収録されています。


%package -n %{kmod}-%{name}
Summary:        Collection of recent wireless drivers backported
Version:	%{ver}_%{kver}
License:	BSD or GPL
Group:		System Environment/Kernel
Requires:	%{name} >= %{ver}-%{release}
Requires(pre):	kernel = %{kversion}

%description -n %{kmod}-%{name}
This package contains the latest Linux wireless drivers
backpoted to kernel >= 2.6.35.

This package is built explicitly for kernel-%{kversion}.

%description -l ja -n %{kmod}-%{name}
このパッケージには、kernel >= 2.6.35 用にバックポートされた
最新の Linux 無線 LAN デバイスドライバ群が収録されています。

このパッケージは kernel-%{kversion} 用に作成されています。


%prep
%setup -q -n %{name}-%{origsrcver}


%build
%if %{build_kmod}
%__make
%endif


%install
%__rm -rf %{buildroot}

%if %{build_kmod}
%__make -C /lib/modules/%{kversion}/build \
	INSTALL_MOD_PATH=%{buildroot} \
	M=`pwd` \
	modules_install
# remove unusable module
%{__rm} -rf %{buildroot}/lib/modules/%{kversion}/extra/drivers/net/wireless/wl1251/wl1251_sdio.ko
%else
%__install -d %{buildroot}%{_libdir}/compat-wireless
%__install -d %{buildroot}%{_sbindir}
%__install scripts/modlib.sh      %{buildroot}%{_libdir}/compat-wireless/
%__install scripts/madwifi-unload %{buildroot}%{_sbindir}/
%__install scripts/athenable      %{buildroot}%{_sbindir}/
%__install scripts/b43enable      %{buildroot}%{_sbindir}/
%__install scripts/iwl-enable     %{buildroot}%{_sbindir}/
%__install scripts/athload        %{buildroot}%{_sbindir}/
%__install scripts/b43load        %{buildroot}%{_sbindir}/
%__install scripts/iwl-load       %{buildroot}%{_sbindir}/
%endif


%clean
%__rm -rf ${RPM_BUILD_ROOT}


%post -n %{kmod}-%{name}
/sbin/depmod -a -F /boot/System.map-%{kversion} %{kversion}


%if ! %{build_kmod}
%files
%defattr(-,root,root)
%doc COPYRIGHT README
%{_sbindir}/*
%{_libdir}/compat-wireless/*
%else
%files -n %{kmod}-%{name}
/lib/modules/%{kversion}/extra/*
%endif


%changelog
* Sat May 21 2011 Kazutaka HARADA <kazutaka@vinelinux.org> 2.6.38.2_2-1
- new upstream release
- remove unusable moudule (wl1251_sdio.ko)

* Sat Feb 13 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20100212-1
- updated to 2010-02-12

* Thu Oct  8 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20091008-1
- updated to 2009-10-05

* Thu Jul  2 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20090630-2
- add Patch0 to boost build time
  (see: http://osdir.com/ml/linux-wireless/2009-06/msg00875.html)

* Thu Jul  2 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20090630-1
- updated to 2009-06-30

* Sat May  2 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20090502-1
- updated to 2009-05-02

* Wed Mar 25 2009 Shu KONNO <owa@bg.wakwak.com> 0.20090325-1
- updated to 2009-03-25

* Sun Mar 15 2009 Shu KONNO <owa@bg.wakwak.com> 0.20090314-1
- new upstream release

* Fri Mar  6 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 0.20090305-1
- initial package for Vine Linux
