%define qt4_ver 4.8.6
# Qt4 version auto-detection
%define _qt4_version %(pkg-config --modversion --silence-errors Qt 2>/dev/null || echo %{qt4_ver})
%define _qt4_prefix %(pkg-config --variable prefix --silence-errors Qt 2>/dev/null || echo %{_libdir}/qt4)
%define _qt4_datadir %(pkg-config --variable datadir --silence-errors Qt 2>/dev/null || echo %{_qt4_prefix})

%global pulseaudio_version %(pkg-config --modversion libpulse 2>/dev/null || echo 0.9.15)


#define bootstrap 1

Name: phonon
Summary: Multimedia framework api
Summary(ja): マルチメディアフレームワーク API
Version: 4.9.0
Release: 1%{?_dist_release}

Group: System Environment/Libraries
License: LGPLv2+
URL: http://phonon.kde.org/

Vendor: Project Vine
Distribution: Vine Linux

Provides: phonon-experimental = %{version}-%{release}
%if 0%{?bootstrap}
Provides: phonon-backend%{?_isa} = 4.7
%else
Requires: phonon-backend%{?_isa} => 4.7
%endif

Source0: http://download.kde.org/stable/phonon/%{version}/phonon-%{version}.tar.xz

## Upstream patches

## upstreamable patches
Patch10: phonon-rpath_use_link_path.patch
Patch11: phonon-DEFAULT_SOURCE.patch

## Vine patches

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: automoc4 >= 0.9.86
BuildRequires: cmake >= 2.6.2
BuildRequires: glib2-devel
BuildRequires: libqzeitgeist-devel
BuildRequires: libxcb-devel
BuildRequires: libxml2-devel
BuildRequires: qt4-devel >= 4.6.0
BuildRequires: openssl-devel
BuildRequires: pulseaudio-libs-devel >= 0.9.15
BuildRequires: extra-cmake-modules
BuildRequires: pkgconfig(Qt5DBus) pkgconfig(Qt5Designer) pkgconfig(Qt5OpenGL) pkgconfig(Qt5Widgets)
BuildRequires: pkgconfig(Qt5Declarative)

# TODO: enable the following Requires in next release
Requires: pulseaudio-libs >= %{pulseaudio_version}
Requires: qt4 >= %{_qt4_version}

%description
Phonon is a cross-platform portable Multimedia Support Abstraction,
which allows you to play multiple audio or video formats with the same
quality on all platforms, no matter which underlying architecture is
used.

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

%description devel
Header files for developing applications using phonon

%package qt5 
Summary: phonon for Qt5
Summary(ja): Qt5用phonon
%{?_qt5_version:Requires: qt5-qtbase%{?_isa} >= %{_qt5_version}}
%if 0%{?bootstrap}
Provides: %{name}-qt5-backend%{?_isa} = 4.7
%else
Requires: %{name}-qt5-backend%{?_isa} => 4.7
%endif
%description qt5 
Phonon is a cross-platform portable Multimedia Support Abstraction,
which allows you to play multiple audio or video formats with the same
quality on all platforms, no matter which underlying architecture is
used.

%package qt5-devel
Summary: Developer files for %{name}-qt5 
Summary(ja): %{name}-qt5の開発者向けファイル
Requires: %{name}-qt5%{?_isa} = %{version}-%{release}
%description qt5-devel
Header files for developing applications using phonon-qt5


%prep
%setup -q

%patch10 -p1 -b .10
%patch11 -p1 -b .11


%build
%ifarch x86_64
PATH="$PATH:`/usr/bin/pkg-config --variable=bindir Qt`"
%endif

mkdir -p %{_target_platform}
pushd %{_target_platform}
%cmake \
  -DCMAKE_BUILD_TYPE:STRING="Release" \
  -DPHONON_INSTALL_QT_COMPAT_HEADERS:BOOL=ON \
  -DPHONON_INSTALL_QT_EXTENSIONS_INTO_SYSTEM_QT:BOOL=ON \
  ..
popd

make %{?_smp_mflags} -C %{_target_platform}

mkdir -p %{_target_platform}-Qt5
pushd %{_target_platform}-Qt5
%cmake \
  -DCMAKE_BUILD_TYPE:STRING="Release" \
  -DPHONON_BUILD_PHONON4QT5:BOOL=ON \
  -DPHONON_INSTALL_QT_EXTENSIONS_INTO_SYSTEM_QT:BOOL=ON \
  ..
popd

make %{?_smp_mflags} -C %{_target_platform}-Qt5


%install
rm -rf $RPM_BUILD_ROOT

make install/fast DESTDIR=$RPM_BUILD_ROOT -C %{_target_platform}
make install/fast DESTDIR=%{buildroot} -C %{_target_platform}-Qt5

# own these dirs
mkdir -p $RPM_BUILD_ROOT%{_libdir}/kde4/plugins/phonon_backend/
mkdir -p $RPM_BUILD_ROOT%{_datadir}/kde4/services/phononbackends/
mkdir -p %{buildroot}%{_qt5_plugindir}/phonon4qt5_backend


%check
export PKG_CONFIG_PATH=%{buildroot}%{_datadir}/pkgconfig:%{buildroot}%{_libdir}/pkgconfig
test "$(pkg-config --modversion phonon)" = "%{version}"
test "$(pkg-config --modversion phonon4qt5)" = "%{version}"


%clean
rm -rf $RPM_BUILD_ROOT

%post
/sbin/ldconfig

%postun
/sbin/ldconfig

