#!/bin/sh
# Build Maildrop for Slackware (by arossato@istitutocolli.org)
CWD=`pwd` 

VERSION=2.0.2
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1ar}

if [ "$ARCH" = "i386" ]; then
  AOPTS="-march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  AOPTS="-march=i486 -mtune=i686"
elif [ "$ARCH" = "s390" ]; then
  AOPTS=""
elif [ "$ARCH" = "x86_64" ]; then
  AOPTS=""
fi

PKG=/tmp/package-maildrop
rm -rf $PKG
mkdir $PKG
cd /tmp
rm -rf maildrop-2.0.1
tar xjvf $CWD/maildrop-$VERSION.tar.bz2
cd `basename maildrop-$VERSION i`

chown -R root:root .
CFLAGS="-O2 $AOPTS" \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  $ARCH-slackware-linux
make
make install DESTDIR=$PKG

( 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
)
gzip -9 $PKG/usr/man/man?/*

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
requiredbuilder -y $PKG

mkdir -p $PKG/usr/doc/maildrop-$VERSION
cp -a \
  AUTHORS COPYING COPYING.GPL ChangeLog \
  INSTALL INSTALL.html README README.html \
  README.postfix NEWS UPGRADE UPGRADE.html \
  $PKG/usr/doc/maildrop-$VERSION
mv $PKG/usr/share/maildrop $PKG/usr/doc/maildrop-$VERSION
rm -rf $PKG/usr/share

cd $PKG
makepkg -l y -c n ../maildrop-$VERSION-$ARCH-$BUILD.tgz
