#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://cutecom.sourceforge.net/
# Packagers Gohanz ( gohanz@infinito.it )
# http://www.slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-cutecom
NAME=cutecom
VERSION=0.14.2
TARGET=i486
ARCH=${ARCH:-i486}
BUILD=2as

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION.tar.gz
cd $NAME-$VERSION
qmake
sed -i "s|-pipe -Wall -W -O2|-O2 -march=i486 -mtune=i686|g" Makefile
make
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
COPYING Changelog README $PKG/usr/doc/$NAME-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
mkdir -p $PKG/usr/bin
cp cutecom  $PKG/usr/bin/cutecom
mkdir -p $PKG/usr/share/applications
cp cutecom.desktop $PKG/usr/share/applications
strip $PKG/usr/bin/*
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 -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

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