#!/bin/sh
# Set initial variables:
PATH=$PATH:/usr/X11R6/bin
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi

PKG=$TMP/package-xrush
if [ ! -d $PKG ]; then
  mkdir -p $PKG
fi

# explode the package framework
cd $PKG
explodepkg $CWD/_xrush.tar.gz

#
# Build XFree86 server for the Voodoo Rush chipset
#
cd $TMP
tar xvyf $CWD/X335src-1.tar.bz2
zcat $CWD/X335.rush.diff.gz | patch -p0
cd xc
zcat $CWD/xfree86.cf.diff.gz | patch -p0
zcat $CWD/xf86site.def.diff.gz | patch -p0
zcat $CWD/site.def.diff.gz | patch -p0
make World -i CDEBUGFLAGS=-O2
( cd programs/Xserver ; make CDEBUGFLAGS=-O2 Xwrapper )
( cd programs/Xserver/hw/xfree86/etc ; make CDEBUGFLAGS=-O2 joycal )
# Work around an egcs optimization problem that breaks Netscape:
cd lib
rm -f {X11,X11/unshared}/{imLcFlt.o,FilterEv.o}
rm -f {Xt,Xt/unshared}/{Event.o,Callback.o,Destroy.o,NextEvent.o}
make CDEBUGFLAGS=""
cd ..

# make the xrush.tgz package
cat programs/Xserver/XF86_SVGA > $PKG/usr/X11R6/bin/XF86_SVGA
cd $PKG
echo "n" | makepkg $TMP/xrush.tgz

# make the xrushlib.tgz package
PKG2=$TMP/package-xrushlib
mkdir -p $PKG2
mkdir -p $PKG2/usr/X11R6/lib
mkdir -p $PKG2/usr/X11R6/include/extensions
chmod -R g-w $PKG2
cd $TMP/xc
cp -a lib/Xxf86rush/libXxf86rush* $PKG2/usr/X11R6/lib
cp -a include/extensions/xf86rush* $PKG2/usr/X11R6/include/extensions
cd $PKG2
chown -R root.root *
echo "y
n" | makepkg $TMP/xrushlib.tgz

cd $TMP
if [ "$1" = "--cleanup" ]
then
   rm -rf $TMP/package-xrush
   rm -rf $TMP/package-xrushlib
   rm -rf $TMP/xc
fi