# Depends on: bluez cmake curl doxygen glew gperf hicolor-icon-theme jasper libaacs libass libbluray libcdio libcec mariadb libmicrohttpd libmodplug libmpeg2 nfs-utils libplist pulseaudio libssh libva libvdpau xorg-libxrandr libxslt lzo mesa nasm nss-mdns python2-pillow python2-bluez python2-simplejson rtmpdump shairplay samba speex swig taglib tinyxml unzip upower yajl zip git giflib libdvdcss libdvdnav libdvdread ffmpeg lirc lsb-release unrar desktop-file-utils xorg-xdpyinfo fribidi

description="A software media player and entertainment hub for digital media"
url="http://kodi.tv"
contributors="Rémy"
packager="tnut <tnut@nutyx.org>"

name=kodi
version=17.6
release=2

run=(hicolor-icon-theme libaacs bluez python2-bluez libplist libcec lsb-release pulseaudio shairplay unrar unzip upower libva libvdpau libssh desktop-file-utils samba xorg-xdpyinfo taglib speex fribidi xorg-libxrandr)

PKGMK_KEEP_SOURCES="no"

source=(https://github.com/xbmc/xbmc/archive/$version-Krypton.tar.gz
        fix-python-lib-path.patch
        cheat-sse-build.patch
        cpuinfo)
_components=(
kodi
kodi-bin
kodi-eventclients-common
kodi-eventclients-ps3
kodi-eventclients-xbmc-send
kodi-tools-texturepacker
kodi-addon-dev
kodi-audio-dev
kodi-eventclients-dev
kodi-game-dev
kodi-inputstream-dev
kodi-peripheral-dev
kodi-pvr-dev
kodi-screensaver-dev
kodi-visualization-dev)

prepare() {
[[ -d kodi-build ]] && rm -rvf kodi-build
  mkdir -v kodi-build
  cd "xbmc-$version-Krypton"
  patch -p1 -i ../fix-python-lib-path.patch
  # detect if building in arch chroot
  if [[ "$SRC" =~ ^\/build.* ]]; then
  patch -p1 -i "$srcdir/cheat-sse-build.patch"
  fi
}

build() {

cd kodi-build

cmake -DCMAKE_INSTALL_PREFIX=/usr \
      -DCMAKE_INSTALL_LIBDIR=/usr/lib \
      -DENABLE_EVENTCLIENTS=ON \
      -DENABLE_BLUETOOTH=ON \
      -DLIRC_DEVICE=/run/lirc/lircd \
      ../"xbmc-$version-Krypton"/project/cmake

make
make preinstall
}

package() {

cd kodi-build
for _cmp in ${_components[@]}
do 
DESTDIR=$PKG /usr/bin/cmake \
-DCMAKE_INSTALL_COMPONENT="$_cmp" \
-P cmake_install.cmake
done

install -dm755 $PKG/usr/share/licenses/$name
for licensef in LICENSE.GPL copying.txt; do
  mv $PKG/usr/share/doc/kodi/$licensef \
  $PKG/usr/share/licenses/$pkgname
done
cd $PKG
grep -lR '#!.*python' * | while read file; do sed -s 's/\(#!.*python\)/\12/g' -i "$file"; done
}
