%global gpac_postinstall     \
    gpac_postinstall_sh=$(mktemp) ; \
    rpm -q --scripts self-build-gpac | \
    /bin/sed -e 's|posttrans[[:blank:]].*|\#!/bin/bash|' > ${gpac_postinstall_sh} ; \
    /bin/bash ${gpac_postinstall_sh} ; /bin/rm -f ${gpac_postinstall_sh}

%global x264_postinstall     \
    x264_postinstall_sh=$(mktemp) ; \
    rpm -q --scripts self-build-x264 | \
    /bin/sed -e 's|posttrans[[:blank:]].*|\#!/bin/bash|' > ${x264_postinstall_sh} ; \
    /bin/bash ${x264_postinstall_sh} ; /bin/rm -f ${x264_postinstall_sh}


%global pkgname ffmpeg
%global name	self-build-%{pkgname}
%global major_version 2.6
%global version %{major_version}
#% define svndate	20110326
%global release	1%{?svndate:.%svndate}%{?_dist_release}

%global sourceurl0	http://ffmpeg.org/releases/%{pkgname}-%{?svndate:%svndate}%{!?svndate:%version}.tar.bz2

%global with_faac 1
%global with_vaapi 1
%global with_libvpx 1

#% define enable_avconv 1

Summary:	Package to automatically build %{pkgname} rpm package
Summary(ja): 	%{pkgname} の rpm パッケージを自動作成するパッケージ
Name:		%{name}
Version:	%{version}
Release: 	%{release}
Source0:	%{pkgname}-vl.spec
#Source1:	%{pkgname}-%{?svndate:%svndate}%{!?svndate:%version}.tar.bz2

License:	GPLv2+
Group:		Restricted Software

Obsoletes:      ffmpeg < %{major_version}, ffmpeg-libs < %{major_version}, ffmpeg-devel < %{major_version}
Obsoletes:      self-build-ffmpeg < %{version}

Requires(post):		self-build-setup >= 0.9.9
#Requires(post):		subversion

# (build)requies of target package.
Requires(post):  bzip2-devel
Requires(post):  celt-devel
##Requires(post):  dirac-devel
Requires(post):  freetype2-devel
Requires(post):  gnutls-devel
Requires(post):	gsm-devel
Requires(post):	imlib2-devel
Requires(post):	libdc1394-devel
Requires(post):	libogg-devel
Requires(post):  libass-devel
%{!?_without_cdio:Requires(post): libcdio-devel}
%{!?_without_cdio:Requires: libcdio-paranoia-devel}
#libcrystalhd is currently broken
%{?_with_crystalhd:Requires(post):	libcrystalhd-devel}
Requires(post):	libraw1394-devel
Requires(post):	librtmp-devel >= 2.3
Requires(post):	libtheora-devel
%{?with_vaapi:Requires(post):	libva-devel >= 0.31.0}
Requires(post):  libvdpau-devel
Requires(post):	libvorbis-devel
%{?with_libvpx:Requires(post):  libvpx-devel >= 0.9.7}
Requires(post):  libXvMC-devel
%{?_with_opencore_amr:Requires(post):  opencore-amr-devel vo-amrwbenc-devel}
%{!?_without_openal:Requires(post):  openal-soft-devel}
%{?_with_opencv:Requires(post):  opencv-devel}
%{?_with_openjpeg:Requires(post):  openjpeg-devel}
##Requires(post):  schroedinger-devel
Requires(post):	SDL-devel
Requires(post):  speex-devel
##Requires(post):	texi2html
Requires(post):	zlib-devel 
Requires(post):	libogg-devel
Requires(post):		yasm
Requires(post):		self-build-a52dec
Requires(post):		self-build-faac
Requires(post):		self-build-faad2
Requires(post):		self-build-lame 
Requires(post):		self-build-libdca
Requires(post):		self-build-x264 >= 0.142
Requires(post):		self-build-x265 >= 1.4
Requires(post):		self-build-xvidcore

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

BuildArch:	noarch
Packager:	munepi

