#!/bin/sh

. config/options

$SCRIPTS/build toolchain
$SCRIPTS/build boost
$SCRIPTS/build Python
$SCRIPTS/build zlib
$SCRIPTS/build bzip2
$SCRIPTS/build lzo
$SCRIPTS/build pcre

$SCRIPTS/build alsa-lib
$SCRIPTS/build libass
$SCRIPTS/build enca #libass?
$SCRIPTS/build curl
$SCRIPTS/build libssh

$SCRIPTS/build dbus

$SCRIPTS/build libXt
$SCRIPTS/build libXtst
$SCRIPTS/build libXmu
$SCRIPTS/build libXrandr

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

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

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

$SCRIPTS/build SDL         #?
$SCRIPTS/build SDL_mixer   #?
$SCRIPTS/build SDL_image   #?

$SCRIPTS/build sqlite
$SCRIPTS/build mysql #lib  #?
$SCRIPTS/build samba #lib

if [ "$NONFREE_SUPPORT" = yes ]; then
  XBMC_NONFREE="--enable-non-free"
else
  XBMC_NONFREE="--disable-non-free"
fi

if [ "$DVDCSS_SUPPORT" = yes ]; then
  XBMC_DVDCSS="--enable-dvdcss"
else
  XBMC_DVDCSS="--disable-dvdcss"
fi

if [ "$FAAC_SUPPORT" = yes ]; then
  $SCRIPTS/build faac
  XBMC_FAAC="--enable-faac"
else
  XBMC_FAAC="--disable-faac"
fi

if [ "$AVAHI_DAEMON" = yes ]; then
  $SCRIPTS/build avahi
  XBMC_AVAHI="--enable-avahi"
else
  XBMC_AVAHI="--disable-avahi"
fi

if [ "$WEBSERVER" = yes ]; then
  $SCRIPTS/build libmicrohttpd
  XBMC_WEBSERVER="--enable-webserver"
else
  XBMC_WEBSERVER="--disable-webserver"
fi

if [ "$VDPAU" = yes ]; then
  $SCRIPTS/build libvdpau
  XBMC_VDPAU="--enable-vdpau"
else
  XBMC_VDPAU="--disable-vdpau"
fi

if [ "$VAAPI" = yes ]; then
  $SCRIPTS/build libva
  XBMC_VAAPI="--enable-vaapi"
else
  XBMC_VAAPI="--disable-vaapi"
fi

if [ "$CRYSTALHD" = yes ]; then
  $SCRIPTS/build crystalhd
  XBMC_CRYSTALHD="--enable-crystalhd"
else
  XBMC_CRYSTALHD="--disable-crystalhd"
fi

# ensure we dont use size optimization.
  CFLAGS=`echo $CFLAGS | sed -e "s|-Os|-O3|"`
  CXXFLAGS=`echo $CXXFLAGS | sed -e "s|-Os|-O3|"`

cd $PKG_BUILD

./bootstrap

$AUTORECONF xbmc/lib/libid3tag/libid3tag

./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --with-arch=$TARGET_ARCH \
            --with-cpu=$TARGET_CPU \
            --prefix=/usr \
            --exec-prefix=/usr \
            --sysconfdir=/etc \
            --datadir=/usr/share \
            --disable-debug \
            --disable-optimizations \
            --enable-gl \
            $XBMC_VDPAU \
            $XBMC_VAAPI \
            $XBMC_CRYSTALHD \
            --disable-vdadecoder \
            --disable-profiling \
            --disable-joystick \
            --enable-xrandr \
            --disable-goom \
            --disable-xbmcprojectm \
            --disable-rsxs \
            --disable-ccache \
            --disable-pulse \
            --enable-ffmpeg-libvorbis \
            $XBMC_FAAC \
            $XBMC_DVDCSS \
            --disable-mid \
            $XBMC_AVAHI \
            --disable-hal \
            $XBMC_NONFREE \
            --disable-asap-codec \
            $XBMC_WEBSERVER \
            --disable-libdts \
            --disable-liba52 \
            --disable-external-ffmpeg \
            --disable-external-liba52 \
            --disable-external-libdts \
            --enable-external-libz \
            --enable-external-python \

make externals
make xbmc.bin
make xbmc-xrandr
