makedepends=(cmake doxygen glew gperf jasper libass libbluray xorg-glu nss-mdns libnfs
             libcdio mariadb libmicrohttpd libmodplug libmpeg2 nfs-utils libplist pulseaudio
             libva libvdpau xorg-libxrandr libxslt mesa nss-mdns rapidjson rtmpdump pipewire
             shairplay samba speex swig taglib tinyxml tinyxml2 yajl zip git giflib libdvdcss libdvdnav
             libdvdread lirc lsb-release fribidi flatbuffers fmt fstrcmp gtest pcre)
run=(hicolor-icon-theme libaacs bluez libplist python-pillow python-pycryptodomex python-simplejson
     libcec pulseaudio shairplay unrar unzip upower libva openjdk
     libvdpau libssh desktop-file-utils samba xorg-xdpyinfo taglib speex fribidi xorg-libxrandr)

description="A software media player and entertainment hub for digital media"
url="http://kodi.tv"

packager="Great-OS Team"
maintainer="Great-OS Team"

name=kodi
version=21.3
release=4

_versionname=Omega

PKGMK_KEEP_SOURCES="no"
PKGMK_IGNORE_UNPACK="yes"
source=(https://github.com/xbmc/xbmc/archive/refs/tags/${version}-${_versionname}.tar.gz
        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() {

  bsdtar -xf ${version}-${_versionname}.tar.gz

  [[ -d kodi-build ]] && rm -rvf kodi-build
    mkdir -v kodi-build

}

build() {

  cd kodi-build

  cmake -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=/usr/lib \
        -DENABLE_EVENTCLIENTS=ON \
        -DCORE_PLATFORM_NAME=x11 \
        -DAPP_RENDER_SYSTEM=gl \
        -DENABLE_INTERNAL_SPDLOG=ON \
        -DENABLE_INTERNAL_FFMPEG=ON \
        -DENABLE_INTERNAL_FMT=ON \
        ../"xbmc-$version-${_versionname}"

  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
}
