#!/bin/sh
#
# Patch for vlc (www.videolan.org)
# and xine (xine.sourceforge.net)
# ===============================
# 3.5.2 The Xv video-out plugin fails to compile!
#
#      If you want to have Xv support compiled in, make sure you either
#      have
#      a shared Xv library on your system, e.g. ls /usr/X11R6/lib/libXv*
#      should give you some .so libs, like this:
#
#      /usr/X11R6/lib/libXv.a
#      /usr/X11R6/lib/libXv.so
#      /usr/X11R6/lib/libXv.so.1
#
#      Alternatively you need to have libtool 1.4 or newer installed. If
#      not
#      and you only got libXv.a you can create the shared versions
#      yourself:
#
#       ld --whole-archive -shared -o libXv.so.1 libXv.a
#       ln -s libXv.so.1 libXv.so
#       ldconfig
#
#      Now you should be ready to build the Xv video-out plugin on your
#      system.
#
###############################################################################

if [ `whoami` != 'root' ]
then
    echo "Run this script as root."
    exit -1
fi

echo -n "Testing if patch is needed:"
if [ ! -f /usr/X11R6/lib/libXv.a ]
then
    echo "XFree86-devel-4.1.0-3 is not installed."
    echo "Install the packages from RedHat distribution first."
    exit -1
fi

if [ -f /usr/X11R6/lib/libXv.so.1 ] &&
    [ -f /usr/X11R6/lib/libXv.so ]
then
    echo "Patch is not needed.";
    exit -1
else
    echo "Patch Xvideo setup."
    cd /usr/X11R6/lib
    /usr/bin/ld --whole-archive -shared -o libXv.so.1 libXv.a
    [ -f /usr/X11R6/lib/libXv.so ] || rm /usr/X11R6/lib/libXv.so
    /bin/ln -s /usr/X11R6/lib/libXv.so.1 /usr/X11R6/lib/libXv.so
    /sbin/ldconfig
fi

#
# SDL output of vlc expects libSDL-1.1, but RedHat supplies libSDL-1.2.
#
if [ -f /usr/lib/libSDL-1.1.so.0 ]
then
   echo -n "Testing if patch is needed:"
   echo "SDL patch is not needed."
   exit -1
else
   echo -n "Patch SDL setup."
   ln -s /usr/lib/libSDL-1.2.so.0 /usr/lib/libSDL-1.1.so.0
   echo "done."
fi
echo "done."

# end of patch script
