#!/bin/sh
# Slackware build script for Pavuk
# Distribution: Slackware Linux 12.0
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Url: http://pavuk.sourceforge.net/

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-pavuk
rm -rf $PKG
mkdir -p $PKG

NAME=pavuk
VERSION=0.9.35
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=1bj

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

cd $TMP
rm -rf $NAME-$VERSION
tar xvjf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION
chown -R root:root .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--mandir=/usr/man \
--disable-debug \
--disable-gnome \
--program-prefix="" \
--program-suffix="" \
--build=$TARGET-slackware-linux-gnu
make
make install DESTDIR=$PKG
rm -f $PKG/usr/bin/*.sh
strip $PKG/usr/bin/*

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
  ABOUT-NLS AUTHORS BUGS ChangeLog COPYING CREDITS INSTALL NEWS *README* wget-pavuk.HOWTO *sample* TODO \
  $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/usr/share/applications
cp -a $CWD/*.desktop $PKG/usr/share/applications
chown -R root:root $PKG/usr/share/applications
gzip -9 $PKG/usr/man/man1/*

mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild

cd $PKG
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/$NAME-$VERSION
  rm -rf $PKG
fi