# https://bugzilla.redhat.com/show_bug.cgi?id=1223956
# replacing symlink with a dir
%pretrans devel -p <lua>
path = "%{_includedir}/phonon/Phonon"
st = posix.stat(path)
if st and st.type == "link" then
  os.remove(path)
end


%files
%defattr(-,root,root)
%license COPYING.LIB
%{_libdir}/libphonon.so.4*
%{_libdir}/libphononexperimental.so.4*
%{_qt4_plugindir}/designer/*.so
# kde4-specific dirs
%dir %{_libdir}/kde4/plugins/phonon_backend
%dir %{_datadir}/kde4/services/phononbackends
%dir %{_datadir}/phonon/

%files devel
%defattr(-,root,root)
%dir %{_includedir}/KDE
%{_includedir}/KDE/Phonon/
%{_includedir}/phonon/
%{_libdir}/libphonon.so
%{_libdir}/libphononexperimental.so
%dir %{_libdir}/cmake/
%{_libdir}/cmake/phonon/
%{_libdir}/pkgconfig/phonon.pc
%{_datadir}/phonon/buildsystem/
%{_qt4_datadir}/mkspecs/modules/qt_phonon.pri
%{_datadir}/dbus-1/interfaces/org.kde.Phonon.AudioOutput.xml

%files qt5 
%license COPYING.LIB
%dir %{_datadir}/phonon4qt5
%{_libdir}/libphonon4qt5.so.4*
%{_libdir}/libphonon4qt5experimental.so.4*
%{_qt5_plugindir}/designer/phononwidgets.so
%dir %{_qt5_plugindir}/phonon4qt5_backend/

%files qt5-devel
%{_datadir}/dbus-1/interfaces/org.kde.Phonon4Qt5.AudioOutput.xml
%{_datadir}/phonon4qt5/buildsystem/
%dir %{_libdir}/cmake/
%{_libdir}/cmake/phonon4qt5/
%{_includedir}/phonon4qt5/
%{_libdir}/libphonon4qt5.so
%{_libdir}/libphonon4qt5experimental.so
%{_libdir}/pkgconfig/phonon4qt5.pc
%{_qt5_archdatadir}/mkspecs/modules/qt_phonon4qt5.pri


%changelog
* Thu Jun 30 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.8.2-2
- rebuilt with new toolchain.

* Fri Nov  7 2014 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 4.8.2-1
- new upstream release

* Tue Dec 10 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.7.1-1
- new upstream release
- update Patch1
- remove Patch50 (phonon-4.5.57-plugindir.patch)

* Sat Jan  7 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.6.0-1
- new upstream release

* Sat Nov 26 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.5.1-1
- new upstream release

* Sat Oct 22 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.5.0-2
- added Patch100 and 200 to build with pulseaudio-1.0

* Sun Jun  5 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.5.0-1
- new upstream release
- added BR: libqzeitgeist-devel

* Tue Mar  8 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.4-2
- rebuilt with qt4-4.7.2

* Sat Jan 29 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.4-1
- new upstream release
- rebuilt with qt4-4.7.1 on VineSeed

* Mon Dec 13 2010 Yoji TOYODA <bsyamato@sea.plala.or.jp> 4.4.3-1
- new upstream release

* Sun Oct 17 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.2-2
- added sybolic link in %%{_qt4_headerdir}

* Mon Sep 20 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.2-1
- new upstream release
- dropt Patch51 and 57
- rebuilt with rpm-4.8.1

* Sun Mar 14 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.4.0-1
- new upstream release
- dropt Patch1, 50, 54 and 100
- added Patch57
  * Fri Jan 22 2010 Rex Dieter <rdieter@fedoraproject.org> - 4.3.80-5.2
  - F11: patch/modularize pa device-manager bits 

* Sun Feb 14 2010 Shu KONNO <owa@bg.wakwak.com> 4.3.80-2
- added qmake path to PATH (if x86_64)

* Sat Feb 13 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.80-1
- new upstream release
- built with new toolchain

* Sat Aug 29 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.1-3
- added Patch102 and 103 from FC
  * Thu Jun 18 2009 Rex Dieter <rdieter@fedoraproject.org> - 4.3.1-11
  - fix for '#' in filenames
  * Fri Jun 05 2009 Kevin Kofler <Kevin@tigcc.ticalc.org> - 4.3.1-8
  - restore patches to the xine backend

* Fri Aug 14 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 4.3.1-2
- added Patch100 and 101 from FC
  * Tue Mar  3 2009 Lukáš Tinkl <ltinkl@redhat.com> - 4.3.1-2
  - backport GStreamer backend bugfixes (UTF-8 file handling, volume fader)
- added backend sub-pakcages

* Thu Mar 26 2009 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 4.3.1-1
- new upstream release
- add BuildPrereq: cmake

* Sat Jan 24 2009 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 4.3.0-1
- new upstream release

* Wed Jan 14 2009 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 4.2.96-1
- new upstream release
- update %%files
- add BuildPrereq: xine-lib-devel libxcb-devel

* Wed Nov 26 2008 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 4.2.80-1
- new upstream release

* Thu Oct 09 2008 Shu KONNO <owa@bg.wakwak.com> 4.2.0-2
- added script to append qmake path
- added option -DLIB_INSTALL_DIR at cmake

* Tue Oct  7 2008 AKIYAMA Kazuhito <akiyama@yb3.so-net.ne.jp> 4.2.0-1
- initial release for VineSeed
