#!/bin/sh

# Parts of this SlackBuild from the Slamd64 Project (thanks guys)
# Other SlackBuild constructs added later by jmd

CWD=`pwd`
VERSION=1.00.3
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-0}

TMP=/tmp/raidtools-$VERSION
PKG=/tmp/package-raidtools

rm -rf $TMP $PKG

cd /tmp
tar xzvf $CWD/raidtools-$VERSION.tar.gz
cd $TMP
chown -R root.root .

# Apply patches
zcat $CWD/patches-splack/gcc33.diff.gz | patch -p1 --verbose
# zcat $CWD/patches-splack/linux26.diff.gz | patch -p1 --verbose

# Build
./configure --prefix=/usr
make
make install ROOTDIR=$PKG

mkdir -p $PKG/usr/doc/raidtools-$VERSION
cp -a \
  COPYING README Software-RAID.HOWTO *.sample raidreconf-HOWTO *.txt summary \
  $PKG/usr/doc/raidtools-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/raidtools-$VERSION-$ARCH-$BUILD.tgz

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

