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

# Why do people do things like this?
VERSION=5.21.4.10.8
PKGVER=5.21.4.10.8
DIRVER=5.21.4.10.8

ARCH=${ARCH:-i486}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
# place for the package to be built
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf dvd+rw-tools-$VERSION
tar xzvf $CWD/dvd+rw-tools-$VERSION.tar.gz
cd dvd+rw-tools-$DIRVER
chown -R root.root .
make
mkdir -p $PKG/usr/bin
cat dvd+rw-booktype > $PKG/usr/bin/dvd+rw-booktype
cat dvd+rw-format > $PKG/usr/bin/dvd+rw-format
cat dvd+rw-mediainfo > $PKG/usr/bin/dvd+rw-mediainfo
cat dvd-ram-control > $PKG/usr/bin/dvd-ram-control
cat growisofs > $PKG/usr/bin/growisofs
strip $PKG/usr/bin/*
chmod 755 $PKG/usr/bin/*
chown -R root.bin $PKG/usr/bin
mkdir -p $PKG/usr/man/man1
cat growisofs.1 | gzip -9c > $PKG/usr/man/man1/growisofs.1.gz
mkdir -p $PKG/usr/doc/dvd+rw-tools-$VERSION
cp -a \
  index.html \
  $PKG/usr/doc/dvd+rw-tools-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/dvd+rw-tools-$PKGVER-$ARCH-$BUILD.tgz

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