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

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/_cmatrix.tar.gz

echo "+==============+"
echo "| cmatrix-1.1b |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/cmatrix-1.1b.tar.gz
cd cmatrix-1.1b
./configure --prefix=/usr
make
strip cmatrix
cat cmatrix > $PKG/usr/bin/cmatrix
cat cmatrix.1 | gzip -9c > $PKG/usr/man/man1/cmatrix.1.gz
cat matrix.fnt > $PKG/usr/lib/kbd/consolefonts/matrix.fnt
cat matrix.psf.gz > $PKG/usr/lib/kbd/consolefonts/matrix.psf.gz
cat mtx.pcf > $PKG/usr/X11R6/lib/fonts/misc/mtx.pcf
cp -a AUTHORS COPYING Changelog INSTALL NEWS README README.fonts TODO \
   $PKG/usr/doc/cmatrix-1.1b
chown root.root $PKG/usr/doc/cmatrix-1.1b/*
chmod 644 $PKG/usr/doc/cmatrix-1.1b/*

# Build the package:
cd $PKG
echo "n" | makepkg $TMP/cmatrix.tgz

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