#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-svgalib
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

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
explodepkg $CWD/_svgalib.tar.gz

# Function to handle manpage source:
man2gz () { # $1 is source page name, $2 is target name for preformatted
            # output (full path && name) and $3 is the same, but for the
            # source.
  mkdir -p `dirname $2`
  groff -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+============+"
echo "| svgalib126 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/svgalib126.tar.gz
cd svgalib
zcat $CWD/svgalib.diff.gz | patch
make src/libvga.a
cat src/libvga.a > $PKG/usr/lib/libvga.a
( cd gl ; make libvgagl.a )
cat gl/libvgagl.a > $PKG/usr/lib/libvgagl.a
make clean ; makeshared
cat sharedlib/libvga.sa > $PKG/usr/lib/libvga.sa
cat sharedlib/libvga.so.1.2.6 > $PKG/usr/lib/libvga.so.1.2.6
cat sharedlib/libvgagl.sa > $PKG/usr/lib/libvgagl.sa
( cd utils ; make )
cat utils/convfont > $PKG/usr/bin/convfont
cat utils/dumpreg > $PKG/usr/bin/dumpreg
cat utils/fix132x43 > $PKG/usr/bin/fix132x43
cat utils/restorefont > $PKG/usr/bin/restorefont
cat utils/restorepalette > $PKG/usr/bin/restorepalette
cat utils/restoretextmode > $PKG/usr/bin/restoretextmode
cat utils/setmclk > $PKG/usr/bin/setmclk
( cd demos ; make )
cat demos/3d > $PKG/usr/lib/svgalib/3d
cat demos/fun > $PKG/usr/lib/svgalib/fun
cat demos/keytest > $PKG/usr/lib/svgalib/keytest
cat demos/linuxlogo.bmp > $PKG/usr/lib/svgalib/linuxlogo.bmp
cat demos/mousetest > $PKG/usr/lib/svgalib/mousetest
cat demos/scrolltest > $PKG/usr/lib/svgalib/scrolltest
cat demos/speedtest > $PKG/usr/lib/svgalib/speedtest
cat demos/testgl > $PKG/usr/lib/svgalib/testgl
cat demos/testlinear > $PKG/usr/lib/svgalib/testlinear
cat demos/vgatest > $PKG/usr/lib/svgalib/vgatest

# Build the package:
cd $PKG
tar czvf $TMP/svgalib.tgz .

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