%description
FFMpeg is a complete and free Internet live audio and video
broadcasting solution for Linux/Unix. It also includes a 
digital VCR. It can encode in real time in many formats 
including MPEG1 audio and video, MPEG4, h263, ac3, asf, avi,
real, mjpeg, and flash.

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
target software. So it consume more disk space than usual.
Also installation takes longer 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
FFMpeg は Linux/Unix に対する完全にフリーなインターネットライ
ブオーティオ・ビデオブロードキャスティングソリューションです.
またデジタル VCR を含んでいます.MPEG1 オーディオ・ビデオ,
MPEG4, h263, ac3, asf, avi, real, mjpeg, flash を含む
多様なフォーマットをリアルタイムにエンコードすることができます.

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

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

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

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

%prep
[ "%{version}-%{release}" != $(rpm -q --queryformat "%%{version}-%%{release}\n" --specfile %{SOURCE0} | tail -1) ] && exit 1

%install
%{__rm} -rf ${RPM_BUILD_ROOT}
%{__install} -d ${RPM_BUILD_ROOT}/%{_datadir}/%{name}
%{__install} -m 644 %{SOURCE0} ${RPM_BUILD_ROOT}/%{_datadir}/%{name}

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

%posttrans
/usr/lib/rpm/self-build-rpm.sh %{name} %{pkgname}-vl.spec "%{sourceurl0}" 86000
/usr/lib/rpm/pre-allocate-rpm.sh %{pkgname}-%{version}-%{release} \
                                 %{pkgname}-libs-%{version}-%{release} \
                                 %{pkgname}-devel-%{version}-%{release}

## Rebuild gpac with ffmpeg-devel
# set locale
case $LANG in
    ja*)LOCALE=ja ;;
    *) LOCALE=C ;;
esac

Rebuild_gpac_C(){
    echo -n "     "
    echo "Rebuild gpac with ffmpeg-devel"
}

Rebuild_gpac_ja(){
    echo -n "     "
    echo "ffmpeg-devel で gpac をリビルドします。"
}

Rebuild_gpac_$LOCALE
%{gpac_postinstall}

## Rebuild x264 with ffmpeg-devel
# set locale
case $LANG in
    ja*)LOCALE=ja ;;
    *) LOCALE=C ;;
esac

Rebuild_x264_C(){
    echo -n "     "
    echo "Rebuild x264 with ffmpeg-devel"
}

Rebuild_x264_ja(){
    echo -n "     "
    echo "ffmpeg-devel で x264 をリビルドします。"
}

Rebuild_x264_$LOCALE
%{x264_postinstall}


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

%changelog
* Mon Mar  9 2015 Munehiro Yamamoto <munepi@vinelinux.org> 2.6-1
- new upstream release

* Sat Feb 21 2015 Munehiro Yamamoto <munepi@vinelinux.org> 2.5.4-1
- new upstream release

* Mon Jan 19 2015 Munehiro Yamamoto <munepi@vinelinux.org> 2.5.3-1
- new upstream release

* Fri Jan  2 2015 Munehiro Yamamoto <munepi@vinelinux.org> 2.5.2-1
- new upstream release

* Sun Jul 13 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.2.6-2
- add BuildRequires: libcdio-paranoia-devel

* Sun Mar 16 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.2.6-1
- new upstream release

* Fri Oct  4 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.2.4-1
- new upstream release

* Sun Sep 29 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.2.3-1
- new upstream release
- added %%{x264_postinstall} in %%post

* Wed May 22 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.2.1-1
- new upstream release
- added man pages
  - added Source10: ffmpeg-1.2.1-doc.tar.xz

* Thu Apr  4 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.2-1
- new upstream release

* Tue Mar 12 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.1.3-1
- new upstream release

* Sun Feb  3 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.1.1-2
- libvpx >= 0.9.7

* Sun Jan 20 2013 Munehiro Yamamoto <munepi@vinelinux.org> 1.1.1-1
- new upstream release /x264-0.129

* Thu Sep 27 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.11.2-1
- new upstream release

* Mon Jun 11 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.11.1-1
- new upstream release

* Sat May 26 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.11-1
- new upstream release

