#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-svgalib
SRC=/devel/manpagesrc
INFO=$PKG/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 "| svgalib127 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/svgalib-127.tar.gz
cd svgalib-127
# Let's make sure these don't get compiled with old header files...
cat src/vga.h > /usr/include/vga.h
cat gl/vgagl.h > /usr/include/vgagl.h
cat src/keyboard/vgakeyboard.h > /usr/include/vgakeyboard.h
cat src/mouse/vgamouse.h > /usr/include/vgamouse.h
( cd src ; ln -sf Makefile.elf Makefile ; make libvga.a )
cat src/libvga.a > $PKG/usr/lib/libvga.a
( cd src ; make libvga.so.1.2.7 )
cat src/libvga.so.1.2.7 > $PKG/usr/lib/libvga.so.1.2.7
cat src/libvga.so.1.2.7 > /usr/lib/libvga.so.1.2.7
cat src/vga.h > $PKG/usr/include/vga.h
cat src/keyboard/vgakeyboard.h > $PKG/usr/include/vgakeyboard.h
cat src/mouse/vgamouse.h > $PKG/usr/include/vgamouse.h
( cd gl ; ln -sf Makefile.elf Makefile ; make libvgagl.a )
cat gl/libvgagl.a > $PKG/usr/lib/libvgagl.a
cat gl/vgagl.h > $PKG/usr/include/vgagl.h
( cd gl ; make libvgagl.so.1.2.7 )
cat gl/libvgagl.so.1.2.7 > $PKG/usr/lib/libvgagl.so.1.2.7
cat gl/libvgagl.so.1.2.7 > /usr/lib/libvgagl.so.1.2.7
chmod 755 $PKG/usr/lib/libvgagl.so.1.2.7
( 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
