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

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

# extract the package framework
cd $PKG
explodepkg $CWD/_sdk3x.tar.gz

echo "+===============+"
echo "| Glide 3.x SDK |"
echo "+===============+"
cd $TMP
mkdir Glide
cd Glide
tar xvzf $CWD/glide3x.tar.gz
tar xvzf $CWD/swlibs.tar.gz

###
### Write out the headers
###
cat swlibs/fxmisc/3dfx.h > $PKG/usr/include/glide3/3dfx.h
cat glide3x/h3/glide3/src/glide.h > $PKG/usr/include/glide3/glide.h
cat glide3x/h3/glide3/src/glidesys.h > $PKG/usr/include/glide3/glidesys.h
cat glide3x/h3/glide3/src/glideutl.h > $PKG/usr/include/glide3/glideutl.h
cat glide3x/h3/incsrc/sst1vid.h > $PKG/usr/include/glide3/sst1vid.h
cat swlibs/fxmisc/linutil.h > $PKG/usr/include/glide3/linutil.h
cat swlibs/texus/lib/texus.h > $PKG/usr/include/glide3/texus.h

###
### Write out the test sources
###
cat glide3x/h3/glide3/tests/makefile.distrib > \
   $PKG/usr/src/glide/tests3x/Makefile
cp -a glide3x/h3/glide3/tests/*.3df $PKG/usr/src/glide/tests3x
cp -a glide3x/h3/glide3/tests/test??.c $PKG/usr/src/glide/tests3x
cp -a glide3x/h3/glide3/tests/tldata.inc $PKG/usr/src/glide/tests3x
cp -a glide3x/h3/glide3/tests/tlib.[ch] $PKG/usr/src/glide/tests3x

###
### Write out the documentation
###
( cd $PKG/usr/doc ; tar xvzf $CWD/Glide3-Doc.tar.gz )
cat glide3x/glide_license.txt > $PKG/usr/doc/Glide3/glide_license.txt

# Fix permissions and ownerships
chown -R root.root $PKG

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

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