#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2012 Stephan Raue (stephan@openelec.tv)
#
#  This Program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2, or (at your option)
#  any later version.
#
#  This Program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with OpenELEC.tv; see the file COPYING.  If not, write to
#  the Free Software Foundation, 51 Franklin Street, Suite 500, Boston, MA 02110, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

get_graphicdrivers

DRM_CONFIG="--disable-libkms --disable-intel --disable-radeon"
DRM_CONFIG="$DRM_CONFIG --disable-nouveau-experimental-api --disable-vmwgfx-experimental-api"

for drv in $GRAPHIC_DRIVERS; do
  [ "$drv" = "i915" -o "$drv" = "i965" ] && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-libkms/enable-libkms/'` && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-intel/enable-intel/'`

  [ "$drv" = "r200" -o "$drv" = "r300" -o "$drv" = "r600" -o "$drv" = "radeon" ] && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-libkms/enable-libkms/'` && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-radeon/enable-radeon/'`

  [ "$drv" = "nouveau" ] && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-libkms/enable-libkms/'` && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-nouveau/enable-nouveau/'`

  [ "$drv" = "vmware" ] && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-libkms/enable-libkms/'` && \
    DRM_CONFIG=`echo $DRM_CONFIG | sed -e 's/disable-vmwgfx-experimental-api/enable-vmwgfx-experimental-api/'`
done

export LIBUDEV_CFLAGS="-I`ls -d $ROOT/$BUILD/udev*`"
export LIBUDEV_LIBS="-I`ls -d $ROOT/$BUILD/udev*`"

cd $PKG_BUILD
./configure --host=$TARGET_NAME \
            --build=$HOST_NAME \
            --prefix=/usr \
            --sysconfdir=/etc \
            --disable-static \
            --enable-shared \
            --enable-udev \
            --enable-largefile \
            --with-kernel-source=$(kernel_path) \
            $DRM_CONFIG \

make

$MAKEINSTALL
