%global somajor 5
%global sominor 0
%global sotiny  0
%global soversion %{somajor}.%{sominor}.%{sotiny}

Name:		libvpx
Version:	1.7.0
Release:	1%{?_dist_release}
Summary:        The VP8/VP9 Codec SDK
Summary(ja):	VP8/VP9 コーデックソフトウェア開発キット

Group:		System Environment/Libraries
License:	BSD
URL:		http://www.webmproject.org/code/
Source0:        https://github.com/webmproject/libvpx/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        vpx_config.h
Source2:        libvpx.ver

BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root
%ifarch %{ix86} x86_64
BuildRequires:  yasm
%endif

Vendor: Project Vine
Distribution: Vine Linux
Packager: daisuke

%description
The WebM VP8/VP9 Codec SDK allows you to integrate your applications with
the VP8/VP9 video codec, a high quality, royalty free, open source codec 
deployed on millions of computers and devices worldwide.

%description -l ja
WebM VP8/VP9 コーデック SDK は、VP8/VP9 ビデオコーデックをアプリケーションに
統合するための開発キットです。VP8/VP9ビデオコーデックは高品質でロイヤリティフリー
かつオープンソースのコーデックで、世界中の多くのコンピュータやデバイスで利用されて
います。

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

%description devel
The %{name}-devel package contains development files for
%{name}.

%description devel -l ja
%{name}-devel パッケージは %{name} の開発用ファイルを含んでいます。

%package utils
Summary:	example programs for %{name}
Summary(ja):	%{name} のサンプルプログラム
Group:		Applications/Multimedia
Requires:	%{name} = %{version}-%{release}

%description utils
The %{name}-utils package contains example programs that
use %{name}.

%description utils -l ja
%{name}-utils パッケージは、%{name} を使用したサンプル
アプリケーションを含んでいます。


%prep
%setup -q

%build

%ifarch %{ix86}
%global vpxtarget x86-linux-gcc
%else
%ifarch x86_64
%global vpxtarget x86_64-linux-gcc
%else
%global vpxtarget generic-gnu
%endif
%endif

%if "%{vpxtarget}" == "generic-gnu"
%global generic_target 1
%else
%global generic_target 0
%endif

./configure \
 --target=%{vpxtarget} \
 --enable-pic \
 --enable-experimental --enable-spatial-svc \
 --enable-vp9-highbitdepth \
%if ! %{generic_target}
 --enable-shared \
%endif
 --prefix=%{_prefix} \
 --libdir=%{_libdir} \
 --disable-install-docs \
 --enable-install-srcs \
 --size-limit=16384x16384

# fix up optflags
sed -i "s|-O3|%{optflags}|g" libs-%{vpxtarget}.mk
sed -i "s|-O3|%{optflags}|g" examples-%{vpxtarget}.mk
sed -i "s|-O3|%{optflags}|g" docs-%{vpxtarget}.mk

%{__make} %{?_smp_mflags} verbose=true

