# Template file for 'tomahawk'
pkgname=tomahawk-qt5
version=0.8.4
revision=12
wrksrc=${pkgname%-*}-${version}
build_style=cmake
build_options="upower hatchet kde xmpp"
desc_option_hatchet="Enable support for http://hatchet.is"
desc_option_kde="Enable support for KDE"
desc_option_xmpp="Enable support for XMPP"
build_options_default=${build_options}
configure_args="-Wno-dev -DBUILD_RELEASE=ON \
 $(vopt_if hatchet '-DBUILD_HATCHET=ON' '-DBUILD_HATCHET=OFF') \
 -DBUILD_WITH_QT4=OFF \
 -DWITH_CRASHREPORTER=OFF \
 -DTAGLIB_MIN_VERSION=1.10 \
 $(vopt_if kde '-DWITH_KDE4=ON' '-DWITH_KDE4=OFF') \
 $(vopt_if upower '-DWITH_UPOWER=ON' '-DWITH_UPOWER=OFF')"
hostmakedepends="pkg-config"
makedepends="boost-devel Lucene++-devel qt5-devel taglib-devel sparsehash
 gnutls-devel qt5-webkit-devel qca-qt5-devel attica-qt5-devel qtkeychain-qt5-devel
 qt5-svg-devel qt5-tools-devel phonon-qt5-devel liblastfm-qt5-devel quazip-qt5-devel
 libechonest-qt5-devel libressl-devel $(vopt_if hatchet websocketpp)
 $(vopt_if xmpp jreen-qt5-devel) $(vopt_if kde telepathy-qt5-devel)"
depends="virtual?phonon-qt5-backend qt5-plugin-sqlite $(vopt_if xmpp qca-qt5-ossl)"
short_desc="Multi-source social music player"
maintainer="Duncaen <duncaen@voidlinux.eu>"
license="GPL-3"
homepage="http://tomahawk-player.org/"
distfiles="http://download.tomahawk-player.org/${pkgname%-*}-${version}.tar.bz2"
checksum=0fb04bc6b7009e17186b3d384057939727c6f289d22f7f9a5ed2c9c9cd800449

provides="tomahawk-${version}_${revision}"
replaces="tomahawk>=0"

if [ -n "$CROSS_BUILD" ]; then
	hostmakedepends+=" qt5-host-tools qt5-devel qt5-svg-devel qt5-tools-devel qt5-webkit-devel"
fi

post_extract() {
	# fix echonest-qt5 detection
	sed -i 's|echonest/Track.h|echonest5/Track.h|' CMakeModules/FindEchonest.cmake
	# fix echonest-qt5 includes
	sed -i 's|^#include <echonest/|#include <echonest5/|' \
		src/tomahawk/sourcetree/items/CategoryItems.cpp \
		src/tomahawk/sourcetree/items/CategoryItems.cpp \
		src/libtomahawk/playlist/dynamic/echonest/EchonestControl.h \
		src/libtomahawk/playlist/dynamic/echonest/EchonestSteerer.cpp \
		src/libtomahawk/playlist/dynamic/echonest/EchonestGenerator.h \
		src/libtomahawk/EchonestCatalogSynchronizer.cpp \
		src/libtomahawk/EchonestCatalogSynchronizer.cpp \
		src/libtomahawk/GlobalActionManager.cpp \
		src/libtomahawk/EchonestCatalogSynchronizer.h \
		src/infoplugins/generic/echonest/EchonestPlugin.cpp \
		src/infoplugins/generic/echonest/EchonestPlugin.h
	# fix quazip-qt5 detection
	sed -i CMakeModules/FindQuaZip.cmake \
		-e 's|quazip/quazip.h|quazip5/quazip.h|' \
		-e '/^find_library/s|quazip|&5|'
	sed -i 's|#include <quazip|&5|' src/libtomahawk/utils/TomahawkUtils.cpp
	# fix qca-qt5 detection
	sed -i CMakeModules/FindQCA2.cmake \
		-e 's|qca2|&-qt5|' \
		-e 's|NAMES qca|&-qt5|'
	# fix build
	sed -i '24a#include <QDataStream>' src/libtomahawk/network/acl/AclRegistry.cpp
	sed -i '30a#include <QDataStream>' src/libtomahawk/utils/TomahawkCache.h
	# fix musl build
	sed -i '41a#include <sys/user.h>' src/libtomahawk/accounts/ResolverAccount.cpp
}

tomahawk-qt5-devel_package() {
	depends="tomahawk-qt5>=${version}_${revision}"
	short_desc+=" - development files"
	provides="tomahawk-devel-${version}_${revision}"
	replaces="tomahawk-devel>=0"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/cmake
	}
}
