#!/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

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/fbdevhw/.libs/libfbdevhw.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

mkdir -p $XORG_DST/extensions
  cp -P $XORG_SRC/dixmods/.libs/libdbe.so $XORG_DST/extensions
  cp -P $XORG_SRC/dixmods/.libs/librecord.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

  if [ -f $XORG_SRC/dri/.libs/libdri.so ]; then
    cp -P $XORG_SRC/dri/.libs/libdri.so $XORG_DST/extensions
  fi
  if [ -f $XORG_SRC/dixmods/.libs/libglx.so ]; then
    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
  fi

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

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

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

mkdir -p $INSTALL/etc/X11
  if [ -f $PROJECT_DIR/$PROJECT/xorg/xorg.conf ]; then
    cp $PROJECT_DIR/$PROJECT/xorg/xorg.conf $INSTALL/etc/X11
  elif [ -f $PKG_DIR/config/xorg.conf ]; then
    cp $PKG_DIR/config/xorg.conf $INSTALL/etc/X11
  fi

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