#!/bin/sh

. config/options

$SCRIPTS/install Python
$SCRIPTS/install zlib
$SCRIPTS/install bzip2
$SCRIPTS/install lzo
$SCRIPTS/install pcre

$SCRIPTS/install alsa-lib
$SCRIPTS/install libass
$SCRIPTS/install enca #libass
$SCRIPTS/install curl
$SCRIPTS/install libssh

$SCRIPTS/install dbus

$SCRIPTS/install libXt
$SCRIPTS/install libXtst
$SCRIPTS/install libXmu
$SCRIPTS/install libXrandr

$SCRIPTS/install Mesa
$SCRIPTS/install glew
$SCRIPTS/install fontconfig  #libass?
$SCRIPTS/install fribidi

$SCRIPTS/install jpeg
$SCRIPTS/install libpng
$SCRIPTS/install tiff
$SCRIPTS/install freetype   #libass?
$SCRIPTS/install jasper

# $SCRIPTS/install a52dec # static
$SCRIPTS/install libmad
$SCRIPTS/install libsamplerate
$SCRIPTS/install libogg
$SCRIPTS/install libvorbis
$SCRIPTS/install libcdio
$SCRIPTS/install libmms
$SCRIPTS/install libmodplug
$SCRIPTS/install faad2
$SCRIPTS/install flac
$SCRIPTS/install wavpack
$SCRIPTS/install libmpeg2
# $SCRIPTS/install musepack

$SCRIPTS/install SDL
$SCRIPTS/install SDL_mixer
$SCRIPTS/install SDL_image

$SCRIPTS/install sqlite
$SCRIPTS/install mysql
$SCRIPTS/install samba

[ "$FAAC_SUPPORT" = yes ] && $SCRIPTS/install faac
[ "$VDPAU" = yes ] && $SCRIPTS/install libvdpau
[ "$VAAPI" = yes ] && $SCRIPTS/install libva
[ "$CRYSTALHD" = yes ] && $SCRIPTS/install crystalhd
[ "$AVAHI_DAEMON" = yes ] && $SCRIPTS/install avahi
[ "$WEBSERVER" = yes ] && $SCRIPTS/install libmicrohttpd

PKG_DIR=`find $PACKAGES -type d -name $1`
PYTHON_LIBDIR="`ls -d $INSTALL/usr/lib/python*`"

mkdir -p $INSTALL/usr/bin
  cp $PKG_DIR/scripts/xbmc $INSTALL/usr/bin
  cp $PKG_BUILD/tools/EventClients/Clients/XBMC\ Send/xbmc-send.py $INSTALL/usr/bin/xbmc-send

mkdir -p $INSTALL/usr/lib/xbmc
  cp $PKG_BUILD/xbmc.bin $INSTALL/usr/lib/xbmc
  cp $PKG_BUILD/xbmc-xrandr $INSTALL/usr/lib/xbmc

cd $PKG_BUILD
  find system addons \
    -regextype posix-extended -type f \
    -not -iregex ".*svn.*|.*win32(dx)?\.vis|.*osx\.vis" \
    -iregex ".*-linux.*|.*\.vis|.*\.xbs" \
    -exec install -D "{}" $ROOT/$INSTALL/usr/lib/xbmc/"{}" ";"

  find addons language media scripts sounds userdata system \
    -regextype posix-extended -type f \
    -not -iregex ".*-linux.*|.*\.vis|.*\.xbs|.*svn.*|.*\.so|.*\.dll|.*\.pyd|.*python/.*\.zlib" \
    -exec install -D -m 0644 "{}" $ROOT/$INSTALL/usr/share/xbmc/"{}" ";"
cd -

# overriding Splash image
mkdir -p $INSTALL/usr/share/xbmc/media
  rm -rf $INSTALL/usr/share/xbmc/media/Splash.png
  cp $PKG_DIR/splash/Splash.png $INSTALL/usr/share/xbmc/media/

mkdir -p $PYTHON_LIBDIR/site-packages
  cp -R $PKG_BUILD/tools/EventClients/lib/python/* $PYTHON_LIBDIR/site-packages

if [ "$WEBSERVER" = yes ]; then
  mkdir -p $INSTALL/usr/share/xbmc/web
    cp -R $PKG_BUILD/web/poc_jsonrpc/* $INSTALL/usr/share/xbmc/web
fi

# other programs needed to run
  $SCRIPTS/install alsa
