%define	hg_src	c44e16dbb0e2

Summary:	Digital terrestrial television recording tool for linux
Summary(ja): 	地上波デジタルテレビ放送の Linux 用録画ツール
Name:		recfriio
Version:	r4
Release: 	4%{?_dist_release}
Source0:	http://2sen.dip.jp/cgi-bin/friioup/source/up0777.zip
Source1:	http://2sen.dip.jp/cgi-bin/hdusup/source/up0127.zip
Source2:	http://2sen.dip.jp/cgi-bin/hdusup/source/up0257.zip
# Download URL: http://hg.honeyplanet.jp/pt1/archive/%{hg_src}.tar.bz2
Source3:	pt1-%{hg_src}.tar.bz2
Patch0:		recfriior4-fix-compile.patch
Patch1:		b25-0.2.4-Makefile.patch
License:	distributable/BSD (see README files for detail)
Group:		Applications/Multimedia
#URL:		

#Requires:	
BuildRequires:	libboost-devel, libboost-thread, libboost-filesystem
BuildRequires:	pcsc-lite-devel
BuildRequires:	unzip
BuildRequires:	glib2-devel, libusb-devel

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

Packager:	kazutaka


%description
Set of command line tools to record digital terrestrial television
for linux.
It supports friio (digital terrestrial television and BS/CS) and
MonsterTV HDUS series (*Not suppot all models).

For HDUS uses, you should copy the firmware(SKNET_AS11Loader.sys)
to %{_libdir}/hdus and then udev automatically load it when device 
is found.

%description -l ja
地上波デジタルテレビ放送を録画する為の、Linux 用のコマンドライン
ツールです。
friio (地上波デジタル用及びBS/CS用)と MonsterTV HDUS シリーズ
(*一部の対応機種のみ)に対応しています。

尚、HDUS で利用する場合はファームウェア(SKNET_AS11Loader.sys)
を %{_libdir}/hdus に置いておくと、udev 経由で自動的に読み込まれ
ます。

#------------------------------------------------------------------------------

%package -n b25
Summary:	Digital terrestrial television stream decryption tool
Summary(ja): 	地上波デジタルテレビ放送の複合用ツール

License:	distributable
Group:		Applications/Multimedia
URL:		http://hg.honeyplanet.jp/pt1
Conflicts:	recfriio <= r4-2%{?_dist_release}

%description -n b25
b25 is a command line tool for linux to decrypt MPEG2-TS stream
recorded by digital terrestrial television recorder, such as
friio, pt1 and HDUS.

%description -n b25 -l ja
friio や pt1、HDUS 等の、PC 用の地上波デジタルテレビ放送の
受信機で録画した、暗号化されているMPEG2-TS ストリームを復号化
する為の、Linux 用のコマンドラインツールです。

#------------------------------------------------------------------------------

%package -n b25-devel
Summary:	Development file for b25
Summary(ja):	b25 用の開発ファイル
Group:		Development/Libraries
Requires:	b25 = %{version}-%{release}

%description -n b25-devel
This package contains the libraries and header files for b25. 

%description -n b25-devel -l ja
このパッケージには b25 を操作するためのライブラリとヘッダが
含まれています。

#------------------------------------------------------------------------------

%prep
%setup -q -n %{name}%{version} -a 1 -a 2 -a 3

pushd recfriior4
patch -p1 < ../hdus-recfriior4/recfriior4.diff
patch -p1 < ../recfriio-newpatch/recfriior4-newhdus.patch

# apply patch to fix recfriio compilation error on Vine Linux
%patch0 -p2
popd

pushd pt1-%{hg_src}
%patch1 -p1 -b .
popd

# remove old b25 directory and create sym link to point newer one
%{__rm} -rf arib25v021/arib25
pushd arib25v021
%{__ln_s} ../pt1-%{hg_src}/arib25 arib25
popd

%build
pushd pt1-%{hg_src}/arib25
%{__make}
popd

pushd recfriior4
%{__make}
popd

pushd hdus-recfriior4/as11loader/
%{__make}
popd


