%define oname	hybrid-portsrc
%define over	%(echo %{version} | tr . _)
%define kname	wl

%define downloadurl https://docs.broadcom.com/docs-and-downloads/docs/linux_sta

Summary:	Proprietary driver for Broadcom wireless adapters
Summary(ja): 	Broadcom ワイヤレスドライバ用プロプライエタリドライバ
Name:		broadcom-wl
Version:	##VERSION##
Release: 	##RELEASE##

License:	Freeware and GPLv2 with exception
Group:		System Environment/Kernel
URL:		http://www.broadcom.com/support/802.11/linux_sta.php

%ifarch %{ix86}
# Source0:	http://www.broadcom.com/docs/linux_sta/hybrid-v35-nodebug-pcoem-%{over}.tar.gz
Source0:	%{downloadurl}/hybrid-v35-nodebug-pcoem-%{over}.tar.gz
%endif
%ifarch x86_64
# Source0:	http://www.broadcom.com/docs/linux_sta/hybrid-v35_64-nodebug-pcoem-%{over}.tar.
Source0:	%{downloadurl}/hybrid-v35_64-nodebug-pcoem-%{over}.tar.gz
%endif
Source1:	blacklist-broadcom.conf

#Patch100:	broadcom-wl-kernel318.patch
# Patches from Debian-sid
Patch101:	14-rdtscl.patch
Patch102:	15-linux47.patch
Patch103:	16-linux48.patch
Patch104:	17-fix-kernel-warnings.patch
Patch105:	18-linux411.patch
Patch106:	19-linux412.patch

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

%description
This package contains the proprietary driver for Broadcom wireless adapters
provided by Broadcom. If installed, it will be used for these cards in
preference to the third-party open source driver that requires manual
installation of firmware, or ndiswrapper.

%description -l ja
このパッケージには、Broadcom ワイヤレスアダプタ用のプロプライエタリドライバが
収録されています。ファームウェアのインストールを手で行わなければいけない
オープンソースドライバや ndiswrapper とは異なり、この Broadcom 社製の
ハイブリッドドライバは単体で動作します。


%package -n dkms-%{name}
Summary:	 Hybrid kernel module f-r Broadcom wireless adapters
Summary(ja):	 Broadcom ワイヤレスドライバ用ハイブリッドカーネルモジュール
Group:		 System Environment/Kernel
Requires(post):	 dkms
Requires(preun): dkms

%description -n dkms-%{name}
This package contains the proprietary driver for Broadcom wireless adapters
provided by Broadcom. If installed, it will be used for these cards in
preference to the third-party open source driver that requires manual
installation of firmware, or ndiswrapper.

%description -n dkms-%{name} -l ja
このパッケージには、Broadcom ワイヤレスアダプタ用のプロプライエタリドライバが
収録されています。ファームウェアのインストールを手で行わなければいけない
オープンソースドライバや ndiswrapper とは異なり、この Broadcom 社製の
ハイブリッドドライバは単体で動作します。


%prep
%setup -q -T -c -a0
#%patch100 -p0 -b .kernel318
%patch101 -p2 -b .rdtscl
%patch102 -p2 -b .linux47
%patch103 -p2 -b .linux48
%patch104 -p2 -b .fix-kernel-warnings
%patch105 -p2 -b .linux411
%patch106 -p2 -b .linux412

%install
%{__rm} -rf %{buildroot}

## DKMS ##
mkdir -p %{buildroot}%{_usr}/src/%{name}-%{version}-%{release}
cp -R * %{buildroot}%{_usr}/src/%{name}-%{version}-%{release}/
cat > %{buildroot}%{_usr}/src/%{name}-%{version}-%{release}/dkms.conf << EOF
PACKAGE_NAME=%{name}
PACKAGE_VERSION=%{version}-%{release}

BUILT_MODULE_NAME[0]="%{kname}"
BUILT_MODULE_LOCATION[0]="."
DEST_MODULE_LOCATION[0]="/kernel/drivers/net/wireless"

MAKE[0]="make"
CLEAN="make clean"

AUTOINSTALL="yes"
EOF

## BLACKLIST ##
mkdir -p %{buildroot}/etc/modprobe.d
install -m 644 %{SOURCE1} %{buildroot}/etc/modprobe.d/


%clean
%{__rm} -rf %{buildroot}


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

%preun -n dkms-%{name}
dkms remove  -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --all || :


%files -n dkms-%{name}
%defattr(-,root,root)
%doc lib/LICENSE.txt
%dir /usr/src/%{name}-%{version}-%{release}
/usr/src/%{name}-%{version}-%{release}/*
/etc/modprobe.d/blacklist-broadcom.conf


%changelog
* Tue Dec 05 2017 Toshiaki Ara <ara_t@384.jp> 6.30.223.271-3
- add patches for build with kernel 4.12

* Wed Nov 22 2017 Toshiaki Ara <ara_t@384.jp> 6.30.223.271-2
- change download URL

* Sat Oct 31 2015 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 6.30.223.271-1
- dropped patch100.
- new upstream release.

* Sun Aug  2 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 6.30.223.248-2
- added Source100 to build with kernel 3.18

* Wed Nov 19 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 6.30.223.248-1
- new upstream release
- dropped SOURCE2
- updated dmks.conf

* Tue May 05 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 5.10.91.9-1
- initial build for Vine Linux
