#!/bin/sh
#
# Build script for: QtWvDialer
# BuildRequires:qt >= 3.0,wvdial
# Distribution: Slackware Linux 11.0
# Packager baldelario ~at~ gmail ~dot~ com
# http://www.slacky.it
# Source location: http://www.mtoussaint.de/qtwvdialer.html

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-qtwvdialer
NAME=qtwvdialer
VERSION=0.4.4
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=1bj
SOURCEARCH=QtWvDialer-0.4.4

COMP=tgz
#COMP=tarbz2

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

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

echo "| Start SlackBuild $NAME-$VERSION |"

cd $TMP
rm -rf $PKG
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 $SOURCEARCH
CFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--program-prefix="" \
--program-suffix="" \
$TARGET-slackware-linux
make

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/*
cp -a $CWD/*.desktop $PKG/usr/share/applications

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
chown -R root:root .
requiredbuilder -y -v -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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