# Template file for 'kodi'
pkgname=kodi
version=17.1
revision=3
build_style=cmake
patch_args="-Np1"
_codename="Krypton"
wrksrc="xbmc-${version}-${_codename}"
short_desc="A software media player and entertainment hub for digital media"
maintainer="Juan RP <xtraeme@voidlinux.eu>"
homepage="http://www.kodi.tv/"
license="GPL-2"
distfiles="https://github.com/xbmc/xbmc/archive/${version}-${_codename}.tar.gz"
checksum=303f3903cbb57ccc2961f09cf3746505542bcb129a464f0687d7ca8601cebbee
build_wrksrc=project/cmake

lib32disabled=yes
only_for_archs="i686 i686-musl x86_64 x86_64-musl"

hostmakedepends="
 automake libtool pkg-config gperf cmake zip unzip nasm yasm python-devel
 gettext-devel libltdl-devel curl"
makedepends="
 eudev-libudev-devel pcre-devel expat-devel libpng-devel libjpeg-turbo-devel
 libXrandr-devel avahi-libs-devel pulseaudio-devel samba-devel tiff-devel
 libmysqlclient-devel libmpeg2-devel wavpack-devel zlib-devel lzo-devel
 libXmu-devel glew-devel fribidi-devel sqlite-devel libcdio-devel freetype-devel
 jasper-devel faac-devel SDL2_image-devel faad2-devel libmodplug-devel libressl-devel
 libmad-devel fontconfig-devel libXinerama-devel libsamplerate-devel libmms-devel
 enca-devel boost-devel libcurl-devel libva-devel libvdpau-devel libass-devel
 libbluetooth-devel yajl-devel libplist-devel librtmp-devel tinyxml-devel
 taglib-devel libcap-devel lame-devel libbluray-devel libnfs-devel ffmpeg-devel
 giflib-devel libxslt-devel gnutls-devel libssh-devel libmicrohttpd-devel
 libcec-devel dcadec-devel crossguid"

# The following dependencies are dlopen(3)ed.
depends="libbluray libmad libvorbis libcurl libflac libmodplug libass libmpeg2
 lame librtmp libnfs>=1.9.7 libplist>=1.12"
depends+=" glxinfo hicolor-icon-theme desktop-file-utils xdpyinfo"

# musl builds need generated addons (no java).
# gold broken with musl
case "$XBPS_MACHINE" in
       *-musl) _kodi_nojava=yes; configure_args+=" -DENABLE_LDGOLD=Off";;
       *) hostmakedepends+=" swig openjdk-jre";;
esac

pre_configure() {
	# Copy generated files to avoid requiring java.
	if [ -n "${_kodi_nojava}" ]; then
		mkdir -p build/build/swig

		# THESE FILES MUST BE UPDATED WITH EVERY VERSION BUMP!
		cp -r $FILESDIR/swig.nojava-$version/* -t build/build/swig
		cp $FILESDIR/CMakeCache.txt.nojava build/CMakeCache.txt

		echo "set(FOUND_SWIG Yes)" > modules/FindSWIG.cmake
	else
		. /etc/profile.d/10_openjdk.sh
	fi
}

post_install() {
	# remove unused stuff
	rm -rf ${DESTDIR}/usr/include
	find ${DESTDIR}/usr/lib -name "*.cmake" -delete
}
