#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
   TMP=/tmp
fi
PKG=$TMP/package-desktop

if [ ! -d $TMP ]; then
   mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
   mkdir -p $PKG # place for the package to be built
fi

# explode the package framework
cd $PKG
tar xvzf $CWD/_desktop.tar.gz

echo "+=============+"
echo "| DesktopDemo |"
echo "+=============+"
cd $TMP
mkdir DesktopDemo
cd DesktopDemo
tar xvzf $CWD/DesktopDemo.tar.gz
# fix the entries with "redhat" in the Makefile
for makefile in Makefile xform/Makefile
do
   cat $makefile | sed -e s/\-redhat\-/\-slackware\-/g > $makefile.incoming
   mv $makefile.incoming $makefile
done
make GLIDE=2 clean
make GLIDE=2
strip desktop
cat desktop > $PKG/usr/lib/glide/demos/desktop/desktop
cp -a README AUTHORS $PKG/usr/doc/DesktopDemo
( cd $PKG/usr/doc/DesktopDemo ; chown root.root * )
( cd $PKG/usr/doc/DesktopDemo ; chmod 644 * )
cp -a data/*.3df $PKG/usr/lib/glide/demos/desktop/data
cp -a data/*.xpm $PKG/usr/lib/glide/demos/desktop/data
( cd $PKG/usr/lib/glide/demos/desktop/data ; chown root.root * )
( cd $PKG/usr/lib/glide/demos/desktop/data ; chmod 644 * )
cd data
for dirname in bird spider tux
do
   cp -a $dirname/* $PKG/usr/lib/glide/demos/desktop/data/$dirname
   chown root.root $PKG/usr/lib/glide/demos/desktop/data/$dirname/*
   chmod 644 $PKG/usr/lib/glide/demos/desktop/data/$dirname/*
done

# make the package
cd $PKG
echo "n" | makepkg $TMP/desktop.tgz

# clean up the extra stuff
if [ "$1" = "--cleanup" ]; then
   rm -rf $PKG
   rm -rf $TMP/DesktopDemo
fi