%install
%{__rm} -rf ${RPM_BUILD_ROOT}
%{__install} -D -m 755 recfriior4/%{name} ${RPM_BUILD_ROOT}/%{_bindir}/%{name}
%{__install} -D -m 755 hdus-recfriior4/as11loader/as11loader ${RPM_BUILD_ROOT}/%{_libdir}/hdus/as11loader

# install b25 and libarib25.so
pushd pt1-%{hg_src}/arib25
%{__make} install DESTDIR=$RPM_BUILD_ROOT PREFIX=%{_prefix} LIBDIR=%{_libdir}
popd

# setup udev rule for permission and hdus firmware
%{__install} -d ${RPM_BUILD_ROOT}/%{_sysconfdir}/udev/rules.d/

%{__cat} << EOF > ${RPM_BUILD_ROOT}/%{_sysconfdir}/udev/rules.d/99-recfriio.rules
# set permission and group: friio
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \
	ATTRS{idVendor}=="7a69", ATTRS{idProduct}=="0001", \
	MODE="0664", GROUP="video"

# set permission and group: HDUS
SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \
	ATTRS{idVendor}=="3275", ATTRS{idProduct}=="6051", \
	MODE="0664", GROUP="video"

# load the firmware of HDUS
SUBSYSTEM=="usb", ACTION=="add", \
	ATTRS{idVendor}=="1738", ATTRS{idProduct}=="5211", \
	RUN+="/bin/sh -c 'cd %{_libdir}/hdus; ./as11loader'"
EOF

# add documents
%{__install} -d ${RPM_BUILD_ROOT}/%{_defaultdocdir}/%{name}-%{version}
%{__cp} -p recfriior4/readme.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/%{name}-%{version}/README_up0777.zip.recfriior4
%{__cp} -p hdus-recfriior4/README.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/%{name}-%{version}/README_up0127.zip.hdus-recfriior4
%{__cp} -p recfriio-newpatch/README.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/%{name}-%{version}/README_up0257.zip.recfriio-newpatch

%{__install} -d ${RPM_BUILD_ROOT}/%{_defaultdocdir}/b25
%{__cp} -p pt1-%{hg_src}/arib25/readme.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/b25/README.b25
%{__cp} -p pt1-%{hg_src}/b25_docs/readme.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/b25/README.b25-for-linux
%{__cp} -p pt1-%{hg_src}/b25_docs/libccid_Info.plist ${RPM_BUILD_ROOT}/%{_defaultdocdir}/b25
%{__cp} -p pt1-%{hg_src}/b25_docs/smartcard_list.txt ${RPM_BUILD_ROOT}/%{_defaultdocdir}/b25


%clean
%{__rm} -rf ${RPM_BUILD_ROOT}


%files
%defattr(-,root,root)
%doc %{_defaultdocdir}/%{name}-%{version}
%{_bindir}/%{name}
%{_libdir}/hdus/as11loader
%{_sysconfdir}/udev/rules.d/99-recfriio.rules

%files -n b25
%defattr(-,root,root)
%doc %{_defaultdocdir}/b25
%{_bindir}/b25
%{_libdir}/libarib25.so.*

%files -n b25-devel
%defattr(-,root,root)
%{_includedir}/arib25/*.h
%{_libdir}/libarib25.so


%changelog
* Sat Jan 09 2010 Kazutaka HARADA <kazutaka@vinelinux.org> r4-4
- modify b25-0.2.4-Makefile.patch for x86_64

* Wed Dec 30 2009 Kazutaka HARADA <kazutaka@vinelinux.org> r4-3
- add Source3 for updated/modified b25 sources from pt1 project
- add Patch1 to build rpm packages for newer b25
- add b25, b25-devel subpackage whth libarib25.so* libraries 

* Wed Dec 23 2009 Kazutaka HARADA <kazutaka@vinelinux.org> r4-2
- add BuildRequires: glib2-devel, libusb-devel

* Thu Nov 05 2009 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> r4-1
- initial build for Vine Linux

