%define pkgname broadcom-wl
%define name    self-build-%{pkgname}

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

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

%ifarch %{ix86}
%define source0path %{downloadurl}/hybrid-v35-nodebug-pcoem-%{over}.tar.gz
%endif
%ifarch x86_64
%define source0path %{downloadurl}/hybrid-v35_64-nodebug-pcoem-%{over}.tar.gz
%endif

Summary:	Package to automatically build %{pkgname} rpm package
Summary(ja): 	%{pkgname} の rpm パッケージを自動作成するパッケージ
Name:		%{name}
Version:	6.30.223.271
Release: 	3%{?_dist_release}
Source0:	%{pkgname}-vl.spec
Source1:	blacklist-broadcom.conf

Source100:	broadcom-wl-kernel318.patch
# Patches from Debian-sid
Source101:	14-rdtscl.patch
Source102:	15-linux47.patch
Source103:	16-linux48.patch
Source104:	17-fix-kernel-warnings.patch
Source105:	18-linux411.patch
Source106:	19-linux412.patch

License:	Freeware and GPLv2 with exception
Group:		Restricted Software

Requires(pre):	self-build-setup >= 0.7-1

BuildRoot:	%{_tmppath}/%{name}-%{version}-root
ExclusiveArch:	%{ix86} x86_64


%description
Proprietary hybrid driver for Broadcom wireless adapters.

If you install this package, it automaticaly downloads source
code ,compile it, and create rpm packages of %{pkgname}-%{version}.
And the created rpm packages are automatically installed
if installation is executed by apt-get command or synaptic
package manager.

[Note]
This package requires many other packages to compile
targetsoftware. So it consume more disk space than usual.
Also installation takes logner time because of compilation.
(This will take a few minutes to quarter or half of an hour,
depends on building environment)

[About self-build package]
For some kind of software, distributing of binary package
may viorate the patent or law. Therefore we chose self-build
packge, create binary package on your machine, for such kind
of softwares instead of distributing binary package.

Please obey the national law when you use the created binary
packages. And if you want to use the softwares using patented 
thechnology, it may be required to get a permission, make an 
agreement or purchas a license. Please consider it with your
purpose or way of use and take appropriate action.

%description -l ja
Broadcom ワイヤレスアダプタ用のプロプライエタリドライバです。

このパッケージをインストールすると、自動的にソースコードを
ダウンロードしてコンパイルし、%{pkgname}-%{version}
の rpm パッケージを作成します。
また apt-get コマンドや synaptic パッケージマネージャから実行
した場合は、作成された rpm パッケージのインストールも自動的に
行います。

[注意]
コンパイルに必要な多くの関連パッケージを要求するので通常より
ディスクの領域を多く消費します。
またインストール時にコンパイルを行うため、通常より時間がかか
る場合があります。(環境にもよりますが数分から数十分程度)

[self-build パッケージについて]
ソフトウェアによってはバイナリパッケージの配布が特許や法律に
違反する可能性があるものがあります。その為、このような問題が
懸念されるソフトウェアについてはバイナリパッケージを直接配布
せずに、ユーザの環境でバイナリを作成する self-build パッケー
ジという方法を採っています。

作成されたバイナリパッケージの利用にあたっては、各ソフトウェ
アのライセンス、および利用する国の各種法令に従ってください。
また特許に関連するソフトウェアの場合、利用許諾や契約、ライ
センスの購入などが必要となる場合がありますので、利用する目的
や形態に応じて各自で判断し適切な対応を取ってください。


%install
rm -rf %{buildroot}
install -d %{buildroot}%{_datadir}/%{name}
install -m 644 %{SOURCE1} %{buildroot}%{_datadir}/%{name}
#install -m 644 %{SOURCE2} %{buildroot}%{_datadir}/%{name}
sed -e 's|##VERSION##|%{version}|g' -e 's|##RELEASE##|%{release}|g' \
	%{SOURCE0} > %{buildroot}%{_datadir}/%{name}/%{pkgname}-vl.spec

# %{__install} -m 644 %{SOURCE100} \
# 	     $RPM_BUILD_ROOT/%{_datadir}/%{name}
%{__install} -m 644 \
 %{SOURCE101} %{SOURCE102} %{SOURCE103} \
 %{SOURCE104} %{SOURCE105} %{SOURCE106} \
 $RPM_BUILD_ROOT/%{_datadir}/%{name}


%clean
rm -rf %{buildroot}


%posttrans
/usr/lib/rpm/self-build-rpm.sh %{name} %{pkgname}-vl.spec "%{source0path}"
/usr/lib/rpm/pre-allocate-rpm.sh dkms-%{pkgname}-%{version}-%{release}


%files
%defattr(-,root,root)
%{_datadir}/%{name}/*


%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
- new upstream release.
- dropped SOURCE100.
- fixed date of changelog.

* 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 01 2012 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 5.100.82.112-1
- new upstream release.
- dropped an old patch.
- added SOURCE2 to compile for kernel-3.2.x.

* Tue Oct  4 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.100.82.38-3
- update SOURCE1 (see: http://www.broadcom.com/docs/linux_sta/bcma.txt)

* Sun Aug 14 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.100.82.38-2
- add a patch to fix build failure on linux > 2.6.37

* Sat Jan 01 2011 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.100.82.38-1
- new upstream release

* Tue Aug 17 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.60.48.36-2
- add Source2 to fix build failure on kernel >= 2.6.35
  (https://bugs.launchpad.net/ubuntu/+source/bcmwl/+bug/590924)

* Tue Aug 17 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.60.48.36-1
- new upstream release

* Wed Sep 23 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.10.91.9.3-1
- new upstream release

* Tue May 05 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.10.91.9-3
- fix to ensure Source0 has correct version/release numbers

* Tue May 05 2009 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 5.10.91.9-2
- add ExclusiveArch

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