#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# Requirements: libavc1394, libdv, libiec61883, dvgrab, jack-audio, ffmpeg, libquicktime, mjpegtools, mplayer
# http://lives.sourceforge.net

CWD=$PWD
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-lives
NAME=lives
VERSION=0.9.9.4
TARGET=i486
ARCH=i486
BUILD=1gas

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

echo "+=============================+"
echo "|Installazione $NAME-$VERSION |"
echo "+=============================+"

cd $TMP
tar xvf $CWD/LiVES-$VERSION.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
CFLAGS="-O2 -march=i486 -mtune=i686" \
CXXFLAGS="-O2 -march=i486 -mtune=i686" \
./configure --prefix=/usr \
--program-prefix= \
--program-suffix= \
--build=$TARGET-slackware-linux
echo "Verifica e premi invio"
read
make
make prefix=$PKG/usr install

( cd $PKG/usr/bin
  rm -rf lives
  ln -sf /usr/bin/lives-exe lives
)

mkdir -p $PKG/usr/doc/$NAME-$VERSION
mv $PKG/usr/share/doc/$NAME-$VERSION/* $PKG/usr/doc/$NAME-$VERSION
rm -rf $PKG/usr/share/doc
mkdir -p $PKG/usr/share/{pixmaps,applications}
cp menu-entries/LiVES.desktop $PKG/usr/share/applications
cp menu-entries/lives.xpm $PKG/usr/share/pixmaps
sed -i "s|Icon=lives.xpm|Icon=/usr/share/pixmaps/lives.xpm|g" $PKG/usr/share/applications/LiVES.desktop

cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
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
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
