#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-rocksndiamond
VERSION=3.2.4
ARCH=alpha
BUILD=1

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf rocksndiamonds-$VERSION
tar xzf $CWD/rocksndiamonds-$VERSION.tar.gz
cd rocksndiamonds-$VERSION
zcat $CWD/makefile.diff.gz | patch -p0 --verbose || exit 1
chown -R root.root .
make clean
make || exit
mkdir -p $PKG/usr/local/games/rocksndiamonds
cp -a docs sounds scores music levels graphics rocksndiamonds $PKG/usr/local/games/rocksndiamonds
mkdir -p $PKG/usr/man/man1
cat rocksndiamonds.1 | gzip -9 > $PKG/usr/man/man1/rocksndiamonds.1.gz
mkdir -p $PKG/usr/doc/rocksndiamonds-$VERSION
cp -a C* HARDWARE README TODO $PKG/usr/doc/rocksndiamonds-$VERSION

cd $TMP
tar xjf $CWD/rockslevels-dx-1.0.tar.bz2 -C $PKG/usr/local/games/rocksndiamonds

( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/rocksndiamonds-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/rocksndiamonds.build.log
