#!/bin/sh
# Heavily based on the Slackware 12.2 SlackBuild
# Requires: wvstrams, wvdial
# http://www.mtoussaint.de/qtwvdialer.html
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-qtwvdialer
NAME=qtwvdialer
VERSION=0.4.4
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=3bj

COMP=tgz
#COMP=tarbz2

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

if [ ! -d $TMP ]; then
 mkdir -p $TMP
fi
if [ ! -d $PKG ]; then
 mkdir -p $PKG
fi

cd $TMP
if [ "$COMP" = "tarbz2" ]; then
    tar xvjf $CWD/$NAME-$VERSION.tar.bz2
elif [ "$COMP" = "targz" ]; then
    tar xvzf $CWD/$NAME-$VERSION.tar.gz
elif [ "$COMP" = "tgz" ]; then
    tar xvzf $CWD/$NAME-$VERSION.tgz
fi

cd QtWvDialer-$VERSION
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--build=$TARGET-slackware-linux
make || exit 1

mkdir -p -m 755 $PKG/usr{/bin,/doc/$NAME-$VERSION,/share/applications}
(cd bin
cat qtwvdialer > $PKG/usr/bin/qtwvdialer
chmod 755 $PKG/usr/bin/*
strip $PKG/usr/bin/*
)

cat << EOF > $PKG/usr/share/applications/$NAME.desktop
[Desktop Entry]
Encoding=UTF-8
GenericName=Internet Dial-Up Tool
GenericName[it]=Strumento per la connessione ad Internet
Name=QtWvDialer
Exec=qtwvdialer %i %m
Icon=kppp
Type=Application
Terminal=false
X-KDE-StartupNotify=true
X-DCOP-ServiceType=Multi
Categories=Qt;KDE;Network;
EOF

cp -a AUTHORS COPYING CHANGELOG INSTALL README $PKG/usr/doc/$NAME-$VERSION

mkdir -p $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
fi
