#!/bin/sh

################################################################################
#      This file is part of OpenELEC - http://www.openelec.tv
#      Copyright (C) 2009-2011 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, 675 Mass Ave, Cambridge, MA 02139, USA.
#  http://www.gnu.org/copyleft/gpl.html
################################################################################

. config/options $1

get_graphicdrivers

XORG_SRC="$PKG_BUILD/hw/xfree86"
XORG_DST="$INSTALL/$XORG_PATH_MODULES"

mkdir -p $INSTALL/usr/bin
  cp $XORG_SRC/Xorg $INSTALL/usr/bin

mkdir -p $INSTALL/lib/udev
  cp $PKG_DIR/scripts/xorg_start $INSTALL/lib/udev

mkdir -p $XORG_DST
  cp -P $XORG_SRC/exa/.libs/libexa.so $XORG_DST
  cp -P $XORG_SRC/dixmods/.libs/libfb.so $XORG_DST
  cp -P $XORG_SRC/int10/.libs/libint10.so $XORG_DST
  cp -P $XORG_SRC/dixmods/.libs/libshadow.so $XORG_DST
  cp -P $XORG_SRC/shadowfb/.libs/libshadowfb.so $XORG_DST
  cp -P $XORG_SRC/vbe/.libs/libvbe.so $XORG_DST
  cp -P $XORG_SRC/vgahw/.libs/libvgahw.so $XORG_DST
  cp -P $XORG_SRC/dixmods/.libs/libwfb.so $XORG_DST
  cp -P $XORG_SRC/xaa/.libs/libxaa.so $XORG_DST
  cp -P $XORG_SRC/xf8_16bpp/.libs/libxf8_16bpp.so $XORG_DST

mkdir -p $XORG_DST/extensions
  cp -P $XORG_SRC/dixmods/.libs/libdbe.so $XORG_DST/extensions
  cp -P $XORG_SRC/dri/.libs/libdri.so $XORG_DST/extensions
  cp -P $XORG_SRC/dri2/.libs/libdri2.so $XORG_DST/extensions
  cp -P $XORG_SRC/dixmods/extmod/.libs/libextmod.so $XORG_DST/extensions
  cp -P $XORG_SRC/dixmods/.libs/libglx.so $XORG_DST/extensions/libglx_mesa.so # rename for cooperate with nvidia drivers
  ln -sf /var/lib/libglx.so $XORG_DST/extensions/libglx.so

mkdir -p $XORG_DST/linux
  cp -P $XORG_SRC/fbdevhw/.libs/libfbdevhw.so $XORG_DST/linux

mkdir -p $XORG_DST/multimedia
  cp -P $XORG_SRC/i2c/.libs/*_drv.so $XORG_DST/multimedia

mkdir -p $INSTALL/usr/lib/xorg
  cp $PKG_BUILD/dix/protocol.txt $INSTALL/usr/lib/xorg

mkdir -p $INSTALL/usr/share/X11/xorg.conf.d
  cp $PKG_BUILD/config/10-evdev.conf $INSTALL/usr/share/X11/xorg.conf.d

if [ "$DEVTOOLS" = yes ]; then
  cp $XORG_SRC/utils/cvt/cvt $INSTALL/usr/bin
  cp $XORG_SRC/utils/gtf/gtf $INSTALL/usr/bin
fi