# Manual shared library creation
# We should never need to do this anymore, and if we do, we need to fix the version-script.
%if %{generic_target}
mkdir tmp
cd tmp
ar x ../libvpx_g.a
cd ..
gcc -fPIC -shared -pthread -lm -Wl,--no-undefined -Wl,-soname,libvpx.so.%{somajor} -Wl,--version-script,%{SOURCE2} -Wl,-z,noexecstack -o libvpx.so.%{soversion}
tmp/*.o
rm -rf tmp
%endif

%install
%{__rm} -rf $RPM_BUILD_ROOT
%{__make} DIST_DIR=$RPM_BUILD_ROOT%{_prefix} dist

# Simpler to label the dir as %%doc.
if [ -d %{buildroot}/usr/docs ]; then
   mv %{buildroot}/usr/docs doc/
fi

# Again, we should never need to do this anymore.
%if %{generic_target}
install -p libvpx.so.%{soversion} %{buildroot}%{_libdir}
pushd %{buildroot}%{_libdir}
ln -sf libvpx.so.%{soversion} libvpx.so
ln -sf libvpx.so.%{soversion} libvpx.so.%{somajor}
ln -sf libvpx.so.%{soversion} libvpx.so.%{somajor}.%{sominor}
popd
%endif

pushd %{buildroot}
# Stuff we don't need.
rm -rf usr/build/ usr/md5sums.txt usr/lib*/*.a usr/CHANGELOG usr/README
# No, bad google. No treat.
mv usr/bin/examples/* usr/bin/
rm -rf usr/bin/examples

# Rename a few examples
mv usr/bin/postproc usr/bin/vp8_postproc
mv usr/bin/simple_decoder usr/bin/vp8_simple_decoder
mv usr/bin/simple_encoder usr/bin/vp8_simple_encoder
mv usr/bin/twopass_encoder usr/bin/vp8_twopass_encoder
# Fix the binary permissions
chmod 755 usr/bin/*
popd

# Get the vpx_config.h file
%ifarch %{arm}
cp -a vpx_config.h %{buildroot}%{_includedir}/vpx/vpx_config-arm.h
%else
# Does ppc64le need its own?
%ifarch ppc64 ppc64le
cp -a vpx_config.h %{buildroot}%{_includedir}/vpx/vpx_config-ppc64.h
%else
%ifarch s390 s390x
cp -a vpx_config.h %{buildroot}%{_includedir}/vpx/vpx_config-s390.h
%else
%ifarch %{ix86}
cp -a vpx_config.h %{buildroot}%{_includedir}/vpx/vpx_config-x86.h
%else
cp -a vpx_config.h %{buildroot}%{_includedir}/vpx/vpx_config-%{_arch}.h
%endif
%endif
%endif
%endif

cp %{SOURCE1} %{buildroot}%{_includedir}/vpx/vpx_config.h
# for timestamp sync
touch -r AUTHORS %{buildroot}%{_includedir}/vpx/vpx_config.h

mv %{buildroot}%{_prefix}/src/vpx_dsp %{buildroot}%{_includedir}/
mv %{buildroot}%{_prefix}/src/vpx_mem %{buildroot}%{_includedir}/
mv %{buildroot}%{_prefix}/src/vpx_ports %{buildroot}%{_includedir}/
mv %{buildroot}%{_prefix}/src/vpx_scale %{buildroot}%{_includedir}/

rm -rf %{buildroot}%{_prefix}/src

%clean
rm -rf $RPM_BUILD_ROOT


%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig


%files
%defattr(-,root,root,-)
%doc AUTHORS LICENSE README CHANGELOG
%{_libdir}/*.so.*

%files devel
%defattr(-,root,root,-)
%doc docs/html/
%{_includedir}/vpx/
%{_includedir}/vpx_dsp/
%{_includedir}/vpx_mem/
%{_includedir}/vpx_ports/
%{_includedir}/vpx_scale/
%{_libdir}/pkgconfig/vpx.pc
%{_libdir}/libvpx.so

%files utils
%defattr(-,root,root,-)
%{_bindir}/*


%changelog
* Thu Feb 22 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 1.7.0-1
- new upstream release.
- updated Source2.
- added Source1.

* Mon Oct 08 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 1.1.0-1
- new upstream release
- remove Patch0 (libvpx-0.9.0-no-explicit-dep-on-static-lib.patch)
- remove Source1 (libvpx.pc)

* Sun Oct 16 2011 Munehiro Yamamoto <munepi@vinelinux.org> 0.9.6-1
- new upstream release

* Mon Dec 27 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9.5-1
- new upstream release

* Sun Sep 26 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.9.1-2
- rebuild with rpm-4.8.1 for pkg-config file

* Sun Jul 11 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9.1-1
- new upstream release

* Mon May 24 2010 Daisuke SUZUKI <daisuke@linux.or.jp> 0.9.0-1
- initial build for Vine Linux