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

VERSION=1.5.7
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-snownews
rm -rf $PKG
mkdir $PKG
cd /tmp
rm -rf snownews-1.5.6
tar xzvf $CWD/snownews-$VERSION.tar.gz
cd `basename snownews-$VERSION i`

chown -R root:root .
CFLAGS="-O2 $AOPTS" \
./configure \
  --prefix=/usr \
  --charset=UTF-8 \
  $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/snownews-$VERSION
cp -a \
  AUTHORS COPYING CREDITS \
  ChangeLog INSTALL README README.de README.patching \
  $PKG/usr/doc/snownews-$VERSION

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