* Wed Jan 11 2012 Munehiro Yamamoto <munepi@vinelinux.org> 0.9.1-1
- new upstream release

* Sun Dec 18 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.9-1
- new upstream release
- enable CELT decoding via libcelt
- enable FreeType support
- drop faad2 support (dropped upstream)

* Mon Sep 12 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.3-2
- added BuildArch: noarch

* Sun May 01 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.3-1
- new upstream release

* Tue Apr 05 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.2-1
- new upstream release

* Sat Mar 26 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.1-2
- required latest x264 build
- added BuildRequires: librtmp-devel >= 2.3

* Sat Oct 30 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6.1-1
- new upstream release

* Sat Jul 17 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6-4
- unpacked source archives

* Sun Jul 11 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6-3
- fixed some dependencies
  - Requires(post): libva-devel
  - Requires(post): libvpx-devel >= 0.9.1

* Sat Jun 26 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6-2
- new upstream release

* Sun Apr 18 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.6-1.20100410
- bumped version to pre-0.6
- updated source snapshot 20100410

* Sat Apr 10 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-12.20100401
- fixed self-build log size

* Sat Apr 10 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-11.20100401
- added ffprobe.1.gz

* Fri Apr 02 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-10.20100401
- updated source snapshot 20100401

* Sat Mar 20 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-8.20100216
- renamed %%{Source0} to ffmpeg-vl.spec

* Wed Feb 17 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.5-7.20100216
- updated source snapshot 20100216
  - rebuild with recent x264-devel
- updated pre-built man files: ffmpeg.1 ffplay.1 ffserver.1
- added BuildRequires:  libvdpau-devel

* Sat Jun 06 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-6
- dropped BuildArch: noarch
- added ffmpeg.1, ffplay.1, ffserver.1

* Tue May 26 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-5
- avoided to execute self-build-rpm.sh on RPM transaction
  - moved %%post actions to %%posttrans

* Wed May 13 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-4
- added BuildArch: noarch
- added ffmpeg-0.5-disable-texi2html.patch
  - dropped PreReq: texi2html

* Thu Mar 12 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-3
- added %%{gpac_postinstall} in %%post

* Wed Mar 11 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-2
- corrected release number

* Wed Mar 11 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.5-1
- new upstream release
- added PreReq: 
  - speex-devel
  - bzip2-devel

* Tue Feb 24 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-20090202.7
- change release to sync with ffmpeg

* Sun Feb 08 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-20090202.6
- changed to PreReq:  self-build-faad2 >= 2.0 from faad2-devel

* Wed Feb 04 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-20090202.5
- 20090202 snapshot

* Sun Jan 11 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-20090110.4
- 20090110 snapshot
- dropped some patches

* Sun Dec 14 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-15488.1
- source updated (r15488)
- fixed License: GPLv2+
- added BuildRequires: gsm-devel libdc1394-devel libraw1394-devel
- added BuildRequires: yasm (only %%ix86)
- applied ffmpeg-cpu.patch (merged from RPM Fusion)

* Sun Nov 02 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-11662.3vl4
- spec in utf8

* Tue May 20 2008 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.9-11662.2vl4
- run pre-allocate-rpm.sh in %%post
- set PreReq: self-build-setup >= 0.8
- change release number

* Wed Apr 16 2008 Atsushi SHICHI <ats777@gmail.com> 0.4.9-11662.1vl4
- add "Source1: %{pkgname}-%{version}.r%{svnrev}.tar.gz",
  include Source1 in the binary package.
- drop "Source100: ffmpeg-vine.patch".
- drop "PreReq: subversion".

* Mon Apr 7 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-0.20080128.1vl4
- build with new versioning policy
- change to use svn export from svn checkout on post install
- fix ffmpeg-vine.patch for libswscale/swscale.c.rej

* Thu Mar 13 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-0.20080128vl2
- For all pre-required package that is provied by self-build,  
  changed to its self-build package
  
* Sun Mar 9 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 0.4.9-0.20080128vl1
- initial build for Vine Linux 4.2
- snapshot 2008/01/28 + some Rev.11662 2008/01/29

### end of file