#!/bin/sh

. config/options

$SCRIPTS/install linux
$SCRIPTS/install libXinerama

PKG_DIR=`find $PACKAGES -type d -name $1`
VER=`ls $BUILD/linux*/modules/lib/modules`

mkdir -p $INSTALL/$XORG_PATH_MODULES/drivers
  cp -P $BUILD/$1/usr/X11R6/lib/modules/drivers/*_drv.so $INSTALL/$XORG_PATH_MODULES/drivers

mkdir -p $INSTALL/$XORG_PATH_MODULES/extensions
  cp -P $BUILD/$1/usr/X11R6/lib/modules/extensions/libglx.so* $INSTALL/$XORG_PATH_MODULES/extensions/libglx_nvidia.so

mkdir -p $INSTALL/etc/X11
  cp -P $PKG_DIR/config/*.conf $INSTALL/etc/X11

mkdir -p $INSTALL/usr/lib
  cp -P $BUILD/$1/usr/lib/libGLcore.so* $INSTALL/usr/lib/libGLcore.so.1
  cp -P $BUILD/$1/usr/lib/libGL.so* $INSTALL/usr/lib/libGL_nvidia.so.1
  cp -P $BUILD/$1/usr/lib/tls/*tls*.so* $INSTALL/usr/lib/libnvidia-tls.so.1

mkdir -p $INSTALL/lib/modules/$VER/nvidia
  cp -P $BUILD/$1/usr/src/nv/nvidia.ko $INSTALL/lib/modules/$VER/nvidia

  for MOD in `find $INSTALL/lib/modules/$VER/nvidia -name *.ko`; do
    $STRIP --strip-debug $MOD
  done

  $ROOT/$TOOLCHAIN/bin/depmod -b $INSTALL -v $VER > /dev/null
  for i in `ls $INSTALL/lib/modules/*/modules.* | grep -v modules.dep | grep -v modules.alias | grep -v modules.symbols`; do
    rm -f $i
  done

if [ "$VDPAU" = yes ]; then
  $SCRIPTS/install libvdpau

  cp $BUILD/$1/usr/lib/vdpau/libvdpau_nvidia.so* $INSTALL/usr/lib/libvdpau_nvidia.so.1
  ln -sf libvdpau_nvidia.so.1 $INSTALL/usr/lib/libvdpau_nvidia.so
fi
