#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# Requirements: jack-audio, libsndfile, portaudio, fftw
# http://mixxx.sourceforge.net
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package-mixxx
NAME=mixxx
VERSION=1.5.0.1
ARCH=i486
BUILD=1sl

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

cd $TMP
tar xjvf $CWD/$NAME-$VERSION-src.tar.bz2
cd $NAME-1.5.0
find . \( -perm 777 -o -perm 775 -o -perm 711 -o -perm 555 -o -perm 511 \) -exec chmod 755 {} \;
find . \( -perm 666 -o -perm 664 -o -perm 600 -o -perm 444 -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
chown -R root:root .
cd src
./configure --prefix=/usr \
--enable-alsa \
--enable-jack \
--cflags="-march=i486;-mtune=i686" \
--cxxflags="-march=i486;-mtune=i686"
read
make
mkdir -p $PKG/usr/share/mixxx/skins/
cp -a $TMP/$NAME-1.5.0/src/skins/outline $PKG/usr/share/mixxx/skins/
cp -a $TMP/$NAME-1.5.0/src/skins/outlineClose $PKG/usr/share/mixxx/skins/
cp -a $TMP/$NAME-1.5.0/src/skins/outlineSmall $PKG/usr/share/mixxx/skins/
mkdir -p $PKG/usr/share/mixxx/skins/
cp -a $TMP/$NAME-1.5.0/src/skins/traditional $PKG/usr/share/mixxx/skins/
cp -a $TMP/$NAME-1.5.0/src/midi $PKG/usr/share/mixxx/
mkdir -p $PKG/usr/share/mixxx/keyboard
cp -a $TMP/$NAME-1.5.0/src/keyboard $PKG/usr/share/mixxx/
mkdir -p $PKG/usr/bin
cp -a $TMP/$NAME-1.5.0/src/mixxx $PKG/usr/bin
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cd $TMP/$NAME-1.5.0
cp -a COPYING LICENSE Mixxx-Manual.pdf README* $PKG/usr/doc/$NAME-$VERSION
chmod 644 $PKG/usr/doc/$NAME-$VERSION/*
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
cd $PKG
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
