# Template file for 'kodi-rpi'
pkgname=kodi-rpi
version=15.2
revision=3
patch_args="-Np1"
_codename="Isengard"
wrksrc="xbmc-${version}-${_codename}"
short_desc="A software media player and entertainment hub for digital media (RPi)"
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=dd8aeb942e6de5d1488e243e1346cff3f6597e21b5131a3ba72ff5cc82037110

nopie=yes
only_for_archs="armv6l armv6l-musl armv7l armv7l-musl"

hostmakedepends="
 automake libtool pkg-config gperf cmake zip unzip nasm yasm
 gettext-devel libltdl-devel python-devel libmysqlclient-devel
 SDL2_image-devel lzo-devel swig"
makedepends="
 libudev-devel pcre-devel expat-devel libpng-devel libjpeg-turbo-devel
 avahi-libs-devel alsa-lib-devel samba-devel tiff-devel libmysqlclient-devel
 libmpeg2-devel wavpack-devel zlib-devel lzo-devel fribidi-devel sqlite-devel freetype-devel
 jasper-devel faac-devel faad2-devel libmodplug-devel libressl-devel libass-devel
 libmad-devel fontconfig-devel libsamplerate-devel libmms-devel libcurl-devel ffmpeg-devel
 enca-devel boost-devel libbluetooth-devel yajl-devel libplist-devel librtmp-devel
 tinyxml-devel taglib-devel libcap-devel lame-devel libnfs-devel libxslt-devel
 libcec-devel libmicrohttpd-devel libcdio-devel python-devel libssh-devel rpi-userland-devel"

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

# musl builds need generated addons (no java).
case "$XBPS_MACHINE" in
	*-musl) _kodi_nojava=yes;;
	*) hostmakedepends+=" openjdk-jre";;
esac

provides="kodi-${version}_${revision}"

# Create xbmc system user to launch xbmc-standalone.
system_accounts="xbmc"
xbmc_homedir="/var/lib/xbmc"
xbmc_groups="audio,input,video"

pre_configure() {
	# Copy generated files to avoid requiring java.
	if [ -n "${_kodi_nojava}" ]; then
		$XBPS_FETCH_CMD http://repo.voidlinux.eu/distfiles/kodi-${version}-generated-addons.tar.xz
		tar xf kodi-${version}-generated-addons.tar.xz -C ${wrksrc}
		BOOTSTRAP_STANDALONE=1 make JAVA=/bin/true -f codegenerator.mk
	else
		. /etc/profile.d/10_openjdk.sh
		BOOTSTRAP_STANDALONE=1 make -f codegenerator.mk
	fi
	BOOTSTRAP_STANDALONE=1 make -f bootstrap.mk
	# Use cross prefix for python include/libdir.
	sed -e "s,-L\$ac_python_libdir,-L${XBPS_CROSS_BASE}/usr/lib,g" -i configure
	sed -e "s,PYTHON_CPPFLAGS=\$python_path,PYTHON_CPPFLAGS=-I${XBPS_CROSS_BASE}/usr/include/python2.7,g" -i configure
}

do_configure() {
	CFLAGS+=" -I${XBPS_CROSS_BASE}/opt/vc/include/ -I${XBPS_CROSS_BASE}/opt/vc/include/IL"
	CFLAGS+=" -I${XBPS_CROSS_BASE}/opt/vc/include/interface/vcos/pthreads"
	CFLAGS+=" -I${XBPS_CROSS_BASE}/opt/vc/include/interface/vmcs_host/linux"
	CXXFLAGS="$CFLAGS -fpermissive"
	LDFLAGS+=" -L${XBPS_CROSS_BASE}/opt/vc/lib -Wl,-R/opt/vc/lib"

	export CFLAGS CXXFLAGS LDFLAGS

	./configure ${configure_args} \
		--disable-gl \
		--disable-sdl \
		--disable-x11 \
		--disable-xrandr \
		--disable-openmax \
		--disable-joystick \
		--disable-debug \
		--disable-crystalhd \
		--disable-vtbdecoder \
		--disable-vaapi \
		--disable-vdpau \
		--disable-pulse \
 		--disable-projectm \
		--disable-optical-drive \
		--disable-libbluray \
		--with-platform=raspberry-pi \
		--enable-gles \
		--enable-optimizations \
		--enable-libcec \
		--enable-player=omxplayer \
		--enable-external-libraries \
		--with-ffmpeg=shared \
		ac_cv_path_JAVA_EXE=/bin/true


	sed -e "s,\$(DVDREAD_CFLAGS),,g;s,AR=ar,AR=$AR,g;s,LD=ld,LD=$LD,g;s,RANLIB=ranlib,RANLIB=$RANLIB,g" -i lib/libdvd/libdvd{nav,read}/Makefile
}
do_build() {
	make ${makejobs}
}
do_install() {
	make DESTDIR=${DESTDIR} install
	rm -rf ${DESTDIR}/usr/include
	vsv xbmc-standalone
}
