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

VERSION=2.8.1
ARCH=i386
BUILD=1

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

echo "+===============+"
echo "| diffutils-$VERSION |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/diffutils-$VERSION.tar.gz
cd diffutils-$VERSION
chown -R root.root .
CFLAGS="-O2 -march=i386 -mcpu=i686" ./configure --prefix=/usr
make
make install DESTDIR=$PKG
( cd $PKG/usr/bin
  strip *
  chown -R root.bin .
)
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*info
gzip -9 $PKG/usr/man/man1/*
mkdir -p $PKG/usr/doc/diffutils-$VERSION
cp -a \
  ABOUT-NLS AUTHORS COPYING INSTALLME NEWS README THANKS \
  $PKG/usr/doc/diffutils-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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