%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	ndiswrapper
%define ver	1.56
%define rel	1%{?_dist_release}

Summary:        Utilities to load and run Windows XP WLAN drivers
Summary(ja):    Windows XP 用無線 LAN ドライバを利用する為の補助ツール群
Name:		%{name}
Version:	%{ver}
Release: 	%{rel}
Source0:	%{name}-%{version}.tar.gz
Source10:	%{name}-kmp.spec
Patch0:		%{name}-1.19-gcc33.patch
Patch1:		%{name}-1.54-module-init-tools.patch
Patch2:		%{name}-1.55-2.6.31.patch
Patch3:		%{name}-2.6.35.patch
License:	GPL
Group:		System Environment/Base
URL:            http://ndiswrapper.sourceforge.net/

BuildRequires:	kernel-devel

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


%description
Some wireless LAN vendors refuse to release hardware specifications or
drivers for their products for operating systems other than Microsoft
Windows. This package includes user space tool to load and run Windows
XP drivers for wireless cards.

%description -l ja
いくつかの無線 LAN カードのベンダーは、製品の仕様を公開しておらず、
Microsoft Windows 以外の OS 用のドライバを提供していません。
このパッケージは Windows XP 用のドライバを Linux で利用する為の、
ツールを含んでいます。


%package -n dkms-%{name}
Summary:         Linux kernel module to load and run Windows XP WLAN drivers
Summary(ja):     Windows XP 用無線 LAN ドライバを利用する為の Linux カーネルモジュール
License:         GPL
Group:           System Environment/Kernel
Requires(pre):   kernel, kernel-devel
Requires(post):	 dkms
Requires(preun): dkms
Requires:        %{name} = %{version}-%{release}
Obsoletes:       kernel-module-ndiswrapper

%description -n dkms-%{name}
Some wireless LAN vendors refuse to release hardware specifications or
drivers for their products for operating systems other than Microsoft
Windows. This package includes Linux kernel module to load and run 
Windows XP drivers for wireless cards.

%description -l ja -n dkms-%{name}
いくつかの無線 LAN カードのベンダーは、製品の仕様を公開しておらず、
Microsoft Windows 以外の OS 用のドライバを提供していません。
このパッケージは Windows XP 用のドライバを Linux で利用する為の、
カーネルモジュールを含んでいます。


%prep
%setup -q
%patch0 -p1
#%patch1 -p1
#%patch2 -p1
%patch3 -p0

%build
%__make -C utils


%install
%__rm -rf %{buildroot}
%__make -C utils install DESTDIR=%{buildroot}

mkdir -p -m 0755 %{buildroot}%{_mandir}/man8
install -m 644 ndiswrapper.8 %{buildroot}%{_mandir}/man8/
install -m 644 loadndisdriver.8 %{buildroot}%{_mandir}/man8/

mkdir -p %{buildroot}/usr/src/%{name}-%{version}-%{release}
cp -a driver/* %{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}"

# Items below here should not have to change with each driver version
MAKE[0]="make KVERS=\${kernelver} -C \${dkms_tree}/\${PACKAGE_NAME}/\${PACKAGE_VERSION}/build"
CLEAN="make -C \${kernel_source_dir} SUBDIRS=\${dkms_tree}/\${PACKAGE_NAME}/\${PACKAGE_VERSION}/build clean"

BUILT_MODULE_NAME[0]="\$PACKAGE_NAME"
DEST_MODULE_LOCATION[0]="/extra/ndiswrapper"
#MODULES_CONF_ALIAS_TYPE[0]="eth"

REMAKE_INITRD="no"
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
if [ -f /etc/modprobe.d/ndiswrapper ]; then
  mv /etc/modprobe.d/ndiswapper /etc/modprobe.d/ndiswapper.conf
fi

%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
%defattr(-,root,root)
%doc README AUTHORS ChangeLog INSTALL
%{_syssbindir}/loadndisdriver
%{_sbindir}/ndiswrapper*
%{_mandir}/man8/ndiswrapper*
%{_mandir}/man8/loadndisdriver*


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


%changelog
* Wed Aug 18 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.56-1
- updated to 1.56
- drop Patch1 and Patch2; add Patch3: fix build on kernel >= 2.6.35

* Fri Sep 25 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.55-1
- updated to 1.55, fixing compilation issues with recent kernels
- add Patch2: fix one more compilation issue with kernel-2.6.31

* Tue May 12 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.54-4
- add Patch1: change modprobe conf name to ndiswrapper.conf

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

* Thu Apr  9 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.54-2
- drop kernel-module-ndiswrapper subpackage; make DKMS-compatible

* Tue Jan 28 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.54-1
- new upstream release
- add kflavor(pae,smp..) to package name

* Thu Dec 11 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 1.53-1
- new upstream release
- add Patch1 to build for kernel 2.6.27

* Wed Mar 26 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 1.52-1
- new upstream release

* Wed Dec 05 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.50-0vl1
- new upstream release

* Tue Oct 30 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.49-0vl1
- new upstream release

* Mon Oct 22 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.48-0vl1
- new upstream release

* Sat Jun 09 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.46-0vl1
- new upstream rekease

* Fri May 11 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 1.43-0vl1
- new upstream release

* Thu Oct 26 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.27-0vl1
- new upstream release

* Fri Oct 06 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.25-0vl1
- new upstream release

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

* Wed Aug 30 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.23-0vl1
- new upstream release

* Sun Aug 06 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.22-0vl1
- new upstream release

* Tue Jul 18 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.21-0vl2
- run depmod for target kernel version
- add PreReq: kernel >= %%{kversion}
  (we need System.map to run depmod in %%post script)

* Tue Jul 18 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.21-0vl1
- new upstream release

* Sat Jul 15 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.19-0vl1
- split kernel module to kernel-module-ndiswrapper subpackage
  to allow duplicated packages.
- change Group to System Environment/Base for utils,
  System Environment/Kernel for kernel modules.
- new upstream release

* Thu May 04 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.15-0vl1
- new upstream release

* Sat Apr 24 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.14-0vl1
- new upstream release

* Tue Apr 04 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.11-0vl1
- new upstream release
- change Group to System Enviroment/Libraries.

* Mon Mar 20 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 1.10-0vl1
- new upstream release
- add mandir to make install option
- call depmod in %%post script

* Sat Feb 04 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.9-0vl1
- source update.

* Thu Feb 02 2006 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.8-0vl1
- source update.

* Sun Dec 18 2005 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.7-0vl1
- source update.

* Sat Nov 19 2005 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.5-0vl1
- source update.

* Sun Oct 08 2005 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.4-0vl1
- source update.
- use '%%__make install' instead of %%maikeinstall macro.

* Tue Aug 02 2005 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.2-0vl2
- Delete unnecessary echo (only used for packaging test).

* Thu Jul 29 2005 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 1.2-0vl1
- initial build for VineSeed Plus.
