#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.kraus.tk/projects/konverter
# http://www.slacky.it
# Required: Mplayer
##########Note Run two Times this SlackBuild for Makefile modify#######

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-konverter
NAME=konverter
VERSION=0.93
TARGET=i486
ARCH=${ARCH:-i686}
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.tar.gz

echo "+-------------------------------------+"
echo "| Starting SlackBuild  $NAME-$VERSION |"
echo "+-------------------------------------+"

cd $NAME

find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

qmake

( cd src
  sed -i "s|-I/usr3/include|-I/usr/include|g" Makefile
  sed -i "s|-L/usr/lib/qt3|-L/usr/lib|g" Makefile
)

make

mkdir -p $PKG/usr/bin
mkdir -p $PKG/usr/share/applications/kde
mkdir -p $PKG/usr/share/icons/hicolor/16x16/apps
mkdir -p $PKG/usr/share/icons/hicolor/32x32/apps
mkdir -p $PKG/usr/man/man3

( cd bin
  cp -a * $PKG/usr/bin
)

( cd docs/man/man3
  cp -a *.3 $PKG/usr/man/man3
  rm $PKG/usr/man/man3/_home*
)

( cd media
  cp -a hi16* $PKG/usr/share/icons/hicolor/16x16/apps/konverter.png
  cp -a hi32* $PKG/usr/share/icons/hicolor/32x32/apps/konverter.png
)

cp -a $CWD/konverter.desktop $PKG/usr/share/applications/kde

mkdir -p $PKG/usr/doc/$NAME-$VERSION

( cd distfiles
  cp -a * $PKG/usr/doc/$NAME-$VERSION
  rm -rf $PKG/usr/doc/$NAME-$VERSION/CVS
)

( cd docs
  cp -a html $PKG/usr/doc/$NAME-$VERSION
  rm -rf $PKG/usr/doc/$NAME-$VERSION/html/CVS
)

cd $CWD
cp -a *.SlackBuild slack-desc $PKG/usr/doc/$NAME-$VERSION

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

strip --strip-unneeded $PKG/usr/bin/* 2> /dev/null
gzip -9 $PKG/usr/man/*/*

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/$NAME
  rm -rf $PKG
fi
