#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.lincvs.org/
# Packagers Gohanz ( gohanz@infinito.ii)
# http://www.slacky.it

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp/tgz
fi

PKG=$TMP/package-crossvc
NAME=crossvc
VERSION=1.5.2
ARCH=${ARCH:-i486}
BUILD=1as

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

cd $TMP
tar xvzf $CWD/$NAME-$VERSION-0-generic-src.tgz
cd CrossVC

qmake -o Makefile lincvs.pro

sed -i "s|-O2|-O2 -march=i486 -mtune=i686|g" Makefile

make || exit 1
make install

mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/share/applications
mkdir -p $PKG/usr/share/pixmaps

cp -a $CWD/crossvc $PKG/usr/bin
cp -a -r $TMP/CrossVC/CrossVC $PKG/usr/share
cp -a $CWD/crossvc.desktop $PKG/usr/share/applications

mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS COPYING ChangeLog LICENSE NEWS README THANKS VERSION \
$PKG/usr/doc/$NAME-$VERSION
cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 550 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
chmod 755 $PKG/usr/bin/crossvc

chown -R root:root .
requiredbuilder -y -v $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
