# Contributor: Carlo Landmeter <clandmeter@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=kodi
pkgver=17.6
_realname=Krypton
pkgrel=4
pkgdesc="A software media player and entertainment hub for digital media"
url="http://kodi.tv"
arch="x86 x86_64"
license="GPL"
depends="python2 hicolor-icon-theme xdpyinfo unrar mesa-demos curl py-pillow
	py-bluez py-simplejson"
depends_dev="gettext-dev boost-dev mesa-dev glew-dev glu-dev mariadb-connector-c-dev
	libass-dev libogg-dev libvorbis-dev libmodplug-dev curl-dev flac-dev
	libgcrypt-dev bzip2-dev tiff-dev lzo-dev yajl-dev bluez-dev tinyxml-dev
	fribidi-dev sqlite-dev libpng-dev libcdio-dev pcre-dev freetype-dev
	taglib-dev jasper-dev alsa-lib-dev dbus-dev sdl-dev sdl_image-dev
	lame-dev libmicrohttpd-dev libbluray-dev avahi-dev libxrandr-dev
	libxt-dev libxmu-dev samba-dev gawk libssh-dev libva-dev libnfs-dev
	yasm-dev libmpeg2-dev libmad-dev libsamplerate-dev rtmpdump-dev
	libjpeg-turbo-dev eudev-dev libcap-dev udisks2-dev faac-dev gnutls-dev
	libxslt-dev libplist-dev libshairport-dev ffmpeg-dev afpfs-ng-dev
	libcec-dev x264-dev bsd-compat-headers curl-dev python2-dev dcadec-dev
	libdvdcss-dev"
makedepends="$depends_dev automake autoconf m4 libtool swig findutils
	openjdk8-jre-base boost-thread zip gperf cmake coreutils nasm tar
	git"
subpackages="$pkgname-dev $pkgname-doc $pkgname-dbg"
install=""
replaces="xbmc"
options="ldpath-recursive"
source="https://github.com/xbmc/xbmc/archive/$pkgver-$_realname.tar.gz
	fix-musl.patch
	fix-fileemu.patch
	fortify-source-fix.patch
	remove-filewrap.patch
	add-missing-includes.patch
	set-default-stacksize.patch
	"

builddir="$srcdir/xbmc-$pkgver-$_realname"

prepare() {
	local i
	cd "$builddir"
	for i in $source; do
		case $i in
			*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
	MAKEFLAGS="-j1" ./bootstrap || return 1
	mkdir -p crossguid
	make -j1 -C tools/depends/target/crossguid PREFIX="$PWD"/crossguid
}

build() {
	cd "$builddir"
	LDFLAGS="$LDFLAGS -L$PWD/crossguid/lib" \
	CXXFLAGS="$CXXFLAGS -I$PWD/crossguid/include" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-non-free \
		--disable-debug \
		--with-ffmpeg=shared \
		--enable-static=no \
		--enable-libbluray \
		--enable-external-libraries \
		|| return 1
	make || return 1
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install || return 1
}

sha512sums="1f1ba91e6129ab423f9ad47b63d7bb75775dbf18638a96413a572aaa790f4f0d738ca35486513e158a7f55d501f78f08dd9d68aabe2fbb80a729c6091b264111  17.6-Krypton.tar.gz
f225073ca75647581463094c0a9d1dd1fa3e1a58353292e1c99da30eb6f97026f4647853da2bbdc7777c6c1b13a16b368b09c93f5d4c1be13f8a11b4bbfbabbf  fix-musl.patch
7dea044f77d9a38a4bccc9d542ba62d0146f2bf60f92999ddada1a4fc020b88e054c7f047ba9b8b21639889b31c3f117308f38aa50fab759f941cc014cb0e69d  fix-fileemu.patch
5e972e6f6ad13f5dc8ac5e9d593171988e0cc93879178aa7621af44d41b89b5b86429af4d0c2e6516b626d042f247bcf0b1f957f647138a03ce73c5c7b3311b9  fortify-source-fix.patch
118a4e10ac5abdd9b6cfc87ad1b91cf03b3641023337571250beb5125c2c830e678eced1e42703253d66af61ec9fe3ce6c44cf7c0012d457f9bebc0ddfe992d2  remove-filewrap.patch
378a0e8fd9676dd76cfb30d62085b953625dd0185e2673de2331fc7ae0802dae4f56d0b74e878e4d313942fda8831e9669bff284dbe974db5ad16fe07af884d6  add-missing-includes.patch
3fd97e9fa22e59b3cd30fdad19474e177a9d062598765fa8ba4955f1da4e10581ff1463dd0794d3ee3cefebf753007a4d445b2bc47a257574d3927c1408b8876  set-default-stacksize.patch"
